Skip to content

Commit d7f0add

Browse files
authored
coverage: kill ChangeDescription flag/message mutation survivors (#160)
1 parent cea6ead commit d7f0add

5 files changed

Lines changed: 176 additions & 3 deletions

Tests/aweXpect.Testably.Tests/ChangeDescriptionTests.HasChangeType.Tests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async Task Act()
5252

5353
await That(Act).Throws<ArgumentException>()
5454
.WithParamName("unexpected");
55+
await That(Act).Throws<ArgumentException>()
56+
.WithMessage("The unexpected change type must include at least one flag.*").AsWildcard();
5557
}
5658

5759
[Fact]
@@ -97,6 +99,45 @@ async Task Act()
9799

98100
await That(Act).Throws<ArgumentException>()
99101
.WithParamName("expected");
102+
await That(Act).Throws<ArgumentException>()
103+
.WithMessage("The expected change type must include at least one flag.*").AsWildcard();
104+
}
105+
106+
[Fact]
107+
public async Task WhenSubjectIsNull_ShouldFail()
108+
{
109+
ChangeDescription? change = null;
110+
111+
async Task Act()
112+
{
113+
await That(change!).HasChangeType(WatcherChangeTypes.Created);
114+
}
115+
116+
await That(Act).ThrowsException()
117+
.WithMessage("""
118+
Expected that change
119+
has change type Created,
120+
but it was <null>
121+
""");
122+
}
123+
124+
[Fact]
125+
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
126+
{
127+
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));
128+
129+
async Task Act()
130+
{
131+
await That(change)
132+
.HasChangeType(WatcherChangeTypes.Created | WatcherChangeTypes.Deleted);
133+
}
134+
135+
await That(Act).ThrowsException()
136+
.WithMessage("""
137+
Expected that change
138+
has change type Created, Deleted,
139+
but it was Created
140+
""");
100141
}
101142
}
102143
}

Tests/aweXpect.Testably.Tests/ChangeDescriptionTests.HasFileSystemType.Tests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ async Task Act()
5252

5353
await That(Act).Throws<ArgumentException>()
5454
.WithParamName("unexpected");
55+
await That(Act).Throws<ArgumentException>()
56+
.WithMessage("The unexpected file system type must include at least one flag.*").AsWildcard();
5557
}
5658

5759
[Fact]
@@ -66,6 +68,8 @@ async Task Act()
6668

6769
await That(Act).Throws<ArgumentException>()
6870
.WithParamName("expected");
71+
await That(Act).Throws<ArgumentException>()
72+
.WithMessage("The expected file system type must include at least one flag.*").AsWildcard();
6973
}
7074

7175
[Fact]
@@ -98,6 +102,43 @@ async Task Act()
98102

99103
await That(Act).DoesNotThrow();
100104
}
105+
106+
[Fact]
107+
public async Task WhenSubjectIsNull_ShouldFail()
108+
{
109+
ChangeDescription? change = null;
110+
111+
async Task Act()
112+
{
113+
await That(change!).HasFileSystemType(FileSystemTypes.File);
114+
}
115+
116+
await That(Act).ThrowsException()
117+
.WithMessage("""
118+
Expected that change
119+
has file system type File,
120+
but it was <null>
121+
""");
122+
}
123+
124+
[Fact]
125+
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
126+
{
127+
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));
128+
129+
async Task Act()
130+
{
131+
await That(change)
132+
.HasFileSystemType(FileSystemTypes.File | FileSystemTypes.Directory);
133+
}
134+
135+
await That(Act).ThrowsException()
136+
.WithMessage("""
137+
Expected that change
138+
has file system type DirectoryOrFile,
139+
but it was File
140+
""");
141+
}
101142
}
102143
}
103144
}

Tests/aweXpect.Testably.Tests/ChangeDescriptionTests.HasName.Tests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ async Task Act()
1919
}
2020

2121
await That(Act).ThrowsException()
22-
.WithMessage("*has name equal to \"bar.txt\"*").AsWildcard();
22+
.WithMessage("""
23+
Expected that change
24+
has name equal to "bar.txt",
25+
but it was "foo.txt" which differs at index 0:
26+
↓ (actual)
27+
"foo.txt"
28+
"bar.txt"
29+
↑ (expected)
30+
""");
2331
}
2432

