-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathWhenMappingWithSecondSourceObject.cs
More file actions
63 lines (53 loc) · 1.6 KB
/
WhenMappingWithSecondSourceObject.cs
File metadata and controls
63 lines (53 loc) · 1.6 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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
namespace Mapster.Tests
{
/// <summary>
/// Regression for https://github.com/MapsterMapper/Mapster/issues/485
/// </summary>
[TestClass]
public class WhenMappingWithSecondSourceObject
{
public interface ISomeType
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
public class ConcreteType1 : ISomeType
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
public class ConcreteType2
{
public int Id { get; set; }
public string Name { get; set; }
}
[TestMethod]
public void TestMapFromSecondSourceObject()
{
var c1 = new ConcreteType1
{
Id = 1,
Name = "Name 1",
Address = "Address 1"
};
var c2 = new ConcreteType2
{
Id = 2,
Name = "Name 2"
};
var generatedType = c1.Adapt<ISomeType>();
generatedType.Id.ShouldBe(1);
generatedType.Name.ShouldBe("Name 1");
generatedType.Address.ShouldBe("Address 1");
generatedType = c2.AdaptToTarget(generatedType);
generatedType.Id.ShouldBe(2);
generatedType.Name.ShouldBe("Name 2");
generatedType.Address.ShouldBe("Address 1");
}
}
}