Skip to content

Commit 9209724

Browse files
authored
Upgrade xunit version to 2.9.0 (#57303)
* Upgrade Xunit version to 2.9.0 * React to removed/changed xunit exceptions * Fix ambiguous calls * Replace Assert.True(false, ...) with Assert.Fail * Await async methods and change async void -> async Task * Use Assert.Equal for string equality checks * Apply analyzer fixes: use Assert.Single and Assert.Empty * Apply analyzer fixes: null parameter in Theory data * Fix TheoryData generic mismatch * Test methods can't return value * Suppress Do not call ConfigureAwait(false) in test method * Suppress Do not use blocking task operations in test method * Suppress Fixture arguments to test classes must have fixture sources * Fix DllNotFoundException in HttpApi on non-Windows platforms * Disable tests that were unintentionally skipped before and fail now * Fix generated test code * Disable generated tests that were unintentionally skipped before and fail now * Add issue link to ResultsOfTTests.Generated.cs * Add issue link to UserManagerTest.cs * Disable xUnit1030 globally * Move check for HttpApi into test code * Revert changes to ResultsOfTTests, they were fixed
1 parent 30fb87c commit 9209724

File tree

270 files changed

+870
-836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+870
-836
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
<!-- xUnit1004 = warns about skipped tests. Make this a non-fatal build warning. -->
131131
<WarningsNotAsErrors>$(WarningsNotAsErrors);xUnit1004</WarningsNotAsErrors>
132132

133+
<!-- don't warn about calling ConfigureAwait in test methods. we already commonly get off the xunit threads because they cause issues. -->
134+
<NoWarn>$(NoWarn);xUnit1030</NoWarn>
135+
133136
<!-- don't warn about unnecessary trim warning suppressions. can be removed with preview 6. -->
134137
<NoWarn>$(NoWarn);IL2121</NoWarn>
135138

eng/Versions.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@
322322
<SwashbuckleAspNetCoreVersion>6.6.2</SwashbuckleAspNetCoreVersion>
323323
<VerifyXunitVersion>19.14.0</VerifyXunitVersion>
324324
<XunitAbstractionsVersion>2.0.3</XunitAbstractionsVersion>
325-
<XunitAnalyzersVersion>1.0.0</XunitAnalyzersVersion>
326-
<XunitVersion>2.4.2</XunitVersion>
325+
<XunitAnalyzersVersion>1.15.0</XunitAnalyzersVersion>
326+
<XunitVersion>2.9.0</XunitVersion>
327327
<XunitAssertVersion>$(XunitVersion)</XunitAssertVersion>
328328
<XunitExtensibilityCoreVersion>$(XunitVersion)</XunitExtensibilityCoreVersion>
329329
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
330-
<XUnitRunnerVisualStudioVersion>2.4.3</XUnitRunnerVisualStudioVersion>
330+
<XUnitRunnerVisualStudioVersion>2.8.2</XUnitRunnerVisualStudioVersion>
331331
<MicrosoftDataSqlClientVersion>4.0.5</MicrosoftDataSqlClientVersion>
332332
<MicrosoftOpenApiVersion>1.6.17</MicrosoftOpenApiVersion>
333333
<MicrosoftOpenApiReadersVersion>1.6.17</MicrosoftOpenApiReadersVersion>

src/Analyzers/Microsoft.AspNetCore.Analyzer.Testing/src/Assert.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void DiagnosticLocation(DiagnosticLocation expected, Location actu
1818
{
1919
if (actualLinePosition.Line + 1 != expected.Line)
2020
{
21-
throw new DiagnosticLocationAssertException(
21+
throw EqualException.ForMismatchedValues(
2222
expected,
2323
actual,
2424
$"Expected diagnostic to be on line \"{expected.Line}\" was actually on line \"{actualLinePosition.Line + 1}\"");
@@ -30,25 +30,11 @@ public static void DiagnosticLocation(DiagnosticLocation expected, Location actu
3030
{
3131
if (actualLinePosition.Character + 1 != expected.Column)
3232
{
33-
throw new DiagnosticLocationAssertException(
33+
throw EqualException.ForMismatchedValues(
3434
expected,
3535
actual,
3636
$"Expected diagnostic to start at column \"{expected.Column}\" was actually on column \"{actualLinePosition.Character + 1}\"");
3737
}
3838
}
3939
}
40-
41-
private sealed class DiagnosticLocationAssertException : EqualException
42-
{
43-
public DiagnosticLocationAssertException(
44-
DiagnosticLocation expected,
45-
Location actual,
46-
string message)
47-
: base(expected, actual)
48-
{
49-
Message = message;
50-
}
51-
52-
public override string Message { get; }
53-
}
5440
}

src/Antiforgery/test/BinaryBlobTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public void Ctor_Data()
5656
[Theory]
5757
[InlineData((object[]?)null)]
5858
[InlineData(new byte[] { 0x01, 0x02, 0x03 })]
59-
public void Ctor_Data_Bad(byte[] data)
59+
public void Ctor_Data_Bad(byte[]? data)
6060
{
6161
// Act & assert
62-
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new BinaryBlob(32, data));
62+
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new BinaryBlob(32, data!));
6363
Assert.Equal("data", ex.ParamName);
6464
}
6565

src/Antiforgery/test/DefaultAntiforgeryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ public void SetCookieTokenAndHeader_OverridesExistingCachingHeaders()
10791079
[InlineData(true, null)]
10801080
public void SetCookieTokenAndHeader_AddsXFrameOptionsHeader(
10811081
bool suppressXFrameOptions,
1082-
string expectedHeaderValue)
1082+
string? expectedHeaderValue)
10831083
{
10841084
// Arrange
10851085
var options = new AntiforgeryOptions()

src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public void SaveCookieToken_HonorsCookieSecurePolicy_OnOptions(
396396
[InlineData("/", "/")]
397397
[InlineData("/vdir1", "/vdir1")]
398398
[InlineData("/vdir1/vdir2", "/vdir1/vdir2")]
399-
public void SaveCookieToken_SetsCookieWithApproriatePathBase(string requestPathBase, string expectedCookiePath)
399+
public void SaveCookieToken_SetsCookieWithApproriatePathBase(string? requestPathBase, string expectedCookiePath)
400400
{
401401
// Arrange
402402
var token = "serialized-value";

src/Components/Analyzers/test/Verifiers/CodeFixVerifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void VerifyFix(string language, DiagnosticAnalyzer analyzer, CodeFixProv
109109
document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().Result, Formatter.Annotation, document.Project.Solution.Workspace));
110110
newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, GetCompilerDiagnostics(document));
111111

112-
Assert.True(false,
112+
Assert.Fail(
113113
string.Format(
114114
CultureInfo.InvariantCulture,
115115
"Fix introduced new compiler diagnostics:\r\n{0}\r\n\r\nNew document:\r\n{1}\r\n",

src/Components/Analyzers/test/Verifiers/DiagnosticVerifier.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
112112
{
113113
string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) : " NONE.";
114114

115-
Assert.True(false,
115+
Assert.Fail(
116116
string.Format(CultureInfo.InvariantCulture, "Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}\"\r\n\r\nDiagnostics:\r\n{2}\r\n", expectedCount, actualCount, diagnosticsOutput));
117117
}
118118

@@ -125,7 +125,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
125125
{
126126
if (actual.Location != Location.None)
127127
{
128-
Assert.True(false,
128+
Assert.Fail(
129129
string.Format(CultureInfo.InvariantCulture, "Expected:\nA project diagnostic with No location\nActual:\n{0}",
130130
FormatDiagnostics(analyzer, actual)));
131131
}
@@ -137,7 +137,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
137137

138138
if (additionalLocations.Length != expected.Locations.Length - 1)
139139
{
140-
Assert.True(false,
140+
Assert.Fail(
141141
string.Format(
142142
CultureInfo.InvariantCulture,
143143
"Expected {0} additional locations but got {1} for Diagnostic:\r\n {2}\r\n",
@@ -153,7 +153,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
153153

154154
if (actual.Id != expected.Id)
155155
{
156-
Assert.True(false,
156+
Assert.Fail(
157157
string.Format(
158158
CultureInfo.InvariantCulture,
159159
"Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
@@ -162,7 +162,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
162162

163163
if (actual.Severity != expected.Severity)
164164
{
165-
Assert.True(false,
165+
Assert.Fail(
166166
string.Format(
167167
CultureInfo.InvariantCulture,
168168
"Expected diagnostic severity to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
@@ -171,7 +171,7 @@ private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResult
171171

172172
if (actual.GetMessage(CultureInfo.InvariantCulture) != expected.Message)
173173
{
174-
Assert.True(false,
174+
Assert.Fail(
175175
string.Format(
176176
CultureInfo.InvariantCulture,
177177
"Expected diagnostic message to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
@@ -204,7 +204,7 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno
204204
{
205205
if (actualLinePosition.Line + 1 != expected.Line)
206206
{
207-
Assert.True(false,
207+
Assert.Fail(
208208
string.Format(
209209
CultureInfo.InvariantCulture,
210210
"Expected diagnostic to be on line \"{0}\" was actually on line \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
@@ -217,7 +217,7 @@ private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagno
217217
{
218218
if (actualLinePosition.Character + 1 != expected.Column)
219219
{
220-
Assert.True(false,
220+
Assert.Fail(
221221
string.Format(
222222
CultureInfo.InvariantCulture,
223223
"Expected diagnostic to start at column \"{0}\" was actually at column \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",

src/Components/Authorization/test/AuthorizeViewTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public async Task RendersAuthorizingUntilAuthorizationCompletedAsync()
321321
// (This wouldn't happen under the sync context or in wasm)
322322
var renderTcs = new TaskCompletionSource();
323323
renderer.OnUpdateDisplayComplete = () => renderTcs.SetResult();
324-
authTcs.SetResult(CreateAuthenticationState("Monsieur").Result);
324+
authTcs.SetResult(await CreateAuthenticationState("Monsieur"));
325325

326326
await renderTcs.Task;
327327
Assert.Equal(2, renderer.Batches.Count);
@@ -347,7 +347,7 @@ public async Task RendersAuthorizingUntilAuthorizationCompletedAsync()
347347
}
348348

349349
[Fact]
350-
public void RendersAuthorizingUntilAuthorizationCompleted()
350+
public async Task RendersAuthorizingUntilAuthorizationCompleted()
351351
{
352352
// Arrange
353353
var @event = new ManualResetEventSlim();
@@ -377,7 +377,7 @@ public void RendersAuthorizingUntilAuthorizationCompleted()
377377

378378
// Act/Assert 2: Auth process completes asynchronously
379379
@event.Reset();
380-
authTcs.SetResult(CreateAuthenticationState("Monsieur").Result);
380+
authTcs.SetResult(await CreateAuthenticationState("Monsieur"));
381381

382382
// We need to wait here because the continuations of SetResult will be scheduled to run asynchronously.
383383
@event.Wait(Timeout);

src/Components/Components/test/LayoutViewTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void CanChangeContentWithSameLayout()
178178
// Assert
179179
Assert.Equal(2, _renderer.Batches.Count);
180180
var batch = _renderer.Batches[1];
181-
Assert.Equal(0, batch.DisposedComponentIDs.Count);
181+
Assert.Empty(batch.DisposedComponentIDs);
182182
Assert.Collection(batch.DiffsInOrder,
183183
diff => Assert.Empty(diff.Edits), // LayoutView rerendered, but with no changes
184184
diff => Assert.Empty(diff.Edits), // RootLayout rerendered, but with no changes
@@ -220,7 +220,7 @@ public void CanChangeLayout()
220220
Assert.True(setParametersTask2.IsCompletedSuccessfully);
221221
Assert.Equal(2, _renderer.Batches.Count);
222222
var batch = _renderer.Batches[1];
223-
Assert.Equal(1, batch.DisposedComponentIDs.Count); // Disposes NestedLayout
223+
Assert.Single(batch.DisposedComponentIDs); // Disposes NestedLayout
224224
Assert.Collection(batch.DiffsInOrder,
225225
diff => Assert.Empty(diff.Edits), // LayoutView rerendered, but with no changes
226226
diff =>

0 commit comments

Comments
 (0)