Skip to content

Commit 58efada

Browse files
committed
feat(test): add Readonly AutoProperty Primitive type use UsingDestinationValue
1 parent dfae8b6 commit 58efada

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/Mapster.Tests/WhenUsingDestinationValue.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,28 @@ public void MappingToReadonlyPropertyWhenPocoDetectRegression()
4747
student.Name.ShouldBe("John");
4848
}
4949

50+
[TestMethod]
51+
public void MappingToReadonlyAutoPropertyPrimitiveOrImmutableType()
52+
{
53+
var studentDto = new StudentDtoOrigin { Name = "Marta" };
54+
var UseDestinationValue = studentDto.Adapt<StudentOrigin>();
55+
var NotUseDestinationValue = studentDto.Adapt<StudentOriginNoUseDestinationValue>();
56+
57+
UseDestinationValue.Name.ShouldBe(studentDto.Name);
58+
NotUseDestinationValue.Name.ShouldBe("John"); // not modified Name == "John" - origin value
59+
}
60+
61+
#region TestClasses
62+
63+
public class StudentOriginNoUseDestinationValue
64+
{
65+
public string Name { get; } = "John"; // readonly primitive type autoproperty
66+
}
5067

5168
public class StudentOrigin
5269
{
5370
[UseDestinationValue]
54-
public string Name { get; } = "John"; // only readonly
71+
public string Name { get; } = "John"; // readonly primitive type autoproperty
5572
}
5673

5774
public class StudentDtoOrigin
@@ -93,5 +110,7 @@ public class InvoiceDto
93110
public IEnumerable<int> Numbers { get; set; }
94111
public ICollection<string> Strings { get; set; }
95112
}
113+
114+
#endregion TestClasses
96115
}
97116
}

0 commit comments

Comments
 (0)