Unit test route name with RouteUrl and ambient values (#6719)

This commit is contained in:
James Newton-King 2019-01-16 13:57:13 +13:00 коммит произвёл GitHub
Родитель 17616a5dba
Коммит df7bfe5243
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 78 добавлений и 0 удалений

Просмотреть файл

@ -26,6 +26,28 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
public HttpClient Client { get; }
[Theory]
[InlineData("http://localhost/Login/Index", "Login", "Index", "http://localhost/Login")]
[InlineData("http://localhost/Login/Sso", "Login", "Sso", "http://localhost/Login/Sso")]
[InlineData("http://localhost/Contact/Index", "Contact", "Index", "http://localhost/Contact")]
[InlineData("http://localhost/Contact/Sso", "Contact", "Sso", "http://localhost/Contact/Sso")]
public async Task ConventionalRoutedAction_RouteUrl_AmbientValues(string requestUrl, string controller, string action, string expectedUrl)
{
// Arrange & Act
var response = await Client.GetAsync(requestUrl);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<RoutingResult>(body);
Assert.Equal(controller, result.Controller);
Assert.Equal(action, result.Action);
Assert.Equal(expectedUrl, Assert.Single(result.ExpectedUrls));
}
[Fact]
public async Task ConventionalRoutedAction_RouteContainsPage_RouteNotMatched()
{

Просмотреть файл

@ -0,0 +1,28 @@
// 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 Microsoft.AspNetCore.Mvc;
namespace RoutingWebSite
{
// This controller is reachable via traditional routing.
public class ContactController : Controller
{
private readonly TestResponseGenerator _generator;
public ContactController(TestResponseGenerator generator)
{
_generator = generator;
}
public IActionResult Index()
{
return _generator.Generate(Url.RouteUrl("ActionAsMethod", null, Url.ActionContext.HttpContext.Request.Scheme));
}
public IActionResult Sso()
{
return _generator.Generate(Url.RouteUrl("ActionAsMethod", null, Url.ActionContext.HttpContext.Request.Scheme));
}
}
}

Просмотреть файл

@ -0,0 +1,28 @@
// 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 Microsoft.AspNetCore.Mvc;
namespace RoutingWebSite
{
// This controller is reachable via traditional routing.
public class LoginController : Controller
{
private readonly TestResponseGenerator _generator;
public LoginController(TestResponseGenerator generator)
{
_generator = generator;
}
public IActionResult Index()
{
return _generator.Generate(Url.RouteUrl("ActionAsMethod", null, Url.ActionContext.HttpContext.Request.Scheme));
}
public IActionResult Sso()
{
return _generator.Generate(Url.RouteUrl("ActionAsMethod", null, Url.ActionContext.HttpContext.Request.Scheme));
}
}
}