Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created December 16, 2010 20:34
Show Gist options
  • Save jfromaniello/743968 to your computer and use it in GitHub Desktop.
Save jfromaniello/743968 to your computer and use it in GitHub Desktop.
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,
});
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