Skip to content

Move to newer xUnit packages #43598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@
<SystemReactiveLinqVersion>5.0.0</SystemReactiveLinqVersion>
<SwashbuckleAspNetCoreVersion>6.4.0</SwashbuckleAspNetCoreVersion>
<XunitAbstractionsVersion>2.0.3</XunitAbstractionsVersion>
<XunitAnalyzersVersion>0.10.0</XunitAnalyzersVersion>
<XunitVersion>2.4.1</XunitVersion>
<XunitAnalyzersVersion>1.0.0</XunitAnalyzersVersion>
<XunitVersion>2.4.2</XunitVersion>
<XunitAssertVersion>$(XunitVersion)</XunitAssertVersion>
<XunitExtensibilityCoreVersion>$(XunitVersion)</XunitExtensibilityCoreVersion>
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public async Task ReadFromJsonAsyncGeneric_WithOptions_ReturnValue()
var result = await context.Request.ReadFromJsonAsync<List<int>>(options);

// Assert
Assert.NotNull(result);
Assert.Collection(result,
i => Assert.Equal(1, i),
i => Assert.Equal(2, i));
Expand All @@ -87,6 +88,7 @@ public async Task ReadFromJsonAsyncGeneric_Utf8Encoding_ReturnValue()
var result = await context.Request.ReadFromJsonAsync<List<int>>();

// Assert
Assert.NotNull(result);
Assert.Collection(result,
i => Assert.Equal(1, i),
i => Assert.Equal(2, i));
Expand Down Expand Up @@ -200,6 +202,7 @@ public async Task ReadFromJsonAsync_WithOptions_ReturnValue()
var result = (List<int>?)await context.Request.ReadFromJsonAsync(typeof(List<int>), options);

// Assert
Assert.NotNull(result);
Assert.Collection(result,
i => Assert.Equal(1, i),
i => Assert.Equal(2, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public async Task MigrationsEndPointPath_is_respected()

var content = await ExecutePage(options, model);

Assert.NotNull(options.MigrationsEndPointPath.Value); // guard
Assert.Contains(options.MigrationsEndPointPath.Value, content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public async Task Invoke_EnsureHttps(string input)

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/StaticFiles/test/UnitTests/RangeHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void NormalizeRange_ReturnsNullWhenRangeEndEqualsZero()
}

[Theory]
[InlineData(0, null, 0, 2)]
[InlineData(0, 0, 0, 0)]
[InlineData(0L, null, 0L, 2L)]
[InlineData(0L, 0L, 0L, 0L)]
public void NormalizeRange_ReturnsNormalizedRange(long? start, long? end, long? normalizedStart, long? normalizedEnd)
{
// Arrange & Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,9 @@ public void ProducesRouteInfoOnlyForRouteParameters()
{
Assert.Equal("name", parameter.Name);
Assert.NotNull(parameter.RouteInfo);
Assert.Empty(parameter.RouteInfo!.Constraints);
Assert.True(parameter.RouteInfo!.IsOptional);
Assert.NotNull(parameter.RouteInfo.Constraints);
Assert.Empty(parameter.RouteInfo.Constraints);
Assert.True(parameter.RouteInfo.IsOptional);
Assert.Equal("default", parameter.RouteInfo!.DefaultValue);
});
}
Expand All @@ -1164,7 +1165,8 @@ public void HandlesEndpointWithRouteConstraints()
var apiDescription = Assert.Single(context.Results);
var parameter = Assert.Single(apiDescription.ParameterDescriptions);
Assert.NotNull(parameter.RouteInfo);
Assert.Collection(parameter.RouteInfo!.Constraints,
Assert.NotNull(parameter.RouteInfo.Constraints);
Assert.Collection(parameter.RouteInfo.Constraints,
constraint => Assert.IsType<MinLengthRouteConstraint>(constraint),
constraint => Assert.IsType<GuidRouteConstraint>(constraint),
constraint => Assert.IsType<MaxLengthRouteConstraint>(constraint));
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/test/HttpParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public void ParseRequestLineTlsOverHttp()
ParseRequestLine(parser, requestHandler, buffer, out var consumed, out var examined);
});

Assert.Equal(badHttpRequestException.StatusCode, StatusCodes.Status400BadRequest);
Assert.Equal(StatusCodes.Status400BadRequest, badHttpRequestException.StatusCode);
Assert.Equal(RequestRejectionReason.TlsOverHttpError, badHttpRequestException.Reason);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,21 @@ public async Task StopAcceptingReadsCausesCopyToAsyncToThrowObjectDisposedExcept
}

[Fact]
public void NullDestinationCausesCopyToAsyncToThrowArgumentNullException()
public async Task NullDestinationCausesCopyToAsyncToThrowArgumentNullException()
{
var pipeReader = new HttpRequestPipeReader();
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>(), pipeReader);
pipeReader.StartAcceptingReads(null);
Assert.Throws<ArgumentNullException>(() => { stream.CopyToAsync(null); });
await Assert.ThrowsAsync<ArgumentNullException>(async () => { await stream.CopyToAsync(null); });
}

[Fact]
public void ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException()
public async Task ZeroBufferSizeCausesCopyToAsyncToThrowArgumentException()
{
var pipeReader = new HttpRequestPipeReader();
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>(), new HttpRequestPipeReader());
pipeReader.StartAcceptingReads(null);
// This is technically a breaking change, to throw an ArgumentoutOfRangeException rather than an ArgumentException
Assert.Throws<ArgumentOutOfRangeException>(() => { stream.CopyToAsync(Mock.Of<Stream>(), 0); });
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => { await stream.CopyToAsync(Mock.Of<Stream>(), 0); });
}
}
6 changes: 3 additions & 3 deletions src/Servers/Kestrel/Core/test/HttpResponseStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public void PositionThrows()
}

[Fact]
public void StopAcceptingWritesCausesWriteToThrowObjectDisposedException()
public async Task StopAcceptingWritesCausesWriteToThrowObjectDisposedException()
{
var pipeWriter = new HttpResponsePipeWriter(Mock.Of<IHttpResponseControl>());
var stream = new HttpResponseStream(Mock.Of<IHttpBodyControlFeature>(), pipeWriter);
pipeWriter.StartAcceptingWrites();
pipeWriter.StopAcceptingWritesAsync();
var ex = Assert.Throws<ObjectDisposedException>(() => { stream.WriteAsync(new byte[1], 0, 1); });
await pipeWriter.StopAcceptingWritesAsync();
var ex = await Assert.ThrowsAsync<ObjectDisposedException>(async () => { await stream.WriteAsync(new byte[1], 0, 1); });
Assert.Contains(CoreStrings.WritingToResponseBodyAfterResponseCompleted, ex.Message);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Servers/Kestrel/Core/test/KestrelServerLimitsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void MaxConnectionsDefault()

[Theory]
[InlineData(null)]
[InlineData(1u)]
[InlineData(1L)]
[InlineData(long.MaxValue)]
public void MaxConnectionsValid(long? value)
{
Expand All @@ -238,8 +238,8 @@ public void MaxConnectionsInvalid(long value)

[Theory]
[InlineData(null)]
[InlineData(0)]
[InlineData(1)]
[InlineData(0L)]
[InlineData(1L)]
[InlineData(long.MaxValue)]
public void MaxUpgradedConnectionsValid(long? value)
{
Expand Down Expand Up @@ -269,8 +269,8 @@ public void MaxRequestBodySizeDefault()

[Theory]
[InlineData(null)]
[InlineData(0)]
[InlineData(1)]
[InlineData(0L)]
[InlineData(1L)]
[InlineData(long.MaxValue)]
public void MaxRequestBodySizeValid(long? value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task TestUnixDomainSocketWithUrl()
Assert.False(httpStatusEnd == -1, $"Second space not found in '{httpResponse}'.");

var httpStatus = int.Parse(httpResponse.Substring(httpStatusStart, httpStatusEnd - httpStatusStart), CultureInfo.InvariantCulture);
Assert.Equal(httpStatus, StatusCodes.Status200OK);
Assert.Equal(StatusCodes.Status200OK, httpStatus);

}
await host.StopAsync().DefaultTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task DoesNotRejectRequestWithContentLengthHeaderExceedingGlobalLimi
var buffer = new byte[1];

Assert.Equal(1, await context.Request.Body.ReadAsync(buffer, 0, 1));
Assert.Equal(buffer[0], (byte)'A');
Assert.Equal((byte)'A', buffer[0]);
Assert.Equal(0, await context.Request.Body.ReadAsync(buffer, 0, 1));

context.Response.ContentLength = 1;
Expand Down
8 changes: 4 additions & 4 deletions src/Shared/ResultsTests/FileContentResultTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public async Task WriteFileAsync_CopiesBuffer_ToOutputStream()
}

[Theory]
[InlineData(0, 4, "Hello", 5)]
[InlineData(6, 10, "World", 5)]
[InlineData(null, 5, "World", 5)]
[InlineData(6, null, "World", 5)]
[InlineData(0L, 4L, "Hello", 5L)]
[InlineData(6L, 10L, "World", 5L)]
[InlineData(null, 5L, "World", 5L)]
[InlineData(6L, null, "World", 5L)]
public async Task WriteFileAsync_PreconditionStateShouldProcess_WritesRangeRequested(
long? start,
long? end,
Expand Down
10 changes: 5 additions & 5 deletions src/Shared/ResultsTests/FileStreamResultTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ protected abstract Task ExecuteAsync(
bool enableRangeProcessing = false);

[Theory]
[InlineData(0, 4, "Hello", 5)]
[InlineData(6, 10, "World", 5)]
[InlineData(null, 5, "World", 5)]
[InlineData(6, null, "World", 5)]
[InlineData(0L, 4L, "Hello", 5L)]
[InlineData(6L, 10L, "World", 5L)]
[InlineData(null, 5L, "World", 5L)]
[InlineData(6L, null, "World", 5L)]
public async Task WriteFileAsync_PreconditionStateShouldProcess_WritesRangeRequested(long? start, long? end, string expectedString, long contentLength)
{
// Arrange
Expand Down Expand Up @@ -326,7 +326,7 @@ public async Task WriteFileAsync_NotModified_RangeRequestedIgnored()
}

[Theory]
[InlineData(0)]
[InlineData(0L)]
[InlineData(null)]
public async Task WriteFileAsync_RangeRequested_FileLengthZeroOrNull(long? fileLength)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Shared/ResultsTests/PhysicalFileResultTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ protected abstract Task ExecuteAsync(
bool enableRangeProcessing = false);

[Theory]
[InlineData(0, 3, 4)]
[InlineData(8, 13, 6)]
[InlineData(null, 5, 5)]
[InlineData(8, null, 26)]
[InlineData(0L, 3L, 4L)]
[InlineData(8L, 13L, 6L)]
[InlineData(null, 5L, 5L)]
[InlineData(8L, null, 26L)]
public async Task WriteFileAsync_WritesRangeRequested(long? start, long? end, long contentLength)
{
// Arrange
Expand Down Expand Up @@ -284,10 +284,10 @@ public async Task ExecuteResultAsync_CallsSendFileAsync_IfIHttpSendFilePresent()
}

[Theory]
[InlineData(0, 3, 4)]
[InlineData(8, 13, 6)]
[InlineData(null, 3, 3)]
[InlineData(8, null, 26)]
[InlineData(0L, 3L, 4L)]
[InlineData(8L, 13L, 6L)]
[InlineData(null, 3L, 3L)]
[InlineData(8L, null, 26L)]
public async Task ExecuteResultAsync_CallsSendFileAsyncWithRequestedRange_IfIHttpSendFilePresent(long? start, long? end, long contentLength)
{
// Arrange
Expand Down
16 changes: 8 additions & 8 deletions src/Shared/ResultsTests/VirtualFileResultTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ protected abstract Task ExecuteAsync(
bool enableRangeProcessing = false);

[Theory]
[InlineData(0, 3, 4)]
[InlineData(8, 13, 6)]
[InlineData(null, 4, 4)]
[InlineData(8, null, 25)]
[InlineData(0L, 3L, 4L)]
[InlineData(8L, 13L, 6L)]
[InlineData(null, 4L, 4L)]
[InlineData(8L, null, 25L)]
public async Task WriteFileAsync_WritesRangeRequested(
long? start,
long? end,
Expand Down Expand Up @@ -314,10 +314,10 @@ public async Task WriteFileAsync_RangeRequested_NotModified()
}

[Theory]
[InlineData(0, 3, 4)]
[InlineData(8, 13, 6)]
[InlineData(null, 3, 3)]
[InlineData(8, null, 25)]
[InlineData(0L, 3L, 4L)]
[InlineData(8L, 13L, 6L)]
[InlineData(null, 3L, 3L)]
[InlineData(8L, null, 25L)]
public async Task ExecuteResultAsync_CallsSendFileAsyncWithRequestedRange_IfIHttpSendFilePresent(long? start, long? end, long contentLength)
{
// Arrange
Expand Down