This repository has been 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
Removing IInputFormatterSelector #2353
Merged
+119
−146
Merged
Changes from all commits
Commits
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
26 changes: 0 additions & 26 deletions
26
src/Microsoft.AspNet.Mvc.Core/Formatters/DefaultInputFormatterSelector.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/Microsoft.AspNet.Mvc.Core/Formatters/IInputFormatterSelector.cs
This file was deleted.
Oops, something went wrong.
This file contains 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 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
67 changes: 0 additions & 67 deletions
67
test/Microsoft.AspNet.Mvc.Core.Test/DefaultInputFormatterSelectorTests.cs
This file was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
|
@@ -126,6 +126,44 @@ public async Task JsonInputFormatter_IsModelStateValid_ForValidContentType(strin | |
Assert.Equal(expectedSampleIntValue.ToString(), responseBody); | ||
} | ||
|
||
[Theory] | ||
[InlineData("\"I'm a JSON string!\"")] | ||
[InlineData("true")] | ||
[InlineData("\"\"")] // Empty string | ||
public async Task JsonInputFormatter_ReturnsDefaultValue_ForValueTypes(string input) | ||
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. How about an empty string content? that should be treated as a null value and a model state error should be added by JsonInputformatter |
||
{ | ||
// Arrange | ||
var server = TestHelper.CreateServer(_app, SiteName, _configureServices); | ||
var client = server.CreateClient(); | ||
var content = new StringContent(input, Encoding.UTF8, "application/json"); | ||
|
||
// Act | ||
var response = await client.PostAsync("http://localhost/JsonFormatter/ValueTypeAsBody/", content); | ||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
|
||
//Assert | ||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); | ||
Assert.Equal("0", responseBody); | ||
} | ||
|
||
[Fact] | ||
public async Task JsonInputFormatter_ReadsPrimitiveTypes() | ||
{ | ||
// Arrange | ||
var expected = "1773"; | ||
var server = TestHelper.CreateServer(_app, SiteName, _configureServices); | ||
var client = server.CreateClient(); | ||
var content = new StringContent(expected, Encoding.UTF8, "application/json"); | ||
|
||
// Act | ||
var response = await client.PostAsync("http://localhost/JsonFormatter/ValueTypeAsBody/", content); | ||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
|
||
//Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.Equal(expected, responseBody); | ||
} | ||
|
||
[Theory] | ||
[InlineData("{\"SampleInt\":10}")] | ||
[InlineData("{}")] | ||
|
Oops, something went wrong.
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 was my bad. I think the first parameter here was supposed to be assigned the default value for type model calculated above?
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.
MethodInfo.Invoke
seems to take care of coercing null value types to default values for value types (this is verified by test).[FromBody]
, we end up getting a null ref as part of the property setter. Tracking this via Value type controller properties with [From*] fail with NullRef exception when no value is available #2357.That said, it seems like fixing it specifically for
BodyModelBinder
is incorrect and we should have a single top level piece of code that addresses this, not individual binders.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.
👍