Skip to content

Commit

Permalink
fix bug when mapWith arguments does not save nullability for referenc…
Browse files Browse the repository at this point in the history
…e types
  • Loading branch information
DedAnton committed Dec 9, 2023
1 parent 2f53cbb commit eace1d6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NextGenMapper/Mapping/Designers/ConfiguredMapDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private static void DesignConfiguredMaps(
continue;
}

var destinationPropertyType = destinationProperty.Type.ToNotNullableString();
var destinationPropertyType = destinationProperty.Type.ToDisplayString();
if (arguments.Contains(destinationProperty.Name))
{
var propertyMap = CreateUserProvidedProeprtyMap(destinationProperty.Name, destinationPropertyType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
PropertyThatNeedMap: {
Property: good
},
Property: good
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//HintName: Mapper_ConfiguredMaps_MockMethods.g.cs
#nullable enable
using NextGenMapper.Extensions;

namespace NextGenMapper
{
internal static partial class Mapper
{
internal static Test.Destination MapWith<To>
(
this Test.Source source,
Test.B? PropertyThatNeedMap = default!,
string Property = default!
)
{
throw new System.NotImplementedException("This method is a mock and is not intended to be called");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//HintName: Mapper_ConfiguredMaps.g.cs
#nullable enable
using NextGenMapper.Extensions;

namespace NextGenMapper
{
internal static partial class Mapper
{
internal static Test.Destination MapWith<To>
(
this Test.Source source,
Test.B? PropertyThatNeedMap
)
=> new Test.Destination
{
PropertyThatNeedMap = PropertyThatNeedMap,
Property = source.Property
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,43 @@ public class B

await VerifyAndRun(source);
}

[TestMethod]
public async Task NullableReferenceTypesInArgumentWithMapMethodCall_ShouldMap()
{
var source =
@"#nullable enable
using NextGenMapper;
namespace Test;
public class Program
{
public object RunTest() => new Source().MapWith<Destination>(PropertyThatNeedMap: new B { Property = ""good"" });
}
public class Source
{
public A? PropertyThatNeedMap { get; set; } = null;
public string Property { get; set; } = ""good"";
}
public class Destination
{
public B? PropertyThatNeedMap { get; set; }
public string Property { get; set; } = ""bad"";
}
public class A
{
public string Property { get; set; } = string.Empty;
}
public class B
{
public string Property { get; set; } = ""bad"";
}";

await VerifyAndRun(source);
}
}

0 comments on commit eace1d6

Please sign in to comment.