Skip to content

Commit 16f0663

Browse files
authored
coverage: kill statistics/timer mutation survivors (#159)
1 parent d7f0add commit 16f0663

4 files changed

Lines changed: 410 additions & 0 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using Testably.Abstractions.Testing;
2+
3+
namespace aweXpect.Testably.Tests;
4+
5+
public sealed partial class Statistics
6+
{
7+
public sealed partial class Recorded
8+
{
9+
public sealed class DirectoryNegated
10+
{
11+
[Fact]
12+
public async Task WhenNegatingNeverAndCalled_ShouldSucceed()
13+
{
14+
MockFileSystem fileSystem = new();
15+
fileSystem.Directory.CreateDirectory("foo");
16+
17+
async Task Act()
18+
{
19+
await That(fileSystem.Statistics).DoesNotComplyWith(it
20+
=> it.Recorded().Directory.CreateDirectory().Never());
21+
}
22+
23+
await That(Act).DoesNotThrow();
24+
}
25+
26+
[Fact]
27+
public async Task WhenNegatingNeverAndNotCalled_ShouldFailWithAtLeastOneWording()
28+
{
29+
MockFileSystem fileSystem = new();
30+
31+
async Task Act()
32+
{
33+
await That(fileSystem.Statistics).DoesNotComplyWith(it
34+
=> it.Recorded().Directory.CreateDirectory().Never());
35+
}
36+
37+
await That(Act).ThrowsException()
38+
.WithMessage("""
39+
Expected that fileSystem.Statistics
40+
recorded at least one call to Directory.CreateDirectory,
41+
but it was recorded 0 times
42+
""");
43+
}
44+
45+
[Fact]
46+
public async Task WhenNegatingNeverWithMatcherAndNotCalled_ShouldIncludeMatcher()
47+
{
48+
MockFileSystem fileSystem = new();
49+
50+
async Task Act()
51+
{
52+
await That(fileSystem.Statistics).DoesNotComplyWith(it
53+
=> it.Recorded().Directory.CreateDirectory(p => p == "foo").Never());
54+
}
55+
56+
await That(Act).ThrowsException()
57+
.WithMessage("""
58+
Expected that fileSystem.Statistics
59+
recorded at least one call to Directory.CreateDirectory with path matching p => p == "foo",
60+
but it was recorded 0 times
61+
""");
62+
}
63+
64+
[Fact]
65+
public async Task WhenNegatingExactlyAndMatching_ShouldFailWithDidNotRecordWording()
66+
{
67+
MockFileSystem fileSystem = new();
68+
fileSystem.Directory.CreateDirectory("foo");
69+
70+
async Task Act()
71+
{
72+
await That(fileSystem.Statistics).DoesNotComplyWith(it
73+
=> it.Recorded().Directory.CreateDirectory().Once());
74+
}
75+
76+
await That(Act).ThrowsException()
77+
.WithMessage("""
78+
Expected that fileSystem.Statistics
79+
did not record a call to Directory.CreateDirectory exactly once,
80+
but it was recorded 1 time
81+
""");
82+
}
83+
}
84+
}
85+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Testably.Abstractions.Testing;
2+
3+
namespace aweXpect.Testably.Tests;
4+
5+
public sealed partial class Statistics
6+
{
7+
public sealed partial class Recorded
8+
{
9+
public sealed class DirectoryTwoMatchers
10+
{
11+
#if NET8_0_OR_GREATER
12+
[Fact]
13+
public async Task WithTwoMatchers_NoMatch_ShouldJoinMatchersWithComma()
14+
{
15+
MockFileSystem fileSystem = new();
16+
17+
async Task Act()
18+
{
19+
await That(fileSystem.Statistics).Recorded()
20+
.Directory.CreateSymbolicLink(p => p == "foo", t => t == "bar").Once();
21+
}
22+
23+
await That(Act).ThrowsException()
24+
.WithMessage("""
25+
Expected that fileSystem.Statistics
26+
recorded a call to Directory.CreateSymbolicLink with path matching p => p == "foo", pathToTarget matching t => t == "bar" exactly once,
27+
but it was recorded 0 times
28+
""");
29+
}
30+
31+
[Fact]
32+
public async Task WithNeverAndMatcher_Matching_ShouldFailIncludingMatcher()
33+
{
34+
MockFileSystem fileSystem = new();
35+
fileSystem.Directory.CreateDirectory("target");
36+
fileSystem.Directory.CreateSymbolicLink("link", "target");
37+
38+
async Task Act()
39+
{
40+
await That(fileSystem.Statistics).Recorded()
41+
.Directory.CreateSymbolicLink(p => p == "link").Never();
42+
}
43+
44+
await That(Act).ThrowsException()
45+
.WithMessage("""
46+
Expected that fileSystem.Statistics
47+
recorded no call to Directory.CreateSymbolicLink with path matching p => p == "link",
48+
but it was recorded 1 time
49+
""");
50+
}
51+
#endif
52+
}
53+
}
54+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
using System.IO.Abstractions;
2+
using Testably.Abstractions.Testing;
3+
4+
namespace aweXpect.Testably.Tests;
5+
6+
public sealed partial class Statistics
7+
{
8+
public sealed partial class Recorded
9+
{
10+
public sealed class FileInfoPropertyAccess
11+
{
12+
[Fact]
13+
public async Task WhenNeverAccessed_NeverGet_ShouldSucceed()
14+
{
15+
MockFileSystem fileSystem = new();
16+
fileSystem.File.WriteAllText("foo.txt", "");
17+
18+
async Task Act()
19+
{
20+
await That(fileSystem.Statistics).Recorded()
21+
.FileInfo["foo.txt"].IsReadOnly.Get().Never();
22+
}
23+
24+
await That(Act).DoesNotThrow();
25+
}
26+
27+
[Fact]
28+
public async Task WhenAccessed_NeverGet_ShouldFailWithNoGetWording()
29+
{
30+
MockFileSystem fileSystem = new();
31+
fileSystem.File.WriteAllText("foo.txt", "");
32+
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
33+
_ = fileInfo.IsReadOnly;
34+
35+
async Task Act()
36+
{
37+
await That(fileSystem.Statistics).Recorded()
38+
.FileInfo["foo.txt"].IsReadOnly.Get().Never();
39+
}
40+
41+
await That(Act).ThrowsException()
42+
.WithMessage("""
43+
Expected that fileSystem.Statistics
44+
recorded no get of FileInfo["foo.txt"].IsReadOnly,
45+
but it was recorded 1 time
46+
""");
47+
}
48+
49+
[Fact]
50+
public async Task WhenSet_NeverSet_ShouldFailWithNoSetWording()
51+
{
52+
MockFileSystem fileSystem = new();
53+
fileSystem.File.WriteAllText("foo.txt", "");
54+
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
55+
fileInfo.IsReadOnly = false;
56+
57+
async Task Act()
58+
{
59+
await That(fileSystem.Statistics).Recorded()
60+
.FileInfo["foo.txt"].IsReadOnly.Set().Never();
61+
}
62+
63+
await That(Act).ThrowsException()
64+
.WithMessage("""
65+
Expected that fileSystem.Statistics
66+
recorded no set of FileInfo["foo.txt"].IsReadOnly,
67+
but it was recorded 1 time
68+
""");
69+
}
70+
71+
[Fact]
72+
public async Task WhenNegatingNeverGetAndAccessed_ShouldSucceed()
73+
{
74+
MockFileSystem fileSystem = new();
75+
fileSystem.File.WriteAllText("foo.txt", "");
76+
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
77+
_ = fileInfo.IsReadOnly;
78+
79+
async Task Act()
80+
{
81+
await That(fileSystem.Statistics).DoesNotComplyWith(it
82+
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Never());
83+
}
84+
85+
await That(Act).DoesNotThrow();
86+
}
87+
88+
[Fact]
89+
public async Task WhenNegatingNeverGetAndNotAccessed_ShouldFailWithAtLeastOneGetWording()
90+
{
91+
MockFileSystem fileSystem = new();
92+
fileSystem.File.WriteAllText("foo.txt", "");
93+
94+
async Task Act()
95+
{
96+
await That(fileSystem.Statistics).DoesNotComplyWith(it
97+
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Never());
98+
}
99+
100+
await That(Act).ThrowsException()
101+
.WithMessage("""
102+
Expected that fileSystem.Statistics
103+
recorded at least one get of FileInfo["foo.txt"].IsReadOnly,
104+
but it was recorded 0 times
105+
""");
106+
}
107+
108+
[Fact]
109+
public async Task WhenNegatingNeverSetAndNotAccessed_ShouldFailWithAtLeastOneSetWording()
110+
{
111+
MockFileSystem fileSystem = new();
112+
fileSystem.File.WriteAllText("foo.txt", "");
113+
114+
async Task Act()
115+
{
116+
await That(fileSystem.Statistics).DoesNotComplyWith(it
117+
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Set().Never());
118+
}
119+
120+
await That(Act).ThrowsException()
121+
.WithMessage("""
122+
Expected that fileSystem.Statistics
123+
recorded at least one set of FileInfo["foo.txt"].IsReadOnly,
124+
but it was recorded 0 times
125+
""");
126+
}
127+
128+
[Fact]
129+
public async Task WhenNegatingExactlyGetAndAccessed_ShouldFailWithDidNotRecordGetWording()
130+
{
131+
MockFileSystem fileSystem = new();
132+
fileSystem.File.WriteAllText("foo.txt", "");
133+
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
134+
_ = fileInfo.IsReadOnly;
135+
136+
async Task Act()
137+
{
138+
await That(fileSystem.Statistics).DoesNotComplyWith(it
139+
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Once());
140+
}
141+
142+
await That(Act).ThrowsException()
143+
.WithMessage("""
144+
Expected that fileSystem.Statistics
145+
did not record a get of FileInfo["foo.txt"].IsReadOnly exactly once,
146+
but it was recorded 1 time
147+
""");
148+
}
149+
}
150+
}
151+
}

0 commit comments

Comments
 (0)