Add a functional test for middleware after routing

It came up during routing discussions that we don't have any tests for
this scenario.
This commit is contained in:
Ryan Nowak 2018-08-30 13:08:07 -07:00
parent 3dfa26f7e3
commit 1128bd572c
3 changed files with 25 additions and 0 deletions

View File

@ -1265,6 +1265,19 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(actionName, result.Action);
}
[Fact]
public async Task CanRunMiddlewareAfterRouting()
{
// Act
var response = await Client.GetAsync("/afterrouting");
// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.OK);
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("Hello from middleware after routing", content);
}
protected static LinkBuilder LinkFrom(string url)
{
return new LinkBuilder(url);

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
@ -47,6 +48,11 @@ namespace RoutingWebSite
"RouteWithOptionalSegment",
"{controller}/{action}/{path?}");
});
app.Map("/afterrouting", b => b.Run(c =>
{
return c.Response.WriteAsync("Hello from middleware after routing");
}));
}
}
}

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
@ -47,6 +48,11 @@ namespace RoutingWebSite
"RouteWithOptionalSegment",
"{controller}/{action}/{path?}");
});
app.Map("/afterrouting", b => b.Run(c =>
{
return c.Response.WriteAsync("Hello from middleware after routing");
}));
}
}
}