2533
[Fact]
@@ -34,6 +42,24 @@ async Task Act()
3442

3543
await That(Act).DoesNotThrow();
3644
}
45+
46+
[Fact]
47+
public async Task WhenSubjectIsNull_ShouldFail()
48+
{
49+
ChangeDescription? change = null;
50+
51+
async Task Act()
52+
{
53+
await That(change!).HasName("foo.txt");
54+
}
55+
56+
await That(Act).ThrowsException()
57+
.WithMessage("""
58+
Expected that change
59+
has name equal to "foo.txt",
60+
but it was <null>
61+
""");
62+
}
3763
}
3864
}
3965
}

Tests/aweXpect.Testably.Tests/ChangeDescriptionTests.HasNotifyFilters.Tests.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ async Task Act()
3434
}
3535

3636
await That(Act).ThrowsException()
37-
.WithMessage("*does not have notify filters*").AsWildcard();
37+
.WithMessage($"""
38+
Expected that change
39+
does not have notify filters {present},
40+
but it did
41+
""");
3842
}
3943

4044
[Fact]
@@ -49,6 +53,8 @@ async Task Act()
4953

5054
await That(Act).Throws<ArgumentException>()
5155
.WithParamName("unexpected");
56+
await That(Act).Throws<ArgumentException>()
57+
.WithMessage("The unexpected notify filters must include at least one flag.*").AsWildcard();
5258
}
5359

5460
[Fact]
@@ -77,20 +83,61 @@ async Task Act()
7783

7884
await That(Act).Throws<ArgumentException>()
7985
.WithParamName("expected");
86+
await That(Act).Throws<ArgumentException>()
87+
.WithMessage("The expected notify filters must include at least one flag.*").AsWildcard();
8088
}
8189

8290
[Fact]
8391
public async Task WhenMissingExpectedFlag_ShouldFail()
8492
{
8593
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));
8694

95+
NotifyFilters actual = change.NotifyFilters;
96+
8797
async Task Act()
8898
{
8999
await That(change).HasNotifyFilters(NotifyFilters.Security);
90100
}
91101

92102
await That(Act).ThrowsException()
93-
.WithMessage("*has notify filters Security*").AsWildcard();
103+
.WithMessage($"""
104+
Expected that change
105+
has notify filters Security,
106+
but it was {actual}
107+
""");
108+
}
109+
110+
[Fact]
111+
public async Task WhenSubjectIsNull_ShouldFail()
112+
{
113+
ChangeDescription? change = null;
114+
115+
async Task Act()
116+
{
117+
await That(change!).HasNotifyFilters(NotifyFilters.FileName);
118+
}
119+
120+
await That(Act).ThrowsException()
121+
.WithMessage("""
122+
Expected that change
123+
has notify filters FileName,
124+
but it was <null>
125+
""");
126+
}
127+
128+
[Fact]
129+
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
130+
{
131+
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));
132+
NotifyFilters present = change.NotifyFilters;
133+
134+
async Task Act()
135+
{
136+
await That(change).HasNotifyFilters(present | NotifyFilters.Security);
137+
}
138+
139+
await That(Act).ThrowsException()
140+
.WithMessage("*has notify filters*Security*but it was*").AsWildcard();
94141
}
95142
}
96143
}

Tests/aweXpect.Testably.Tests/FileSystem.TriggeredNotification.Tests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ but it was not triggered
210210
""");
211211
}
212212

213+
[Fact]
214+
public async Task WhichTwice_WhenChangeDoesNotMatch_ShouldJoinFiltersWithAnd()
215+
{
216+
MockFileSystem sut = new();
217+
sut.File.WriteAllText("foo.txt", "x");
218+
219+
async Task Act()
220+
{
221+
await That(sut).TriggeredNotification()
222+
.Which(c => c.HasName("foo.txt"))
223+
.Which(c => c.HasChangeType(WatcherChangeTypes.Deleted))
224+
.Within(TimeSpan.FromMilliseconds(100));
225+
}
226+
227+
await That(Act).ThrowsException()
228+
.WithMessage("*which has name equal to \"foo.txt\" and has change type Deleted*").AsWildcard();
229+
}
230+
213231
[Fact]
214232
public async Task WhichWithInnerExpectation_WhenChangeMatches_ShouldSucceed()
215233
{

0 commit comments

Comments
 (0)