Skip to content

Commit 0711eb8

Browse files
committed
add Test for RecordType check
IgnoreNullValue UseDestinationValue Use Destination value from Primitive type AutoProperty
1 parent 32f0a34 commit 0711eb8

File tree

1 file changed

+60
-9
lines changed

1 file changed

+60
-9
lines changed

src/Mapster.Tests/WhenMappingRecordRegression.cs

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,36 @@ public void WhenRecordReceivedIgnoreCtorParamProcessing()
391391

392392
}
393393

394+
[TestMethod]
395+
public void WhenRecordTypeWorksWithUseDestinationValueAndIgnoreNullValues()
396+
{
397+
398+
TypeAdapterConfig<SourceFromTestUseDestValue, TestRecordUseDestValue>
399+
.NewConfig()
400+
.IgnoreNullValues(true);
401+
402+
var _source = new SourceFromTestUseDestValue() { X = 300, Y = 200, Name = new StudentNameRecord() { Name = "John" } };
403+
var result = _source.Adapt<TestRecordUseDestValue>();
404+
405+
var _sourceFromMapToTarget = new SourceFromTestUseDestValue() { A = 100, X = null, Y = null, Name = null };
406+
407+
var txt1 = _sourceFromMapToTarget.BuildAdapter().CreateMapExpression<TestRecordUseDestValue>();
408+
409+
var txt = _sourceFromMapToTarget.BuildAdapter().CreateMapToTargetExpression<TestRecordUseDestValue>();
410+
411+
var _resultMapToTarget = _sourceFromMapToTarget.Adapt(result);
412+
413+
result.A.ShouldBe(0); // default Value - not match
414+
result.S.ShouldBe("Inside Data"); // is not AutoProperty not mod by source
415+
result.Y.ShouldBe(200); // Y is AutoProperty value transmitted from source
416+
result.Name.Name.ShouldBe("John"); // transmitted from source standart method
394417

418+
_resultMapToTarget.A.ShouldBe(100);
419+
_resultMapToTarget.X.ShouldBe(300); // Ignore NullValues work
420+
_resultMapToTarget.Y.ShouldBe(200); // Ignore NullValues work
421+
_resultMapToTarget.Name.Name.ShouldBe("John"); // Ignore NullValues work
422+
423+
}
395424

396425
#region NowNotWorking
397426

@@ -419,6 +448,37 @@ public void CollectionUpdate()
419448

420449

421450
#region TestClasses
451+
public class SourceFromTestUseDestValue
452+
{
453+
public int? A { get; set; }
454+
public int? X { get; set; }
455+
public int? Y { get; set; }
456+
public StudentNameRecord Name { get; set; }
457+
}
458+
459+
460+
public record TestRecordUseDestValue()
461+
{
462+
private string _s = "Inside Data";
463+
464+
public int A { get; set; }
465+
public int X { get; set; }
466+
467+
[UseDestinationValue]
468+
public int Y { get; }
469+
470+
[UseDestinationValue]
471+
public string S { get => _s; }
472+
473+
[UseDestinationValue]
474+
public StudentNameRecord Name { get; } = new StudentNameRecord() { Name = "Marta" };
475+
}
476+
477+
public record StudentNameRecord
478+
{
479+
public string Name { get; set; }
480+
}
481+
422482
public record TestRecordY()
423483
{
424484
public int X { get; set; }
@@ -724,14 +784,5 @@ sealed record TestSealedRecord()
724784

725785
sealed record TestSealedRecordPositional(int X);
726786

727-
728-
729-
730-
731-
732-
733-
734-
735-
736787
#endregion TestClasses
737788
}

0 commit comments

Comments
 (0)