-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #510 where existing structs were incorrectly mapped.
- Loading branch information
Showing
2 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Mapster; | ||
using MapsterMapper; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Shouldly; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static Mapster.Tests.WhenMappingStructRegression; | ||
|
||
namespace Mapster.Tests | ||
{ | ||
/// <summary> | ||
/// Regression tests for https://github.com/MapsterMapper/Mapster/issues/510 | ||
/// </summary> | ||
[TestClass] | ||
public class WhenMappingStructRegression | ||
{ | ||
public struct SourceClass | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
public struct SourceStruct | ||
{ | ||
public string Name { get; set; } | ||
} | ||
public struct DestinationStruct | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string Ignore { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void TestMapStructToExistingStruct() | ||
{ | ||
|
||
TypeAdapterConfig<SourceStruct, DestinationStruct> | ||
.ForType() | ||
.Ignore(s => s.Ignore); | ||
|
||
var source = new SourceStruct | ||
{ | ||
Name = "Some Name", | ||
}; | ||
var dest = new DestinationStruct | ||
{ | ||
Ignore = "Ignored property", | ||
}; | ||
dest = source.Adapt(dest); | ||
|
||
dest.Ignore.ShouldBe("Ignored property"); | ||
dest.Name.ShouldBe("Some Name"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestMapClassToExistingStruct() | ||
{ | ||
|
||
TypeAdapterConfig<SourceClass, DestinationStruct> | ||
.ForType() | ||
.Ignore(s => s.Ignore); | ||
|
||
var source = new SourceClass | ||
{ | ||
Name = "Some Name", | ||
}; | ||
var dest = new DestinationStruct | ||
{ | ||
Ignore = "Ignored property", | ||
}; | ||
dest = source.Adapt(dest); | ||
|
||
dest.Ignore.ShouldBe("Ignored property"); | ||
dest.Name.ShouldBe("Some Name"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters