Created
December 16, 2010 20:33
-
-
Save jfromaniello/743965 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using Mapper.Tests.SampleDomain; | |
using NUnit.Framework; | |
using SharpTestsEx; | |
namespace Mapper.Tests | |
{ | |
[TestFixture] | |
public class SimpleTests | |
{ | |
[Test] | |
public void CanMapSimpleValuesExplicitly() | |
{ | |
var sampleEntity = new Customer | |
{ | |
Id = 1, | |
Name = "Juan Paz" | |
}; | |
var mapper = new Mapper(); | |
mapper.AddMap<Customer, CustomerDto>(c => new CustomerDto | |
{ | |
Id = c.Id, | |
Name = c.Name, | |
CountryName = c.Country == null ? default(string) : c.Country.Name | |
}); | |
var result = mapper.Map<Customer, CustomerDto>(sampleEntity); | |
result.Satisfy(r => r.Id == 1 && r.Name == "Juan Paz"); | |
} | |
[Test] | |
public void CanMapSimpleValuesImplicitly() | |
{ | |
var sampleEntity = new Customer | |
{ | |
Id = 1, | |
Name = "Juan Paz" | |
}; | |
var mapper = new Mapper(); | |
mapper.AddMap<Customer, CustomerDto>(); | |
var result = mapper.Map<Customer, CustomerDto>(sampleEntity); | |
result.Satisfy(r => r.Id == 1 && r.Name == "Juan Paz"); | |
} | |
[Test] | |
public void CanMapSimpleProjection() | |
{ | |
var sampleEntity = new Customer | |
{ | |
Id = 1, | |
Name = "Juan Paz", | |
Country = new Country | |
{ | |
Name = "Argentina" | |
} | |
}; | |
var mapper = new Mapper(); | |
mapper.AddMap<Customer, CustomerDto>(); | |
var result = mapper.Map<Customer, CustomerDto>(sampleEntity); | |
result.CountryName.Should().Be.EqualTo("Argentina"); | |
} | |
[Test] | |
public void WithNestedProperty() | |
{ | |
var sampleEntity = new Supplier | |
{ | |
Country = new Country | |
{ | |
Name = "Argentina", | |
Capital = new Capital {Name = "Buenos Aires"} | |
} | |
}; | |
var mapper = new Mapper(); | |
mapper.AddMap<Supplier, SupplierDto>(); | |
var result = mapper.Map<Supplier, SupplierDto>(sampleEntity); | |
result.CountryCapitalName.Should().Be.EqualTo("Buenos Aires"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment