From 57e7c6bc8ee4940d6b4d844822b76e73524cbcca Mon Sep 17 00:00:00 2001 From: Jimmy Bogard Date: Wed, 14 Apr 2010 10:57:20 -0500 Subject: [PATCH] Fixed bug where the interface matching got overwritten --- src/AutoMapper/Configuration.cs | 2 + src/AutoMapper/MappingEngine.cs | 8 --- .../Bug/MultipleInterfaceInheritance.cs | 58 +++++++++++++++++++ src/UnitTests/UnitTests.csproj | 1 + 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 src/UnitTests/Bug/MultipleInterfaceInheritance.cs diff --git a/src/AutoMapper/Configuration.cs b/src/AutoMapper/Configuration.cs index 4b35edca6a..b2ade80f7d 100644 --- a/src/AutoMapper/Configuration.cs +++ b/src/AutoMapper/Configuration.cs @@ -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)) diff --git a/src/AutoMapper/MappingEngine.cs b/src/AutoMapper/MappingEngine.cs index a30174de14..9b253aeffa 100644 --- a/src/AutoMapper/MappingEngine.cs +++ b/src/AutoMapper/MappingEngine.cs @@ -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; @@ -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; diff --git a/src/UnitTests/Bug/MultipleInterfaceInheritance.cs b/src/UnitTests/Bug/MultipleInterfaceInheritance.cs new file mode 100644 index 0000000000..7e61e35986 --- /dev/null +++ b/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(); + cfg.CreateMap(); + }); + } + + protected override void Because_of() + { + var thing = new Thing { Items = new[] { new Item() } }; + _thingDto = Mapper.Map(thing); + } + + [Test] + public void Should_map_successfully() + { + _thingDto.Items.Length.ShouldEqual(1); + } + } +} \ No newline at end of file diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index f4822508ce..0f60b0cc89 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -90,6 +90,7 @@ +