This repository was archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add integration and functional tests of [BindRequired] on page properties
#8677
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| using System.Collections.Generic; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -420,14 +419,16 @@ public async Task PageConventions_CustomizedModelCanPostToHandlers() | |
| var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(await getPage.Content.ReadAsStringAsync(), ""); | ||
| var cookie = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getPage); | ||
|
|
||
| var message = new HttpRequestMessage(HttpMethod.Post, "/CustomModelTypeModel"); | ||
| message.Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
| var message = new HttpRequestMessage(HttpMethod.Post, "/CustomModelTypeModel") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other tests using |
||
| { | ||
| ["__RequestVerificationToken"] = token, | ||
| ["ConfirmPassword"] = "", | ||
| ["Password"] = "", | ||
| ["Email"] = "" | ||
| }); | ||
| Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
| { | ||
| ["__RequestVerificationToken"] = token, | ||
| ["ConfirmPassword"] = "", | ||
| ["Password"] = "", | ||
| ["Email"] = "" | ||
| }) | ||
| }; | ||
| message.Headers.TryAddWithoutValidation("Cookie", $"{cookie.Key}={cookie.Value}"); | ||
|
|
||
| // Act | ||
|
|
@@ -443,18 +444,20 @@ public async Task PageConventions_CustomizedModelCanPostToHandlers() | |
| public async Task PageConventions_CustomizedModelCanWorkWithModelState() | ||
| { | ||
| // Arrange | ||
| var getPage = await Client.GetAsync("/CustomModelTypeModel"); | ||
| var getPage = await Client.GetAsync("/CustomModelTypeModel?Attempts=0"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't strictly necessary because the |
||
| var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(await getPage.Content.ReadAsStringAsync(), ""); | ||
| var cookie = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getPage); | ||
|
|
||
| var message = new HttpRequestMessage(HttpMethod.Post, "/CustomModelTypeModel"); | ||
| message.Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
| var message = new HttpRequestMessage(HttpMethod.Post, "/CustomModelTypeModel?Attempts=3") | ||
| { | ||
| ["__RequestVerificationToken"] = token, | ||
| ["Email"] = "javi@example.com", | ||
| ["Password"] = "Password.12$", | ||
| ["ConfirmPassword"] = "Password.12$", | ||
| }); | ||
| Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
| { | ||
| ["__RequestVerificationToken"] = token, | ||
| ["Email"] = "javi@example.com", | ||
| ["Password"] = "Password.12$", | ||
| ["ConfirmPassword"] = "Password.12$", | ||
| }) | ||
| }; | ||
| message.Headers.TryAddWithoutValidation("Cookie", $"{cookie.Key}={cookie.Value}"); | ||
|
|
||
| // Act | ||
|
|
@@ -465,6 +468,37 @@ public async Task PageConventions_CustomizedModelCanWorkWithModelState() | |
| Assert.Equal("/", response.Headers.Location.ToString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task PageConventions_CustomizedModelCanWorkWithModelState_EnforcesBindRequired() | ||
| { | ||
| // Arrange | ||
| var getPage = await Client.GetAsync("/CustomModelTypeModel?Attempts=0"); | ||
| var token = AntiforgeryTestHelper.RetrieveAntiforgeryToken(await getPage.Content.ReadAsStringAsync(), ""); | ||
| var cookie = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getPage); | ||
|
|
||
| var message = new HttpRequestMessage(HttpMethod.Post, "/CustomModelTypeModel") | ||
| { | ||
| Content = new FormUrlEncodedContent(new Dictionary<string, string> | ||
| { | ||
| ["__RequestVerificationToken"] = token, | ||
| ["Email"] = "javi@example.com", | ||
| ["Password"] = "Password.12$", | ||
| ["ConfirmPassword"] = "Password.12$", | ||
| }) | ||
| }; | ||
| message.Headers.TryAddWithoutValidation("Cookie", $"{cookie.Key}={cookie.Value}"); | ||
|
|
||
| // Act | ||
| var response = await Client.SendAsync(message); | ||
|
|
||
| // Assert | ||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| var responseText = await response.Content.ReadAsStringAsync(); | ||
| Assert.Contains( | ||
| "A value for the 'Attempts' parameter or property was not provided.", | ||
| responseText); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ValidationAttributes_OnTopLevelProperties() | ||
| { | ||
|
|
@@ -642,10 +676,12 @@ public async Task RoundTrippingFormFileInputWorks() | |
|
|
||
| var cookie = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(response); | ||
|
|
||
| var content = new MultipartFormDataContent(); | ||
| content.Add(new StringContent("property1-value"), property1); | ||
| content.Add(new StringContent("test-value1"), file1, "test1.txt"); | ||
| content.Add(new StringContent("test-value2"), file3, "test2.txt"); | ||
| var content = new MultipartFormDataContent | ||
| { | ||
| { new StringContent("property1-value"), property1 }, | ||
| { new StringContent("test-value1"), file1, "test1.txt" }, | ||
| { new StringContent("test-value2"), file3, "test2.txt" } | ||
| }; | ||
|
|
||
| var request = new HttpRequestMessage(HttpMethod.Post, url) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for
PageBinderFactory