-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathWhenIgnoringNonMapped.cs
53 lines (47 loc) · 1.4 KB
/
WhenIgnoringNonMapped.cs
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
namespace Mapster.Tests
{
[TestClass]
public class WhenIgnoringNonMapped
{
[TestMethod]
public void Should_Ignore_Non_Mapped()
{
TypeAdapterConfig<SimplePoco, SimpleDto>.NewConfig()
.Map(dest => dest.Id, src => src.Id)
.RequireDestinationMemberSource(true)
.IgnoreNonMapped(true)
.Compile();
var poco = new SimplePoco
{
Id = Guid.NewGuid(),
Name1 = "Name1",
Name2 = "Name2",
Name3 = "Name3"
};
var dto = poco.Adapt<SimplePoco, SimpleDto>();
dto.Id.ShouldBe(poco.Id);
dto.Name1.ShouldBeNull();
dto.Name2.ShouldBeNull();
dto.Name3.ShouldBeNull();
}
#region test classes
public class SimplePoco
{
public Guid Id { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
}
public class SimpleDto
{
public Guid Id { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
}
#endregion
}
}