-
-
Save darrencauthon/575156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ObjectUnderTest | |
{ | |
private readonly MappingEngine mappingEngine; | |
public ObjectUnderTest(string prefix) | |
{ | |
var configuration = new Configuration(new TypeMapFactory(), MapperRegistry.AllMappers()); | |
configuration.CreateMap<Person, PersonModel>() | |
.ForMember(x => x.Name, y => y.MapFrom(orig => prefix + orig.Name)); | |
mappingEngine = new MappingEngine(configuration); | |
} | |
public PersonModel MapObject(Person input) | |
{ | |
return mappingEngine.Map<Person, PersonModel>(input); | |
} | |
} | |
public class Person | |
{ | |
public string Name { get; set; } | |
} | |
public class PersonModel | |
{ | |
public string IDoNotExistInPerson { get; set; } | |
public string Name { get; set; } | |
} | |
[TestFixture] | |
public class TestClass | |
{ | |
[Test] | |
public void Test1() | |
{ | |
var test = new ObjectUnderTest(null); | |
var result = test.MapObject(new Person {Name = "world"}); | |
result.Name.ShouldEqual("world"); | |
} | |
[Test] | |
public void Test2() | |
{ | |
var test = new ObjectUnderTest("Hello "); | |
var result = test.MapObject(new Person {Name = "world"}); | |
result.Name.ShouldEqual("Hello world"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's another way to potentially do what I think you're trying to do. You'll have to internalize your use of AutoMapper inside your ObjectUnderTest if you're going to use it that way, the static method will not help.