Skip to content

Commit 871467f

Browse files
committed
Use preferred Assert.* patterns
Visual Studio pointed out a couple of instances where `Assert.Equal(0, X.Count)` was used instead of `Assert.Empty(X)`, and similarly `Assert.Equal(1, X.Count)` instead of `Assert.Single(X)`. Let's accept the suggested fixes and thereby address the last remaining warnings when building in Visual Studio. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8efdff8 commit 871467f

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/shared/Core.Tests/ApplicationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public async Task Application_UnconfigureAsync_EmptyAndGcmWithOthersBefore_Remov
244244

245245
Assert.Single(context.Git.Configuration.Global);
246246
Assert.True(context.Git.Configuration.Global.TryGetValue(key, out var actualValues));
247-
Assert.Equal(1, actualValues.Count);
247+
Assert.Single(actualValues);
248248
Assert.Equal(beforeHelper, actualValues[0]);
249249
}
250250

src/shared/Core.Tests/CurlCookieTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void CurlCookieParser_Parse_MissingFields_SkipsInvalidLines()
3737

3838
IList<Cookie> actual = parser.Parse(content);
3939

40-
Assert.Equal(1, actual.Count);
40+
Assert.Single(actual);
4141
AssertCookie(actual[0], ".example.com", "/path/here", true, 0, "cookie1", "value1");
4242
}
4343

src/shared/Core.Tests/HostProviderRegistryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public async Task HostProviderRegistry_GetProvider_Auto_HasProviders_DynamicMatc
119119

120120
Assert.Same(providerMock.Object, result);
121121
Assert.True(context.Git.Configuration.Global.TryGetValue(configKey, out IList<string> config));
122-
Assert.Equal(1, config.Count);
122+
Assert.Single(config);
123123
Assert.Equal(providerId, config[0]);
124124
}
125125

@@ -148,7 +148,7 @@ public async Task HostProviderRegistry_GetProvider_Auto_HasProviders_DynamicMatc
148148

149149
Assert.Same(providerMock.Object, result);
150150
Assert.True(context.Git.Configuration.Global.TryGetValue(configKey, out IList<string> config));
151-
Assert.Equal(1, config.Count);
151+
Assert.Single(config);
152152
Assert.Equal(providerId, config[0]);
153153
}
154154

src/shared/Core.Tests/IniFileTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ recovery tests]
7979
Assert.Equal(6, ini.Sections.Count);
8080

8181
AssertSection(ini, "one", out IniSection one);
82-
Assert.Equal(1, one.Properties.Count);
82+
Assert.Single(one.Properties);
8383
AssertProperty(one, "foo", "123");
8484

8585
AssertSection(ini, "two", out IniSection twoA);
@@ -88,7 +88,7 @@ recovery tests]
8888
AssertProperty(twoA, "widget", "Hello, World!");
8989

9090
AssertSection(ini, "two", "subsection name", out IniSection twoB);
91-
Assert.Equal(1, twoB.Properties.Count);
91+
Assert.Single(twoB.Properties);
9292
AssertProperty(twoB, "foo", "this is different");
9393

9494
AssertSection(ini, "three", out IniSection three);
@@ -97,7 +97,7 @@ recovery tests]
9797
AssertProperty(three, "empty", "");
9898

9999
AssertSection(ini, "four", out IniSection four);
100-
Assert.Equal(0, four.Properties.Count);
100+
Assert.Empty(four.Properties);
101101

102102
AssertSection(ini, "five", out IniSection five);
103103
Assert.Equal(3, five.Properties.Count);

src/shared/Core.Tests/StreamExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void StreamExtensions_ReadDictionary_EmptyString_ReturnsEmptyDictionary()
2121
var output = ReadStringStream(input, StreamExtensions.ReadDictionary);
2222

2323
Assert.NotNull(output);
24-
Assert.Equal(0, output.Count);
24+
Assert.Empty(output);
2525
}
2626

2727
[Fact]
@@ -73,7 +73,7 @@ public void StreamExtensions_ReadDictionary_CaseInsensitive_ReturnsDictionaryWit
7373
var output = ReadStringStream(input, x => StreamExtensions.ReadDictionary(x, StringComparer.OrdinalIgnoreCase));
7474

7575
Assert.NotNull(output);
76-
Assert.Equal(1, output.Count);
76+
Assert.Single(output);
7777
AssertDictionary("2", "a", output);
7878
}
7979

@@ -197,7 +197,7 @@ public void StreamExtensions_ReadMultiDictionary_EmptyString_ReturnsEmptyDiction
197197
var output = ReadStringStream(input, StreamExtensions.ReadMultiDictionary);
198198

199199
Assert.NotNull(output);
200-
Assert.Equal(0, output.Count);
200+
Assert.Empty(output);
201201
}
202202

203203
[Fact]
@@ -250,7 +250,7 @@ public void StreamExtensions_ReadMultiDictionary_CaseInsensitive_ReturnsDictiona
250250
var output = ReadStringStream(input, x => StreamExtensions.ReadMultiDictionary(x, StringComparer.OrdinalIgnoreCase));
251251

252252
Assert.NotNull(output);
253-
Assert.Equal(1, output.Count);
253+
Assert.Single(output);
254254
AssertMultiDictionary(new[] { "2" }, "a", output);
255255
}
256256

@@ -262,7 +262,7 @@ public void StreamExtensions_ReadMultiDictionary_EmptyString_ReturnsKeyWithEmpty
262262
var output = ReadStringStream(input, StreamExtensions.ReadMultiDictionary);
263263

264264
Assert.NotNull(output);
265-
Assert.Equal(1, output.Count);
265+
Assert.Single(output);
266266

267267
AssertMultiDictionary(new[] { String.Empty, }, "a", output);
268268
}

src/shared/TestInfrastructure/Objects/TestHttpMessageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void AssertRequest(HttpMethod method, Uri uri, int expectedNumberOfCalls)
6565

6666
public void AssertNoRequests()
6767
{
68-
Assert.Equal(0, _requestCounts.Count);
68+
Assert.Empty(_requestCounts);
6969
}
7070

7171
#region HttpMessageHandler

0 commit comments

Comments
 (0)