Skip to content

Commit 6fbdbc6

Browse files
committed
More test coverage
1 parent ea59c39 commit 6fbdbc6

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs

+5-15
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,8 @@ public static bool TryParse(string? value, out MyTryParsableRecord? result)
361361
[MemberData(nameof(TryParsableParameters))]
362362
public async Task RequestDelegatePopulatesUnattributedTryParsableParametersFromRouteValue(Delegate action, string? routeValue, object? expectedParameterValue)
363363
{
364-
var invalidDataException = new InvalidDataException();
365-
var serviceCollection = new ServiceCollection();
366-
serviceCollection.AddSingleton(LoggerFactory);
367-
368364
var httpContext = new DefaultHttpContext();
369365
httpContext.Request.RouteValues["tryParsable"] = routeValue;
370-
httpContext.Features.Set<IHttpRequestLifetimeFeature>(new TestHttpRequestLifetimeFeature());
371-
httpContext.RequestServices = serviceCollection.BuildServiceProvider();
372366

373367
var requestDelegate = RequestDelegateFactory.Create(action);
374368

@@ -460,7 +454,6 @@ void TestAction([FromRoute] int tryParsable, [FromRoute] int tryParsable2)
460454
invoked = true;
461455
}
462456

463-
var invalidDataException = new InvalidDataException();
464457
var serviceCollection = new ServiceCollection();
465458
serviceCollection.AddSingleton(LoggerFactory);
466459

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

591-
[Fact]
592-
public async Task RequestDelegateRejectsEmptyBodyGivenDefaultFromBodyParameter()
584+
[Theory]
585+
[MemberData(nameof(FromBodyActions))]
586+
public async Task RequestDelegateRejectsEmptyBodyGivenFromBodyParameter(Delegate action)
593587
{
594-
void TestAction(Todo todo)
595-
{
596-
}
597-
598588
var httpContext = new DefaultHttpContext();
599589
httpContext.Request.Headers["Content-Type"] = "application/json";
600590
httpContext.Request.Headers["Content-Length"] = "0";
601591

602-
var requestDelegate = RequestDelegateFactory.Create((Action<Todo>)TestAction);
592+
var requestDelegate = RequestDelegateFactory.Create(action);
603593

604594
await Assert.ThrowsAsync<JsonException>(() => requestDelegate(httpContext));
605595
}
@@ -775,7 +765,7 @@ public async Task RequestDelegatePopulatesParametersFromServiceWithAndWithoutAtt
775765
public async Task RequestDelegateRequiresServiceForAllFromServiceParameters(Delegate action)
776766
{
777767
var httpContext = new DefaultHttpContext();
778-
httpContext.RequestServices = (new ServiceCollection()).BuildServiceProvider();
768+
httpContext.RequestServices = new ServiceCollection().BuildServiceProvider();
779769

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

0 commit comments

Comments
 (0)