Commit Graph

33 Commits

Author SHA1 Message Date
Ryan Nowak 98b3f055e1 Change ModelBinding to use a single pass 2015-08-31 11:58:53 -07:00
Kiran Challa e12d44b40a [Fixes #2900] Get rid of manual body-read-state-tracking 2015-08-31 10:34:42 -07:00
Ryan Nowak 6d365e9a32 Make ValueProviderResult a string-ish struct 2015-08-21 11:02:40 -07:00
Ryan Nowak 07fabde92a Part 3 of #2776 - revert a6ce9abab1 and add
some more tests.

This change reverts the behavior change from
a6ce9abab1 and adds more tests around the
scneario that was actually broken.

The right behavior is that unconvertable values result in a validation
error. There's no special behavior around value types and required values.
2015-08-16 16:20:44 -07:00
Ryan Nowak a6ce9abab1 Fix #2776 - Add implicit [BindRequired] for value type properties 2015-08-13 15:35:54 -07:00
Mugdha Kulkarni 933a13608f Adding fix for 2756 and test cases. Skipping the test cases for 2793. 2015-07-10 15:58:36 -07:00
sornaks 68523a3550 Fixing tests in Mono.
- Disabling tests which have corresponding bugs in mono.
- Fixing a few tests which do not handle *nix file system.
- Updating Travis configuration to use mono's alpha bits.
- Introducing PlatformNormalizer to normalize content across multiple platforms.
2015-07-02 17:24:14 -07:00
Doug Bunting 9c63d1d842 Get tests working with `core.autocrlf=false`
- #1514
- refactor `RazorCompilationService` to allow a test subclass that normalizes Razor file line endings
 - add `TestRazorCompilationService` to `RazorPageExecutionInstrumentationWebSite`
 - adjust line endings to match in `RazorPageExecutionInstrumentationTest`
- add `ignoreLineEndingDifferences: true` to `Assert.Equal()` calls
 - responses on Windows can have a mix of line endings
  - `git config` setting affects line endings in .cshtml (and baseline) files
  - however MVC and Razor mix `Environment.NewLine`s into HTTP responses
- update `PrecompilationTest` to split response regardless of line endings
- update `ResourceFile` to normalize all source file streams to LF only
 - ensures consistent checksums and line mappings
 - change `MvcRazorHostTest` to expect new line mappings
 - recreate baseline files to expect new checksums and literal line endings
- use verbatim strings in affected tests
 - careful use of `Environment.NewLine` in expectations is now just noise

nits:
- add doc comments in `RazorCompilationService`
- correct `TagHelpersTest` name to match containing file
- avoid incorrect `using` removal when `GENERATE_BASELINES` is not defined
- remove unnecessary `ResourceFile` normalization of output files
2015-06-24 14:53:07 -07:00
Doug Bunting c4fa402105 Add `ModelBindingResult.IsFatalError` and make body binding more consistent
- 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
2015-06-18 16:19:01 -07:00
Doug Bunting ffd1dc1fb0 Add support for generating baseline output files while testing
- baselines include both expected output and design-time line mappings
- controlled by GENERATE_BASELINES
 - assertions related to file content are not checked in this mode
- add design-time test of Basic.cshtml to `MvcRazorHostTest`
- regenerate all files to avoid BOM and blank line noise in future PRs
 - update out-of-date design-time Basic.cs file

nits:
- make a few variable names more consistent
- make `Assembly` fields `static`
- remove unused `_resourcesAssembly` field from `ErrorPageTests`
- remove `ResourceHelpers` which was specific to functional tests
2015-06-01 13:13:39 -07:00
Doug Bunting e31eab0391 `ByteArrayModelBinder` should return `null` only when type is not matched
- #2456
- visible behaviours now match MVC 5
- prevent `CollectionModelBinder` from converting no value to `byte[0]`
- prevent `TypeConverterModelBinder` from converting empty value to `byte[] { '\0' }`

nit:
- remove additional delegates `ModelBindingTestHelper.GetOperationBindingContext()` calls
 - a few left despite #2625 cleanup
2015-06-01 12:20:17 -07:00
Harsh Gupta 4f419eee55 Removing creating ModelValidationNode by default in CompositeModelBinder.
This moves the responsibility of of MVN creation to individual model binders if they want the individual models to be validated.
2015-05-29 09:21:11 -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
James Newton-King de630754bf SerializerSettings refactor
Add SerializerSettings to MvcOptions and pass those options to the JsonInputFormatter and JsonOutputFormatter.
Remove custom contract resolver.

PR feedback
Pass JsonSerializerSettings to JsonPatchInputFormatter

PR feedback
Make DI JsonOutputFormatter formatter use MvcOptions SerializerSettings

Fix JsonPatchInputFormatter using null ContractResolver

Fix tests
2015-05-11 16:43:17 -07:00
N. Taylor Mullen 64e726d2b2 Update LICENSE.txt and license header on files. 2015-05-01 13:55:25 -07:00
Pranav K 124496a12f Use DateTimeOffset with fixed time zone in tests to allow it to work in
non-PST timezones.
2015-04-30 21:40:20 -07:00
Harsh Gupta adeb1ba194 Adding support for model binding specifically marked controller properties. 2015-03-20 17:37:09 -07:00
Doug Bunting 533474d07c Bind POCO model correctly; fallback to empty prefix despite exact name match
- #1865
- change `MutableObjectModelBinder` to ignore exact match in value providers
 - had an incorrect assumption: don't want exact model name to match since
   this binder supports only complex objects
 - also ignored `BinderModelName`, value provider filtering, et cetera
- reduces over-binding e.g. `[Required]` validation within missing properties

also add more tests of #2129 scenarios
2015-03-20 13:18:42 -07:00
Kirthi Krishnamraju 2b246e7acc Fix for #1694 issue : Removed prefix for ModelState keys for FromBody parameters 2015-03-20 10:41:06 -07:00
Harsh Gupta ac908d405e Removing ModelMetadataProvider.GetModelMetadataForParameters 2015-03-19 16:42:54 -07:00
Hao Kung 4b5dd199ca React to hosting changes 2015-03-19 11:07:25 -07:00
Kirthi Krishnamraju 7b18d1d3f1 Clear ModelState errors of model before TryValidateModel or TryUpdateModel 2015-03-11 10:14:28 -07:00
Doug Bunting cc7b319cb7 Remove use of `ServiceDescriber` in MVC and cleanup related hacks
- see issues aspnet/DependencyInjection#193 and #1612
- use `TryAdd()` in `MvcServices` for the `IAssemblyProvider`

Move `ApplicationBasePath` handling into `RazorPreCompileModule`
- restores view precompilation in functional tests of sample sites
- if we need this, others will as well
- override `IApplicationEnvironment` but get folder from `ProjectContext`
 - also remove remaining `IServiceProvider` implementations in this code

test fixes:
- simplify `IApplicationEnvironment` override
- move override logic into `TestHelper.CreateServer()` methods
- remove `LoggerFactory` setup
 - does not seem to require special-casing
- remove unused `ITestConfigurationProvider` / `TestConfigurationProvider`
- remove `TestAssemblyProvider` classes
 - no longer required
- remove `ReplaceCallContextServiceLocationService` test helper
 - change MVC sample to fully-qualify config.json path
  - avoids `ReplaceCallContextServiceLocationService` need in `MvcSampleTests`
 - no longer required for other tests

nit: remove unused `_serviceProvider` and constructor overload in `RazorPreCompiler`
2015-03-10 22:25:42 -07:00
N. Taylor Mullen e829ba7646 Update aspnet50/aspnetcore50 => dnx451/dnxcore50. 2015-03-08 12:52:24 -07:00
Ajay Bhargav Baaskaran 9f9dcbe6ec Additional functional tests for ElementalValueProvider 2015-02-25 10:22:43 -08:00
Kiran Challa f737083c94 Added JsonContractResolver to validate value type properties 2015-02-24 06:34:35 -08:00
Ryan Nowak 9d5364cf9b Removing ModelMetadata.Model 2015-02-23 19:56:59 -08:00
Kirthi Krishnamraju f6e701b2b2 Reverting #1837 and add non-generic overloads for TryUpdateModel 2015-02-23 10:02:51 -08:00
Harsh Gupta f19c2e493d Merging Model Validation for body and non body validation.
This also fixes #1503.

Currently all model binders except mutable object binder are independent of validation code. The mutable object binder which needs to do some validation ( for scenarios involving [BindRequired] and [BindNever]).
We would be going with an approach where required validaiton happens in input formatters and model binders.
This is needed as validation for value types can best be done at creation time.

Followup PRs:
Introduce support for skipping validation (and not binding) for a particular property/type etc.
2015-02-17 11:50:39 -08:00
Ajay Bhargav Baaskaran 088bb18eed Added support for binding FormCollection
- Added FormCollectionModelBinder
 - Added relevant unit and functional tests
2015-02-13 11:14:50 -08:00
Doug Bunting 3303286288 Add `ModelMetadata.AdditionalValues` property bag
- #1758
- provide the property bag in `ModelMetadata`; seal it in `CachedModelMetadata`
- add unit tests
- include use of `AdditionalValues` in model binding functional test

nits:
- expose `AdditionalValues` as an `IDictionary` though MVC 5 uses `Dictionary`
- seal `ModelMetadata.Properties` collection as well
- cover a few properties previously missed in `CachedDataAnnotationsModelMetadataTest`
- correct two `ModelMetadataTest` method names
2015-02-09 15:59:34 -08:00
Ajay Bhargav Baaskaran 5e704cd5ef Added custom exception message for Format Exception 2015-02-05 10:51:32 -08:00
Doug Bunting 8779cafbab Use `[Display(Order=x)]` to sort validation messages and properties
- #964
- compute `ModelMetadata.Order` based on `[Display]` attribute
 - property affects e.g. `@Html.DisplayFor()` generation for complex objects
 - also affects order of messages in validation summaries
- test new scenarios involving `ModelMetadata.Order`
 - per-property `ModelMetadata` and related tests
 - validation and `HtmlHelper` tests
 - add `HtmlHelperValidationSummaryTest` (which touches on #453)
- update ModelBinding functional test to show use of `[Display(Order = x)]`

nits:
- move more `NullDisplayText` bits into proper slots (just above `Order`)
 - add doc comments for `ComputeNullDisplayText()`
- add more assertions in tests using `ModelStateDictionary.HasReachedMaxErrors`
- remove some trailing whitespace
- avoid `Assert.True()` & `Assert.False()`; split some assertions up
- `""` -> `string.Empty` in affected test classes
- rename "DefaultEditorTemplatesTest~~s~~" class and file to follow guidelines
- rename "ModelBindingTest~~s~~" class and file to follow guidelines

FYI #1888 covers a predictable (or even just stable) order in the UI
2015-01-29 09:31:05 -08:00