Skip to content

Commit 882c0d3

Browse files
dougbuericstj
andauthored
Move to newer xUnit packages (#43598)
* Get newer xUnit packages - move to `2.4.2` version of most xUnit packages - we were slightly behind Arcade SDK here and newer version has some fixes - _could_ reuse Arcade SDK's `$(XUnitVersion)` - that would require moving e.g. `$(XUnitAssertVersion)` to (say) CSharp.Common.props - VersionDefaults.props in SDK imports our Versions.props before setting its defaults - react to nullability errors due to new annotations in this version - move to XUnit.Abstractions `1.0.0` - react to issues new analyzer finds * Workaround Xunit bug casting InlineData (#43570) See xunit/xunit#2564 Workaround this issue by avoiding a cast between nullable numeric types. Co-authored-by: Eric StJohn <[email protected]>
1 parent da62bba commit 882c0d3

File tree

16 files changed

+54
-48
lines changed

16 files changed

+54
-48
lines changed

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@
280280
<SystemReactiveLinqVersion>5.0.0</SystemReactiveLinqVersion>
281281
<SwashbuckleAspNetCoreVersion>6.4.0</SwashbuckleAspNetCoreVersion>
282282
<XunitAbstractionsVersion>2.0.3</XunitAbstractionsVersion>
283-
<XunitAnalyzersVersion>0.10.0</XunitAnalyzersVersion>
284-
<XunitVersion>2.4.1</XunitVersion>
283+
<XunitAnalyzersVersion>1.0.0</XunitAnalyzersVersion>
284+
<XunitVersion>2.4.2</XunitVersion>
285285
<XunitAssertVersion>$(XunitVersion)</XunitAssertVersion>
286286
<XunitExtensibilityCoreVersion>$(XunitVersion)</XunitExtensibilityCoreVersion>
287287
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>

src/Http/Http.Extensions/test/HttpRequestJsonExtensionsTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public async Task ReadFromJsonAsyncGeneric_WithOptions_ReturnValue()
7070
var result = await context.Request.ReadFromJsonAsync<List<int>>(options);
7171

7272
// Assert
73+
Assert.NotNull(result);
7374
Assert.Collection(result,
7475
i => Assert.Equal(1, i),
7576
i => Assert.Equal(2, i));
@@ -87,6 +88,7 @@ public async Task ReadFromJsonAsyncGeneric_Utf8Encoding_ReturnValue()
8788
var result = await context.Request.ReadFromJsonAsync<List<int>>();
8889

8990
// Assert
91+
Assert.NotNull(result);
9092
Assert.Collection(result,
9193
i => Assert.Equal(1, i),
9294
i => Assert.Equal(2, i));
@@ -200,6 +202,7 @@ public async Task ReadFromJsonAsync_WithOptions_ReturnValue()
200202
var result = (List<int>?)await context.Request.ReadFromJsonAsync(typeof(List<int>), options);
201203

202204
// Assert
205+
Assert.NotNull(result);
203206
Assert.Collection(result,
204207
i => Assert.Equal(1, i),
205208
i => Assert.Equal(2, i));

src/Middleware/Diagnostics.EntityFrameworkCore/test/UnitTests/DatabaseErrorPageTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public async Task MigrationsEndPointPath_is_respected()
207207

208208
var content = await ExecutePage(options, model);
209209

210+
Assert.NotNull(options.MigrationsEndPointPath.Value); // guard
210211
Assert.Contains(options.MigrationsEndPointPath.Value, content);
211212
}
212213

src/Middleware/Rewrite/test/ApacheModRewrite/ModRewriteMiddlewareTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public async Task Invoke_EnsureHttps(string input)
349349

350350
var response = await server.CreateClient().GetAsync(input);
351351

352-
Assert.Equal(response.StatusCode, (HttpStatusCode)301);
352+
Assert.Equal((HttpStatusCode)301, response.StatusCode);
353353
Assert.Equal(@"https://www.example.com/foo/", response.Headers.Location.AbsoluteUri);
354354
}
355355

src/Middleware/StaticFiles/test/UnitTests/RangeHelperTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void NormalizeRange_ReturnsNullWhenRangeEndEqualsZero()
3232
}
3333

