Add routing function test with convention builder (#6829)
This commit is contained in:
parent
adcc2bf23c
commit
820ea09fdd
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
|
@ -210,6 +210,19 @@ namespace Microsoft.AspNetCore.Routing.FunctionalTests
|
|||
Assert.Equal("Link: /WithDoubleAsteriskCatchAll/a/b%20b1/c%20c1", actualContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MapGet_HasConventionMetadata()
|
||||
{
|
||||
// Arrange & Act
|
||||
var response = await _client.GetAsync("/convention");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var actualContent = await response.Content.ReadAsStringAsync();
|
||||
Assert.Equal("Has metadata", actualContent);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_testServer.Dispose();
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ namespace RoutingWebSite
|
|||
response.ContentLength = payloadLength;
|
||||
return response.Body.WriteAsync(_plainTextPayload, 0, payloadLength);
|
||||
});
|
||||
routes.MapGet(
|
||||
"/convention",
|
||||
(httpContext) =>
|
||||
{
|
||||
var endpoint = httpContext.GetEndpoint();
|
||||
return httpContext.Response.WriteAsync((endpoint.Metadata.GetMetadata<CustomMetadata>() != null) ? "Has metadata" : "No metadata");
|
||||
}).Add(b =>
|
||||
{
|
||||
b.Metadata.Add(new CustomMetadata());
|
||||
});
|
||||
routes.MapGet(
|
||||
"/withconstraints/{id:endsWith(_001)}",
|
||||
(httpContext) =>
|
||||
|
|
@ -131,6 +141,10 @@ namespace RoutingWebSite
|
|||
app.UseEndpoint();
|
||||
}
|
||||
|
||||
private class CustomMetadata
|
||||
{
|
||||
}
|
||||
|
||||
private IEndpointConventionBuilder MapHostEndpoint(IEndpointRouteBuilder routes, params string[] hosts)
|
||||
{
|
||||
var hostsDisplay = (hosts == null || hosts.Length == 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue