-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathWhenMappingStructRegression.cs
More file actions
80 lines (69 loc) · 2 KB
/
WhenMappingStructRegression.cs
File metadata and controls
80 lines (69 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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.AdaptToTarget(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.AdaptToTarget(dest);
dest.Ignore.ShouldBe("Ignored property");
dest.Name.ShouldBe("Some Name");
}
}
}