Test basic link generation in Razor pages in both regular and endpoint routing

This commit is contained in:
Ajay Bhargav Baaskaran 2018-08-29 15:50:53 -07:00
parent f9c309dd71
commit 4d98ea801e
3 changed files with 29 additions and 0 deletions

View File

@ -1241,6 +1241,24 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(actionName, result.Action);
}
[Fact]
public async Task RazorPage_WithLinks_GeneratesLinksCorrectly()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/PageWithLinks");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var document = await response.GetHtmlDocumentAsync();
var editLink = document.RequiredQuerySelector("#editlink");
Assert.Equal("/Edit/10", editLink.GetAttribute("href"));
var contactLink = document.RequiredQuerySelector("#contactlink");
Assert.Equal("/Home/Contact", contactLink.GetAttribute("href"));
}
protected static LinkBuilder LinkFrom(string url)
{
return new LinkBuilder(url);

View File

@ -0,0 +1,3 @@
@page "{id}"
Hello from Edit page

View File

@ -0,0 +1,8 @@
@page
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
@{
}
<a id="editlink" asp-page="/Edit" asp-route-id="10">Edit</a>
<br />
<a id="contactlink" asp-action="Contact" asp-controller="Home">Contact</a>