Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
halter73 committed Apr 10, 2021
1 parent ea59c39 commit 6fbdbc6
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,8 @@ public static bool TryParse(string? value, out MyTryParsableRecord? result)
[MemberData(nameof(TryParsableParameters))]
public async Task RequestDelegatePopulatesUnattributedTryParsableParametersFromRouteValue(Delegate action, string? routeValue, object? expectedParameterValue)
{
var invalidDataException = new InvalidDataException();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(LoggerFactory);

var httpContext = new DefaultHttpContext();
httpContext.Request.RouteValues["tryParsable"] = routeValue;
httpContext.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
httpContext.RequestServices = serviceCollection.BuildServiceProvider();

var requestDelegate = RequestDelegateFactory.Create(action);

Expand Down Expand Up @@ -460,7 +454,6 @@ void TestAction([FromRoute] int tryParsable, [FromRoute] int tryParsable2)
invoked = true;
}

var invalidDataException = new InvalidDataException();
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(LoggerFactory);

Expand Down Expand Up @@ -588,18 +581,15 @@ public async Task RequestDelegatePopulatesFromBodyParameter(Delegate action)
Assert.Equal(originalTodo.Name, ((Todo)deserializedRequestBody!).Name);
}

[Fact]
public async Task RequestDelegateRejectsEmptyBodyGivenDefaultFromBodyParameter()
[Theory]
[MemberData(nameof(FromBodyActions))]
public async Task RequestDelegateRejectsEmptyBodyGivenFromBodyParameter(Delegate action)
{
void TestAction(Todo todo)
{
}

var httpContext = new DefaultHttpContext();
httpContext.Request.Headers["Content-Type"] = "application/json";
httpContext.Request.Headers["Content-Length"] = "0";

var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction);
var requestDelegate = RequestDelegateFactory.Create(action);

await Assert.ThrowsAsync<JsonException>(() => requestDelegate(httpContext));
}
Expand Down Expand Up @@ -775,7 +765,7 @@ public async Task RequestDelegatePopulatesParametersFromServiceWithAndWithoutAtt
public async Task RequestDelegateRequiresServiceForAllFromServiceParameters(Delegate action)
{
var httpContext = new DefaultHttpContext();
httpContext.RequestServices = (new ServiceCollection()).BuildServiceProvider();
httpContext.RequestServices = new ServiceCollection().BuildServiceProvider();

var requestDelegate = RequestDelegateFactory.Create((Action<HttpContext, MyService>)action);

Expand Down

0 comments on commit 6fbdbc6

Please sign in to comment.