public async Task BuildImplicitlyThrowsForMatchedEndpointAsLastStep() { var builder = new ApplicationBuilder(null); var app = builder.Build(); var endpointCalled = false; var endpoint = new Endpoint( context => { endpointCalled = true; return(Task.CompletedTask); }, EndpointMetadataCollection.Empty, "Test endpoint"); var httpContext = new DefaultHttpContext(); httpContext.SetEndpoint(endpoint); var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => app.Invoke(httpContext)); var expected = "The request reached the end of the pipeline without executing the endpoint: 'Test endpoint'. " + "Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if " + "using routing."; Assert.Equal(expected, ex.Message); Assert.False(endpointCalled); }
public void BuildDoesNotCallMatchedEndpointWhenTerminated() { var builder = new ApplicationBuilder(null); builder.Use((context, next) => { // Do not call next return(Task.CompletedTask); }); var app = builder.Build(); var endpointCalled = false; var endpoint = new Endpoint( context => { endpointCalled = true; return(Task.CompletedTask); }, EndpointMetadataCollection.Empty, "Test endpoint"); var httpContext = new DefaultHttpContext(); httpContext.SetEndpoint(endpoint); app.Invoke(httpContext); Assert.False(endpointCalled); }
public void BuildReturnsCallableDelegate() { var builder = new ApplicationBuilder(null); var app = builder.Build(); var httpContext = new DefaultHttpContext(); app.Invoke(httpContext); Assert.Equal(httpContext.Response.StatusCode, 404); }
public void BuildImplicitlyCallsMatchedEndpointAsLastStep() { var builder = new ApplicationBuilder(null); var app = builder.Build(); var endpointCalled = false; var endpoint = new Endpoint( context => { endpointCalled = true; return(Task.CompletedTask); }, EndpointMetadataCollection.Empty, "Test endpoint"); var httpContext = new DefaultHttpContext(); httpContext.SetEndpoint(endpoint); app.Invoke(httpContext); Assert.True(endpointCalled); }