Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Model State should have values for greedy model binders as well. #2445

Closed
harshgMSFT opened this issue Apr 24, 2015 · 2 comments
Closed

Model State should have values for greedy model binders as well. #2445

harshgMSFT opened this issue Apr 24, 2015 · 2 comments

Comments

@harshgMSFT
Copy link
Contributor

Currently HeaderModelBinder and BodyModelBinder do not populate the model state by calling SetModelValue, for success cases. This means we cannot do a ajax post which uses the populated value.

@Eilon Eilon added this to the 6.0.0-beta5 milestone Apr 24, 2015
@danroth27 danroth27 modified the milestones: 6.0.0-beta6, 6.0.0-beta5 May 11, 2015
@dougbu
Copy link
Member

dougbu commented May 27, 2015

Based on the tests that are disabled with this bug as the reason, problem is much more broad. All values bound from user input should have ModelState entries. This affects ByteArrayModelBinder, FormCollectionModelBinder, and FormFileModelBinder as well as the two mentioned in the original description (BodyModelBinder and HeaderModelBinder). So, "type-matching" as well as "greedy" binders.

dougbu added a commit that referenced this issue Jun 14, 2015
…istent

- part I of II for #2445 (with a duplicate code PR to follow)
- needed for #2445 because new `ModelState` entries for values will make inconsisteny worse
- change `BodyModelBinder` to use same keys for all `ModelBindingResult`s and `ModelState` entries
 - return fatal error result if formatter adds an error to `ModelState`
 - update potential callers to avoid avoid ignoring `IsFatalError`
- fix test attempting to serialize all of `ModelState`
 - will be borked with additional `RawValue`s in state
- fix two other tests that serialized `ModelState` but checked only `IsValid`

nits:
- address minor inconsistencies in `ModelBindingContext`
- use `System.Reflection.Extensions` package a bit more, where it's already referenced
- remove some unused resources
dougbu added a commit that referenced this issue Jun 14, 2015
- part II of II for #2445
- enable tests that #2445 was blocking
 - fix these and other tests expecting different `ModelState` entries
dougbu added a commit that referenced this issue Jun 14, 2015
- cleanup duplicate code now that #2445 is fixed
- update unit tests using old `ModelBindingContext` setups
- fix (just) one integration test where `MutableObjectModelBinder` incorrectly calculated
  `isTopLevelObject` and returned a non-`null` model
- undo temporary changes in `BodyModelBinderTests` due to increased reliance on incorrect
  `isTopLevelObject` in #2445 fix

nits:
- combine tests that are now duplicates
- beef up coverage of some `MutableObjectModelBinderTest` cases
dougbu added a commit that referenced this issue Jun 21, 2015
…istent

- part I of II for #2445 (with a duplicate code PR to follow)
- needed for #2445 because new `ModelState` entries for values will make inconsisteny worse
- change `BodyModelBinder` to use same keys for all `ModelBindingResult`s and `ModelState` entries
 - return fatal error result if formatter adds an error to `ModelState`
 - update potential callers to avoid avoid ignoring `IsFatalError`
- fix test attempting to serialize all of `ModelState`
 - will be borked with additional `RawValue`s in state
- fix two other tests that serialized `ModelState` but checked only `IsValid`

nits:
- address minor inconsistencies in `ModelBindingContext`
- use `System.Reflection.Extensions` package a bit more, where it's already referenced
- remove some unused resources
dougbu added a commit that referenced this issue Jun 22, 2015
- part II of II for #2445
- enable tests that #2445 was blocking
 - fix these and other tests expecting different `ModelState` entries
dougbu added a commit that referenced this issue Jun 22, 2015
- cleanup duplicate code now that #2445 is fixed
- update unit tests using old `ModelBindingContext` setups
- fix (just) one integration test where `MutableObjectModelBinder` incorrectly calculated
  `isTopLevelObject` and returned a non-`null` model
- undo temporary changes in `BodyModelBinderTests` due to increased reliance on incorrect
  `isTopLevelObject` in #2445 fix

nits:
- combine tests that are now duplicates
- beef up coverage of some `MutableObjectModelBinderTest` cases
dougbu added a commit that referenced this issue Jun 24, 2015
- part II of II for #2445
- `FormCollectionModelBinder` is an exception because container is not user-provided
 - no `ModelState` entry added
- enable tests that #2445 was blocking
 - fix these and other tests expecting different `ModelState` entries
- simplify logic in `FormFileModelBinder`

`ValueProviderResult`
- remove `protected` setters and parameterless constructor
 - no scenario for their use in subclasses; however `ConvertTo()` remains `virtual`
- add single-parameter constructor
 - use in most of the greedy and type-matching model binders
- add doc comments throughout class

nits:
- use new `ValueProviderResult` constructor in many existing tests
- `""` -> `string.Empty` and `vpr` -> `valueProviderResult` in `ValueProviderResultTest`
- improve some test names in `BodyValidationIntegrationTests`
- do not check `Message` of a Json.NET `Exception`
dougbu added a commit that referenced this issue Jun 24, 2015
- cleanup duplicate code now that #2445 is fixed
- update unit tests using old `ModelBindingContext` setups
- fix (just) one integration test where `MutableObjectModelBinder` incorrectly calculated
  `isTopLevelObject` and returned a non-`null` model
- undo temporary changes in `BodyModelBinderTests` due to increased reliance on incorrect
  `isTopLevelObject` in #2445 fix

nits:
- combine tests that are now duplicates
- beef up coverage of some `MutableObjectModelBinderTest` cases
- remove unused `using`s
@dougbu
Copy link
Member

dougbu commented Jun 24, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants