Skip to content

Commit

Permalink
fix: map to target from null value should return null
Browse files Browse the repository at this point in the history
  • Loading branch information
chaowlert committed Feb 5, 2019
1 parent d26be04 commit 770a989
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Mapster.Tests/Mapster.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExpressionDebugger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
Expand Down
11 changes: 11 additions & 0 deletions src/Mapster.Tests/WhenMappingArrays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Mapster.Tests
{
Expand All @@ -22,6 +23,16 @@ public void Single_Dimensional_Array_Is_Mapped()
target.Ints.ShouldBe(source.Ints);
}

[TestMethod]
public void MapToTarget_With_Null_Value()
{
var source = new FooArray { Ints = null };
var target = new BarArray { Ints = new int[] { 1, 2, 3, 4, 5 } };

TypeAdapter.Adapt(source, target);
target.Ints.ShouldBeNull();
}

[TestMethod]
public void Multi_Dimensional_Array_Is_Mapped()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mapster/Adapters/BaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected Expression CreateBlockExpressionBody(Expression source, Expression des
var compareNull = Expression.Equal(source, Expression.Constant(null, source.Type));
set = Expression.IfThenElse(
compareNull,
Expression.Assign(result, destination ?? arg.DestinationType.CreateDefault()),
Expression.Assign(result, arg.DestinationType.CreateDefault()),
set);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Mapster/Mapster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<PackageLicenseUrl>https://github.com/MapsterMapper/Mapster/blob/master/LICENSE</PackageLicenseUrl>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>3.3.0</Version>
<Version>3.3.1</Version>
<RootNamespace>Mapster</RootNamespace>
<AssemblyVersion>3.3.0.0</AssemblyVersion>
<AssemblyVersion>3.3.1.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<Reference Include="Microsoft.CSharp" />
Expand Down

0 comments on commit 770a989

Please sign in to comment.