From 35f7d3f09c870165dd8b50c6f81a5e0330a6ad75 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Fri, 27 Apr 2018 12:12:58 -0700 Subject: [PATCH] Added tests to verify that RazorPages and FuzzyMatching with Head requests work --- .../RazorPagesTest.cs | 38 +++++++++++++++++-- .../PageModelWithPropertyBinding.cs | 4 ++ .../PageModelWithPropertyBinding.cshtml | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs index d50c1ef6cc..524f8bd977 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs @@ -684,8 +684,8 @@ Hello from /Pages/WithViewStart/Index.cshtml!"; public async Task PropertiesOnPageModelAreBound() { // Arrange - var expected = "Id = 10, Name = Foo, Age = 25"; - var request = new HttpRequestMessage(HttpMethod.Post, "Pages/PropertyBinding/PageModelWithPropertyBinding/10") + var expected = "Id = 10, Name = Foo, Age = 25, PropertyWithSupportGetsTrue = foo"; + var request = new HttpRequestMessage(HttpMethod.Post, "Pages/PropertyBinding/PageModelWithPropertyBinding/10?PropertyWithSupportGetsTrue=foo") { Content = new FormUrlEncodedContent(new KeyValuePair[] { @@ -711,7 +711,7 @@ Hello from /Pages/WithViewStart/Index.cshtml!"; var url = "Pages/PropertyBinding/PageModelWithPropertyBinding/27"; var expected = new[] { - "Id = 27, Name = , Age = 325", + "Id = 27, Name = , Age = 325, PropertyWithSupportGetsTrue =", "The Name field is required.", "The field Age must be between 0 and 99.", }; @@ -787,6 +787,38 @@ Hello from /Pages/WithViewStart/Index.cshtml!"; Assert.DoesNotContain(validationError, content); } + [Fact] + public async Task PageProperty_WithSupportsGetTrue_OnPageWithHandler_FuzzyMatchesHeadRequest() + { + // Arrange + var request = new HttpRequestMessage(HttpMethod.Head, "Pages/PropertyBinding/PageModelWithPropertyBinding/10?PropertyWithSupportGetsTrue=foo"); + + // Act + var response = await Client.SendAsync(request); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.NotNull(response.Content.Headers.ContentType); + Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType); + } + + [Fact] + public async Task PageProperty_WithSupportsGetTrue_OnPageWithNoHandler_FuzzyMatchesHeadRequest() + { + // Arrange + var request = new HttpRequestMessage(HttpMethod.Head, "Pages/PropertyBinding/BindPropertyWithGet?value=11"); + + // Act + var response = await Client.SendAsync(request); + + // Assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.NotNull(response.Content.Headers.ContentType); + Assert.Equal("text/html", response.Content.Headers.ContentType.MediaType); + } + [Fact] public async Task PageProperty_WithSupportsGet_BoundInGet() { diff --git a/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cs b/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cs index 1d436d9e79..2e7332b3ee 100644 --- a/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cs +++ b/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cs @@ -14,6 +14,10 @@ namespace RazorPagesWebSite [FromRoute] public int Id { get; set; } + [BindProperty(SupportsGet = true)] + [FromQuery] + public string PropertyWithSupportGetsTrue { get; set; } + public void OnGet() { } } } diff --git a/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cshtml b/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cshtml index a7157b59e7..bc9fef8674 100644 --- a/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cshtml +++ b/test/WebSites/RazorPagesWebSite/Pages/PropertyBinding/PageModelWithPropertyBinding.cshtml @@ -1,6 +1,6 @@ @page "{id:int}" @model PageModelWithPropertyBinding -Id = @Model.Id, Name = @Model.UserModel?.Name, Age = @Model.UserModel?.Age +Id = @Model.Id, Name = @Model.UserModel?.Name, Age = @Model.UserModel?.Age, PropertyWithSupportGetsTrue = @Model.PropertyWithSupportGetsTrue @Html.ValidationSummary()