Skip to content

Commit

Permalink
Adding test; closes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Nov 7, 2011
1 parent 015aa2c commit 4344a62
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/UnitTests/InterfaceMapping.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Should;
using NUnit.Framework;

Expand Down Expand Up @@ -359,6 +360,40 @@ public void Should_ignore_interface_members_for_validation()
}
}

public class MappingToInterfacesWithPolymorphism : AutoMapperSpecBase
{
private BaseDto[] _baseDtos;

public interface IBase { }
public interface IDerived : IBase { }
public class Base : IBase { }
public class Derived : Base, IDerived { }
public class BaseDto { }
public class DerivedDto : BaseDto { }

//and following mappings:
protected override void Establish_context()
{
Mapper.CreateMap<Base, BaseDto>().Include<Derived, DerivedDto>();
Mapper.CreateMap<Derived, DerivedDto>();
// try with and without the following two lines, also try with just the following two lines
Mapper.CreateMap<IBase, BaseDto>().Include<IDerived, DerivedDto>();
Mapper.CreateMap<IDerived, DerivedDto>();
}
protected override void Because_of()
{
List<Base> list = new List<Base>() { new Derived() };
_baseDtos = Mapper.Map<IEnumerable<Base>, BaseDto[]>(list);
}

[Test]
public void Should_use_the_derived_type_map()
{
_baseDtos.First().ShouldBeType<DerivedDto>();
}

}

[TestFixture, Explicit]
public class MappingToInterfacesPolymorphic
{
Expand Down

0 comments on commit 4344a62

Please sign in to comment.