Skip to content

Commit

Permalink
Fixed bug where the interface matching got overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Apr 14, 2010
1 parent 595ab90 commit 57e7c6b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/AutoMapper/Configuration.cs
Expand Up @@ -335,6 +335,8 @@ private TypeMap FindTypeMap(object source, Type sourceType, Type destinationType
{
typeMap = CreateTypeMap(sourceType, derivedTypeFor, profileName);
}

break;
}

if ((sourceType.BaseType != null) && (typeMap == null))
Expand Down
8 changes: 0 additions & 8 deletions src/AutoMapper/MappingEngine.cs
Expand Up @@ -118,11 +118,6 @@ object IMappingEngineRunner.Map(ResolutionContext context)
{
try
{
//if (context.SourceValue == null && ShouldMapSourceValueAsNull(context))
//{
// return ObjectCreator.CreateDefaultValue(context.DestinationType);
//}

var contextTypePair = new TypePair(context.SourceType, context.DestinationType);

IObjectMapper mapperToUse;
Expand Down Expand Up @@ -197,9 +192,6 @@ object IMappingEngineRunner.CreateObject(ResolutionContext context)

bool IMappingEngineRunner.ShouldMapSourceValueAsNull(ResolutionContext context)
{
//if (context.DestinationType == typeof(string))
// return false;

if (context.DestinationType.IsValueType)
return false;

Expand Down
58 changes: 58 additions & 0 deletions src/UnitTests/Bug/MultipleInterfaceInheritance.cs
@@ -0,0 +1,58 @@
using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace AutoMapper.UnitTests.Bug
{
[TestFixture]
public class MultipleInterfaceInheritance : AutoMapperSpecBase
{
private ThingDto _thingDto;

public class Thing
{
public IItem[] Items { get; set; }
}

public class ThingDto
{
public ItemDto[] Items { get; set; }
}

public class Item : IItem
{
}

public class ItemDto
{
}

public interface IItem : ISome // everything works well if IItem doesn't inherit ISome.
{
}

public interface ISome
{
}

protected override void Establish_context()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Thing, ThingDto>();
cfg.CreateMap<IItem, ItemDto>();
});
}

protected override void Because_of()
{
var thing = new Thing { Items = new[] { new Item() } };
_thingDto = Mapper.Map<Thing, ThingDto>(thing);
}

[Test]
public void Should_map_successfully()
{
_thingDto.Items.Length.ShouldEqual(1);
}
}
}
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Bug\AddingConfigurationForNonMatchingDestinationMemberBug.cs" />
<Compile Include="Bug\EnumMatchingOnValue.cs" />
<Compile Include="Bug\IgnoreAll.cs" />
<Compile Include="Bug\MultipleInterfaceInheritance.cs" />
<Compile Include="Bug\NamingConventions.cs" />
<Compile Include="Bug\RepeatedMappingConfigurationTest.cs" />
<Compile Include="Bug\SequenceContainsNoElementsTest.cs">
Expand Down

0 comments on commit 57e7c6b

Please sign in to comment.