3434
[Theory]
35-
[InlineData(0, null, 0, 2)]
36-
[InlineData(0, 0, 0, 0)]
35+
[InlineData(0L, null, 0L, 2L)]
36+
[InlineData(0L, 0L, 0L, 0L)]
3737
public void NormalizeRange_ReturnsNormalizedRange(long? start, long? end, long? normalizedStart, long? normalizedEnd)
3838
{
3939
// Arrange & Act

src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,9 @@ public void ProducesRouteInfoOnlyForRouteParameters()
11371137
{
11381138
Assert.Equal("name", parameter.Name);
11391139
Assert.NotNull(parameter.RouteInfo);
1140-
Assert.Empty(parameter.RouteInfo!.Constraints);
1141-
Assert.True(parameter.RouteInfo!.IsOptional);
1140+
Assert.NotNull(parameter.RouteInfo.Constraints);
1141+
Assert.Empty(parameter.RouteInfo.Constraints);
1142+
Assert.True(parameter.RouteInfo.IsOptional);
11421143
Assert.Equal("default", parameter.RouteInfo!.DefaultValue);
11431144
});
11441145
}
@@ -1164,7 +1165,8 @@ public void HandlesEndpointWithRouteConstraints()
11641165
var apiDescription = Assert.Single(context.Results);
11651166
var parameter = Assert.Single(apiDescription.ParameterDescriptions);
11661167
Assert.NotNull(parameter.RouteInfo);
1167-
Assert.Collection(parameter.RouteInfo!.Constraints,
1168+
Assert.NotNull(parameter.RouteInfo.Constraints);
1169+
Assert.Collection(parameter.RouteInfo.Constraints,
11681170
constraint => Assert.IsType<MinLengthRouteConstraint>(constraint),
11691171
constraint => Assert.IsType<GuidRouteConstraint>(constraint),
11701172
constraint => Assert.IsType<MaxLengthRouteConstraint>(constraint));

src/Servers/Kestrel/Core/test/HttpParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public void ParseRequestLineTlsOverHttp()
574574
ParseRequestLine(parser, requestHandler, buffer, out var consumed, out var examined);
575575
});
576576

577-
Assert.Equal(badHttpRequestException.StatusCode, StatusCodes.Status400BadRequest);
577+
Assert.Equal(StatusCodes.Status400BadRequest, badHttpRequestException.StatusCode);
578578
Assert.Equal(RequestRejectionReason.TlsOverHttpError, badHttpRequestException.Reason);
579579
}
580580

src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,21 @@ public async Task StopAcceptingReadsCausesCopyToAsyncToThrowObjectDisposedExcept
197197
}
198198

199199
[Fact]
200-
public void NullDestinationCausesCopyToAsyncToThrowArgumentNullException()
200+
public async Task NullDestinationCausesCopyToAsyncToThrowArgumentNullException()
201201
{
202202
var pipeReader = new HttpRequestPipeReader();
203203
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>(), pipeReader);
204204
pipeReader.StartAcceptingReads(null);
205-
Assert.Throws<ArgumentNullException>(() => { stream.CopyToAsync(null); });
205+
await Assert.ThrowsAsync<ArgumentNullException>(async () => { await stream.CopyToAsync(null); });
206206
}
207207

208208
[Fact]
209-
public void ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException()
209+
public async Task ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException()
210210
{
211211
var pipeReader = new HttpRequestPipeReader();
212212
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>(), new HttpRequestPipeReader());
213213
pipeReader.StartAcceptingReads(null);
214214
// This is technically a breaking change, to throw an ArgumentoutOfRangeException rather than an ArgumentException
215-
Assert.Throws<ArgumentOutOfRangeException>(() => { stream.CopyToAsync(Mock.Of<Stream>(), 0); });
215+
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => { await stream.CopyToAsync(Mock.Of<Stream>(), 0); });
216216
}
217217
}

src/Servers/Kestrel/Core/test/HttpResponseStreamTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public void PositionThrows()
9494
}
9595

9696
[Fact]
97-
public void StopAcceptingWritesCausesWriteToThrowObjectDisposedException()
97+
public async Task StopAcceptingWritesCausesWriteToThrowObjectDisposedException()
9898
{
9999
var pipeWriter = new HttpResponsePipeWriter(Mock.Of<IHttpResponseControl>());
100100
var stream = new HttpResponseStream(Mock.Of<IHttpBodyControlFeature>(), pipeWriter);
101101
pipeWriter.StartAcceptingWrites();
102-
pipeWriter.StopAcceptingWritesAsync();
103-
var ex = Assert.Throws<ObjectDisposedException>(() => { stream.WriteAsync(new byte[1], 0, 1); });
102+
await pipeWriter.StopAcceptingWritesAsync();
103+
var ex = await Assert.ThrowsAsync<ObjectDisposedException>(async () => { await stream.WriteAsync(new byte[1], 0, 1); });
104104
Assert.Contains(CoreStrings.WritingToResponseBodyAfterResponseCompleted, ex.Message);
105105
}
106106

src/Servers/Kestrel/Core/test/KestrelServerLimitsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void MaxConnectionsDefault()
214214

215215
[Theory]
216216
[InlineData(null)]
217-
[InlineData(1u)]
217+
[InlineData(1L)]
218218
[InlineData(long.MaxValue)]
219219
public void MaxConnectionsValid(long? value)
220220
{
@@ -238,8 +238,8 @@ public void MaxConnectionsInvalid(long value)
238238

239239
[Theory]
240240
[InlineData(null)]
241-
[InlineData(0)]
242-
[InlineData(1)]
241+
[InlineData(0L)]
242+
[InlineData(1L)]
243243
[InlineData(long.MaxValue)]
244244
public void MaxUpgradedConnectionsValid(long? value)
245245
{
@@ -269,8 +269,8 @@ public void MaxRequestBodySizeDefault()
269269

270270
[Theory]
271271
[InlineData(null)]
272-
[InlineData(0)]
273-
[InlineData(1)]
272+
[InlineData(0L)]
273+
[InlineData(1L)]
274274
[InlineData(long.MaxValue)]
275275
public void MaxRequestBodySizeValid(long? value)
276276
{

0 commit comments

Comments
 (0)