Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug when mapWith arguments does not save nullability for referenc… #154

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading