From 798eb12b6f6388bc1fee5943146dcbb3cb188d83 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 20 Feb 2018 15:56:13 +0100 Subject: [PATCH] SimpleMapper fixed --- .../Apps/LanguagesConfig.cs | 2 +- .../Reflection/SimpleMapper.cs | 2 +- .../Reflection/SimpleMapperTests.cs | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Squidex.Domain.Apps.Core.Model/Apps/LanguagesConfig.cs b/src/Squidex.Domain.Apps.Core.Model/Apps/LanguagesConfig.cs index caae6499f..be1dbe7f9 100644 --- a/src/Squidex.Domain.Apps.Core.Model/Apps/LanguagesConfig.cs +++ b/src/Squidex.Domain.Apps.Core.Model/Apps/LanguagesConfig.cs @@ -18,7 +18,7 @@ namespace Squidex.Domain.Apps.Core.Apps public sealed class LanguagesConfig : IFieldPartitioning { public static readonly LanguagesConfig Empty = new LanguagesConfig(ImmutableDictionary.Empty, null, false); - public static readonly LanguagesConfig English = LanguagesConfig.Build(Language.EN); + public static readonly LanguagesConfig English = Build(Language.EN); private readonly ImmutableDictionary languages; private readonly LanguageConfig master; diff --git a/src/Squidex.Infrastructure/Reflection/SimpleMapper.cs b/src/Squidex.Infrastructure/Reflection/SimpleMapper.cs index 0845e39d4..29890e85b 100644 --- a/src/Squidex.Infrastructure/Reflection/SimpleMapper.cs +++ b/src/Squidex.Infrastructure/Reflection/SimpleMapper.cs @@ -137,7 +137,7 @@ namespace Squidex.Infrastructure.Reflection new PropertyAccessor(sourceClassType, sourceProperty), new PropertyAccessor(targetClassType, targetProperty))); } - else if (sourceType.Implements()) + else if (sourceType.Implements() || targetType.Implements()) { Mappers.Add(new ConversionPropertyMapper( new PropertyAccessor(sourceClassType, sourceProperty), diff --git a/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs b/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs index 3b044b1e3..36b770438 100644 --- a/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs +++ b/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs @@ -100,6 +100,20 @@ namespace Squidex.Infrastructure.Reflection Assert.Equal(0, obj2.P3); } + [Fact] + public void Should_map_nullables() + { + var obj1 = new Class1 + { + P1 = true, + P2 = true + }; + var obj2 = SimpleMapper.Map(obj1, new Class2()); + + Assert.True(obj2.P2); + Assert.False(obj2.P3); + } + [Fact] public void Should_map_when_convertible_is_null() {