|
2 | 2 | using Shouldly; |
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
| 5 | +using static Mapster.Tests.WhenExplicitMappingRequired; |
5 | 6 | using static Mapster.Tests.WhenMappingDerived; |
6 | 7 |
|
7 | 8 | namespace Mapster.Tests |
@@ -474,22 +475,6 @@ public void ClassCtorAutomapingWorking() |
474 | 475 | result.X.ShouldBe(100); |
475 | 476 | } |
476 | 477 |
|
477 | | - /// <summary> |
478 | | - /// https://github.com/MapsterMapper/Mapster/issues/842 |
479 | | - /// </summary> |
480 | | - [TestMethod] |
481 | | - public void ClassCustomCtorWitoutMapNotWorking() |
482 | | - { |
483 | | - TypeAdapterConfig.GlobalSettings.Clear(); |
484 | | - |
485 | | - var source = new TestRecord() { X = 100 }; |
486 | | - |
487 | | - Should.Throw<InvalidOperationException>(() => |
488 | | - { |
489 | | - source.Adapt<AutoCtorDestYx>(); |
490 | | - }); |
491 | | - } |
492 | | - |
493 | 478 | /// <summary> |
494 | 479 | /// https://github.com/MapsterMapper/Mapster/issues/842 |
495 | 480 | /// </summary> |
@@ -537,6 +522,24 @@ public void ClassUpdateAutoPropertyWitoutSetterWorking() |
537 | 522 | result.X.ShouldBe(200); |
538 | 523 | } |
539 | 524 |
|
| 525 | + /// <summary> |
| 526 | + /// https://github.com/MapsterMapper/Mapster/issues/883 |
| 527 | + /// </summary> |
| 528 | + [TestMethod] |
| 529 | + public void ClassCtorActivateDefaultValue() |
| 530 | + { |
| 531 | + var source = new Source833 |
| 532 | + { |
| 533 | + Value1 = "123", |
| 534 | + }; |
| 535 | + |
| 536 | + Should.NotThrow(() => |
| 537 | + { |
| 538 | + var target = source.Adapt<Target833>(); |
| 539 | + target.Value1.ShouldBe("123"); |
| 540 | + target.Value2.ShouldBe(default); |
| 541 | + }); |
| 542 | + } |
540 | 543 |
|
541 | 544 | #region NowNotWorking |
542 | 545 |
|
@@ -565,6 +568,24 @@ public void CollectionUpdate() |
565 | 568 |
|
566 | 569 | #region TestClasses |
567 | 570 |
|
| 571 | + public class Source833 |
| 572 | + { |
| 573 | + public required string Value1 { get; init; } |
| 574 | + } |
| 575 | + |
| 576 | + public class Target833 |
| 577 | + { |
| 578 | + public Target833(string value1, string value2) |
| 579 | + { |
| 580 | + Value1 = value1; |
| 581 | + Value2 = value2; |
| 582 | + } |
| 583 | + |
| 584 | + public string Value1 { get; } |
| 585 | + |
| 586 | + public string Value2 { get; } |
| 587 | + } |
| 588 | + |
568 | 589 | public sealed record Database746( |
569 | 590 | string Server = "", |
570 | 591 | string Name = "", |
|
0 commit comments