-
-
Notifications
You must be signed in to change notification settings - Fork 540
/
GuidAssertionSpecs.cs
213 lines (174 loc) · 7.3 KB
/
GuidAssertionSpecs.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using System;
using Xunit;
using Xunit.Sdk;
namespace FluentAssertions.Specs.Primitives
{
public class GuidAssertionSpecs
{
public class BeEmpty
{
[Fact]
public void Should_succeed_when_asserting_empty_guid_is_empty()
{
// Arrange
Guid guid = Guid.Empty;
// Act / Assert
guid.Should().BeEmpty();
}
[Fact]
public void Should_fail_when_asserting_non_empty_guid_is_empty()
{
// Arrange
var guid = new Guid("12345678-1234-1234-1234-123456789012");
// Act
Action act = () => guid.Should().BeEmpty("because we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>().WithMessage(
"Expected Guid to be empty because we want to test the failure message, but found {12345678-1234-1234-1234-123456789012}.");
}
}
public class NotBeEmpty
{
[Fact]
public void Should_succeed_when_asserting_non_empty_guid_is_not_empty()
{
// Arrange
var guid = new Guid("12345678-1234-1234-1234-123456789012");
// Act
Action act = () => guid.Should().NotBeEmpty();
// Assert
act.Should().NotThrow();
}
[Fact]
public void Should_fail_when_asserting_empty_guid_is_not_empty()
{
// Act
Action act = () => Guid.Empty.Should().NotBeEmpty("because we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>().WithMessage(
"Did not expect Guid.Empty to be empty because we want to test the failure message.");
}
}
public class Be
{
[Fact]
public void Should_succeed_when_asserting_guid_equals_the_same_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () => guid.Should().Be(sameGuid);
// Assert
act.Should().NotThrow();
}
[Fact]
public void Should_succeed_when_asserting_guid_equals_the_same_guid_in_string_format()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () => guid.Should().Be("11111111-aaaa-bbbb-cccc-999999999999");
// Assert
act.Should().NotThrow();
}
[Fact]
public void Should_fail_when_asserting_guid_equals_a_different_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444");
// Act
Action act = () => guid.Should().Be(differentGuid, "because we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>().WithMessage(
"Expected Guid to be {55555555-ffff-eeee-dddd-444444444444} because we want to test the failure message, but found {11111111-aaaa-bbbb-cccc-999999999999}.");
}
[Fact]
public void Should_throw_when_asserting_guid_equals_a_string_that_is_not_a_valid_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () => guid.Should().Be(string.Empty, "we want to test the failure {0}", "message");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("expected");
}
}
public class NotBe
{
[Fact]
public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
var differentGuid = new Guid("55555555-ffff-eeee-dddd-444444444444");
// Act
Action act = () =>
guid.Should().NotBe(differentGuid);
// Assert
act.Should().NotThrow();
}
[Fact]
public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
var sameGuid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () => guid.Should().NotBe(sameGuid, "because we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>().WithMessage(
"Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} because we want to test the failure message.");
}
[Fact]
public void Should_throw_when_asserting_guid_does_not_equal_a_string_that_is_not_a_valid_guid()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () => guid.Should().NotBe(string.Empty, "we want to test the failure {0}", "message");
// Assert
act.Should().Throw<ArgumentException>()
.WithParameterName("unexpected");
}
[Fact]
public void Should_succeed_when_asserting_guid_does_not_equal_a_different_guid_in_string_format()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () =>
guid.Should().NotBe("55555555-ffff-eeee-dddd-444444444444");
// Assert
act.Should().NotThrow();
}
[Fact]
public void Should_succeed_when_asserting_guid_does_not_equal_the_same_guid_in_string_format()
{
// Arrange
var guid = new Guid("11111111-aaaa-bbbb-cccc-999999999999");
// Act
Action act = () =>
guid.Should().NotBe("11111111-aaaa-bbbb-cccc-999999999999", "we want to test the failure {0}", "message");
// Assert
act.Should().Throw<XunitException>()
.WithMessage("Did not expect Guid to be {11111111-aaaa-bbbb-cccc-999999999999} *failure message*.");
}
}
public class ChainingConstraint
{
[Fact]
public void Should_support_chaining_constraints_with_and()
{
// Arrange
Guid guid = Guid.NewGuid();
// Act / Assert
guid.Should()
.NotBeEmpty()
.And.Be(guid);
}
}
}
}