-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathBuildTests.cs
More file actions
99 lines (82 loc) · 3.14 KB
/
Copy pathBuildTests.cs
File metadata and controls
99 lines (82 loc) · 3.14 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using Shouldly;
using TestStack.Dossier.Tests.TestHelpers.Builders;
using TestStack.Dossier.Tests.TestHelpers.Objects.Entities;
using Xunit;
namespace TestStack.Dossier.Tests
{
public class BuildTests
{
[Fact]
public void GivenBasicBuilder_WhenCallingBuildExplicitly_ThenReturnAnObject()
{
var builder = new BasicCustomerBuilder();
var customer = builder.Build();
customer.ShouldBeOfType<Customer>();
}
[Fact]
public void GivenBuilderWithMethodCalls_WhenCallingBuildExplicitly_ThenReturnAnObjectWithTheConfiguredParameters()
{
var builder = new CustomerBuilder()
.WithFirstName("Matt")
.WithLastName("Kocaj")
.WhoJoinedIn(2010);
var customer = builder.Build();
customer.FirstName.ShouldBe("Matt");
customer.LastName.ShouldBe("Kocaj");
customer.YearJoined.ShouldBe(2010);
}
[Fact]
public void GivenBuilder_WhenCallingSetExplicitly_ShouldOverrideValues()
{
var builder = new CustomerBuilder()
.Set(x => x.FirstName, "Pi")
.Set(x => x.LastName, "Lanningham")
.Set(x => x.YearJoined, 2014);
var customer = builder.Build();
customer.FirstName.ShouldBe("Pi");
customer.LastName.ShouldBe("Lanningham");
customer.YearJoined.ShouldBe(2014);
}
[Fact]
public void GivenBasicBuilder_WhenCallingBuildImplicitly_ThenReturnAnObject()
{
Customer customer = new BasicCustomerBuilder();
customer.ShouldBeOfType<Customer>();
}
[Fact]
public void GivenBuilderWithMethodCalls_WhenCallingBuildImplicitly_ThenReturnAnObjectWithTheConfiguredParameters()
{
Customer customer = new CustomerBuilder()
.WithFirstName("Matt")
.WithLastName("Kocaj")
.WhoJoinedIn(2010);
customer.FirstName.ShouldBe("Matt");
customer.LastName.ShouldBe("Kocaj");
customer.YearJoined.ShouldBe(2010);
}
[Fact]
public void GivenBuilder_WhenCallingSetImplicitly_ShouldOverrideValues()
{
Customer customer = new CustomerBuilder()
.Set(x => x.FirstName, "Pi")
.Set(x => x.LastName, "Lanningham")
.Set(x => x.YearJoined, 2014);
customer.FirstName.ShouldBe("Pi");
customer.LastName.ShouldBe("Lanningham");
customer.YearJoined.ShouldBe(2014);
}
[Fact]
public void GivenBuilderUsingConstructorReflection_WhenCallingBuildExplicitly_ShouldOverrideValues()
{
Customer customer = new AutoConstructorCustomerBuilder()
.WithFirstName("Bruce")
.WithLastName("Wayne")
.WhoJoinedIn(2012)
.Build();
customer.FirstName.ShouldBe("Bruce");
customer.LastName.ShouldBe("Wayne");
customer.YearJoined.ShouldBe(2012);
}
}
}