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:
parent
3dfa26f7e3
commit
1128bd572c
|
|
@ -1265,6 +1265,19 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
Assert.Equal(actionName, result.Action);
|
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)
|
protected static LinkBuilder LinkFrom(string url)
|
||||||
{
|
{
|
||||||
return new LinkBuilder(url);
|
return new LinkBuilder(url);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// 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.Builder;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -47,6 +48,11 @@ namespace RoutingWebSite
|
||||||
"RouteWithOptionalSegment",
|
"RouteWithOptionalSegment",
|
||||||
"{controller}/{action}/{path?}");
|
"{controller}/{action}/{path?}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.Map("/afterrouting", b => b.Run(c =>
|
||||||
|
{
|
||||||
|
return c.Response.WriteAsync("Hello from middleware after routing");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// 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.Builder;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -47,6 +48,11 @@ namespace RoutingWebSite
|
||||||
"RouteWithOptionalSegment",
|
"RouteWithOptionalSegment",
|
||||||
"{controller}/{action}/{path?}");
|
"{controller}/{action}/{path?}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.Map("/afterrouting", b => b.Run(c =>
|
||||||
|
{
|
||||||
|
return c.Response.WriteAsync("Hello from middleware after routing");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue