Commit Graph

22 Commits

Author SHA1 Message Date
Ryan Nowak 8f38650d1f Fix #1579 - Bind top-level collections as an empty collection
This change treats 'top-level' collection-type models similarly to
top-level POCO model - namely that they will always be instantiated even
if there's no data to put inside.
2015-05-21 22:46:04 -07:00
Harsh Gupta d0927bdc75 Fixes #2464 - Does not add extra skipped entries for model bound from services.
Also ensures that when a type is marked as skipped, any sub property which is model bound (and hence a modelstate un validated entry),
is marked as skipped (otherwise it would cause the ModelState to be invalid).
Also fixing a bug in model state dictionary FindKeyWithPrefix was not considering [0] & [0][0] as a valid prefix.
2015-05-15 12:27:43 -07:00
Harsh Gupta 88ac4b94e4 Fixing #2466, #2446.
The assumption is ModelState should have entries if
1. An error is explicitly added by a model binder.
2. There is validation error reported while validating the model.
3. There is value bound by the model binder.

With this change there should be no extra entry other than for the cases mentioned above.

Also enabling the integration test cases.
2015-05-15 12:27:41 -07:00
Harsh Gupta 22f1881cc6 Restoring modelvalidation node. 2015-05-14 18:38:26 -07:00
Ryan Nowak 90805fa827 Pass InputFormatters in OBC
This removes the need to use IScopedInstance<ActionBindingContext> to get
access to the formatters.
2015-05-13 16:02:34 -07:00
Doug Bunting fcf7b15c64 Remove `FromBodyOnProperty_RequiredOnValueTypeSubProperty_AddsModelStateError`
- this integration test depends on the old `[Required]` special case
- #2388 explicitly removes that bahaviour so the test goes with it
2015-05-11 17:18:52 -07:00
Harsh Gupta 583277cceb Adding tests for ActionParameters and TryUpdateModel 2015-05-08 19:11:03 -07:00
Chris R bd03142dab React to Http namespace changes. 2015-05-07 15:19:10 -07:00
Chris R 7f737246b1 React to QueryString API changes. 2015-05-06 15:20:40 -07:00
Ryan Nowak a5df6679f9 More model binding integration tests
Includes tests for a ValidationAttribute other than RequiredAttribute on
complex models using POCOs and collections
2015-05-04 11:20:52 -07:00
Kiran Challa 284c899233 Register default services directly in AddMvc and remove MvcServices 2015-05-04 10:53:34 -07:00
Harsh Gupta f37f2ae352 Validations with BindRequired on properties. 2015-05-04 10:32:35 -07:00
Harsh Gupta 502b832d17 Integration tests for
Collection Model Binder -> MutableObject(POCO) Model Binder – With-Data/Fallback-to-empty-prefix/Without-Data
2015-05-04 09:52:15 -07:00
Ryan Nowak 1ee5238709 Another batch of ModelBinding integration tests
Includes tests for [Required] on properties with various levels of nesting
inside complex model binders.
2015-05-01 14:22:44 -07:00
N. Taylor Mullen 64e726d2b2 Update LICENSE.txt and license header on files. 2015-05-01 13:55:25 -07:00
Harsh Gupta 3a3acde904 Simple ModelBinders and Simple ModelBinder Poco-2
Covers simple scenario for each model binder.
Covers scenarios mixing a POCO model binder -> Simple Model binder.

This contains tests for
FormCollectionModelBinder
BinderTypeBasedModelBinder
TypeConverterModelBinder

Remainging:
TypeMatchModelBinder

This also adds missing unit test for TypeMatchModelBinder as well.
2015-04-30 13:43:02 -07:00
Ryan Nowak 95feb5a3ec ModelBinding Integration tests part 3 2015-04-30 12:45:10 -07:00
Ryan Nowak 4b686b1234 Part 2 of integration tests for GenericModelBinder
This includes a random sampling of combinations where a collection model
binder is binding another collection as an element type.
2015-04-29 16:52:52 -07:00
Chris R b455724859 Remove redundant Http.Core and Http.Interfaces dependencies. 2015-04-29 15:59:52 -07:00
Ryan Nowak f77bb0ed2f GenericModelBinder integration tests part 1
- Covers simple scenario for each model binder.
- Covers scenarios mixing a generic model binder with a greedy model
  binder.
2015-04-28 17:43:29 -07:00
Harsh Gupta b5b37265e1 Simple ModelBinders and Simple ModelBinder Poco - 1
Covers simple scenario for each model binder.
Covers scenarios mixing a POCO model binder -> Simple Model binder.

This contains tests for
HeaderModel
ServicesModelBinder
CancellationTokenModelBinder
ByteArrayModelBinder
FormFileModelBinder

Part 2 Will contain similar tests for
FormCollectionModelBinder
BinderTypeBasedModelBinder
TypeConverterModelBinder
TypeMatchModelBinder
Any leftovers for BodyModelBinder
2015-04-28 14:13:36 -07:00
Harsh Gupta 53ef8258bb The model state keys for body bound models which are bound at property will use the entire model name with this change for example
Consider

public class Person
{
    [FromBody]
    public Address Address { get; set; }
}

public class Address
{
   [Required]
   public string Street { get; set; }

   public int Zip { get; set; }
}

Request body { "Zip" : 12345 }
In this case the error key would be "prefix.Address.Street" (assuming there is a prefix because of additional metadata/positioning for/of the Person model).

public class Person
{
       [Required]
       public string Name { get; set; }
}

public void Action([FromBody]Person p)
{
}
Request body { }
In this case the prefix gets ignored and the error key is Name.
Please note this is so that we are compatible with MVC 5.0

public class Person
{
       [Required]
       public string Name { get; set; }
}

public void Action([FromBody][ModelBinder(Name = "prefix")] Person p)
{
}

public void Action2([FromBody][Bind(Name = "prefix")] Person p)
{
}
Request body { }
In both these cases (Action and Action2) the prefix gets ignored and the error key is Name.
This is a slight improvement from mvc, as in MVC the action parameter would be null.

The followup for this would be to fix #2416 -
This PR ignores the validation assuming that #2416 will address the issues and update the test.

NOTE: previous versions of mvc did not have property binding and hence there is no precedence in this case. For MVC and Web API it was possible to body bind an action parameter which used an empty prefix instead of a parameter name for adding errors to model state (In case of MVC if a custom prefix was provided, it failed binding from body i.e the parameter was null).
2015-04-22 14:02:08 -07:00