Commit Graph

21 Commits

Author SHA1 Message Date
Pranav K 8d66f104f7 Make types in Microsoft.AspNetCore.Mvc.Internal namespace internal 2018-11-08 14:00:16 -08:00
Doug Bunting e0e96ce53b
Include parameter type's attributes in ModelMetadata
- #7595
- #7595 relates to #7350 but does not have the same root cause
  - did _not_ revert the src changes in #7350 fix (d995b0418a)
- make non-`[Obsolete]` `ModelAttributes` constructor overload `internal`
  - should generally use `static` methods and not any constructor
  - change some unit tests to use `[Obsolete]` constructor overloads (with suppressions)
- fix test `ParameterBinderExtensions` to use current `ParameterBinder.BindModelAsync(...)` overload
  - found some tests updated `IModelMetadataProvider`, `MvcOptions`, etc. instances but didn't register them in DI
- extend `ModelBindingTestHelper` and `ModelBindingTestContext`
  - reorder some tests to use correct `MvcOptions` and `IModelMetadataProvider` everywhere
  - fixes above issues

nits:
- take a few VS suggestions
- remove an old comment indended only for PR "Reviewers:"
2018-04-17 12:40:38 -07:00
Pranav K c515cece8e Use ModelMetadataProvider to infer BindingSource on application model 2018-04-02 09:48:49 -07:00
Doug Bunting fc3a815e57
Restore `ModelMetadata.PropertyName != null` behaviour
- #7413 part 2 of 2
- add `ModelMetadata.Name` and `ParameterName`
  - use `Name` instead of `PropertyName` in most cases
- update `ModelMetadata.ContainerType` and other property use
  - choose using `MetadataKind` almost everywhere; support all possibilties
    - usually parameter metadata was possible but not handled
    - worst case was one or two potential NREs, especially `ContainerType.*` dereferences
  - improve `MvcCoreLoggerExtensions` metadata handling
    - add three new debug messages, one for type metadata and two for parameter metadata
- update `ModelMetadata.ContainerMetadata`, `ContainerType` and `PropertyName` doc comments
- no changes needed in Microsoft.AspNetCore.Mvc.ViewFeatures because parameters aren't viewed

nits:
- add missing `TestModelMetadataProvider.ForParameter(...)` method
- remove unused `EmptyModelMetadataProvider` instances in `ModelMetadataTest`
- refactor `ModelValidationResultComparer` out of DataAnnotationsModelValidatorTest`
- take VS suggestions, mostly related to variable inlining and object initializers
2018-03-29 07:22:00 -07:00
Jass Bagga 8d1c85ab74
Add overload for AddModelError without ModelMetadata (#7407)
Addresses #6102
2018-03-02 11:03:46 -08:00
Steve Sanderson d9825d1547 Better JSON deserialization errors. Implements #4607, #4862 2017-11-06 23:02:13 +00:00
Nate McMaster 3f02482617 Minor test code changes to resolve xUnit2013 build error 2017-10-05 16:04:20 -07:00
Nate McMaster 3a710c3d64 Upgrade to xunit 2.3.0-beta4 2017-08-17 10:45:03 -07:00
Doug Bunting a90f4118ad Do not include type names in `ModelState` error messages
- #6076
- add resources and accessors specifically for the element / parameter cases
- avoid `metadata.GetDisplayName()` where possible
- fill in the `ValidationContext` that `ValidatorObjectAdapter` uses
  - e.g. `Validate_NestedComplexType_IValidatableObject_Invalid()` test fails without this

Possible future work:
- improve error message used for `ModelMetadata.IsRequired` elements and parameters
- use something besides the type for `ValidationContext.DisplayName` of elements and parameters

nits:
- trailing whitespace
- use more `out var`
2017-06-28 15:16:23 -07:00
Steve Sanderson 014a786b45 Replace IModelBindingMessageProvider with new highly-virtual base class (#6241)
Replace IModelBindingMessageProvider with new highly-virtual base class. Fixes #6069
2017-05-10 16:02:18 +01:00
Kiran Challa c95c2a5a6d [Fixes #5686] Extend `ModelMetadata` to reduce ugliness 2017-02-03 11:37:28 -08:00
Doug Bunting ce53675b87 Add `[ValidateNever]` and `IPropertyValidationFilter`
- #5642
- lazy-load `ValidationEntry.Model`
  - avoids `Exception`s when moving to a property that will not be validated

nits:
- remove duplicate code in `ValidationVisitor`
- clarify "all properties of" doc comments
  - also add missing `<param>` doc in `ViewDataInfo`
2017-01-15 21:40:29 -08:00
Doug Bunting 42cea41737 Fail more gracefully when option collections cleared
- #4690
- move `ModelBindingMessageProvider` init from `DefaultBindingMetadataProvider` to `DefaultModelMetadata`
 - in addition to avoiding error cases, this removes some boilerplate
- add specific errors to `BodyModelBinderProvider`, `CompilerCache`, `CompositeViewEngine`, `ModelBinderFactory`,
  and `ObjectResultExecutor`
 - `DefaultRazorViewEngineFileProviderAccessor.FileProvider` now a `NullFileProvider` in empty case
2016-06-30 14:52:50 -07:00
Michiel Post b6794ab1b7 Fixed null reference on ModelStateDictionary.ChildNodes when calling Clear 2016-05-26 16:12:49 -07:00
Ryan Nowak 144766f2e3 Simplify BindAttribute - rename PredicateProvider
This change renames IPropertyBindingPredicateProvider to
IPropertyFilterProvider. The changes here are mostly renames of
parameters/variables from predicate -> propertyFilter. I did a
find+replace and left the term 'predicate' in some of the docs because it
refers to a predicate in the abstract sense.

This change also simplifies BindAttribute and removes support for type
activation.
2016-03-31 12:34:02 -07:00
Pranav K f651f18d3a Use a prefix tree as a backing store for ModelStateDictionary 2016-03-17 10:09:36 -07:00
Ryan Nowak b557ca55d9 Fix behavior of StartsWithPrefix
This undoes a behavior change introduced in
7b18d1d3f1.

The intent was to have ClearValidationState do the right thing for a case
where a collection was bound to the empty prefix, and then used again with
TryUpdateModel.

This change was implemented by saying that a key like "[0].Foo" is a match
for the prefix of "Foo". This isn't really right, and it's only
interesting for the ClearValidationState case.

The problem is that we don't know what the keys look like for a
collection. We can assume that they start with [0] but that's not really a
guarantee, it's a guess.

This change fixes the behavior of StartsWithModel, and move the
responsibility for this case back into ClearValidationState.

This change also removes the call to ClearValidationState from
TryUpdateModel. If you need this behavior, then call ClearValidationState
manually. Trying to bind and then re-bind a model object isn't really what
we intend.
2016-02-17 11:16:16 -08:00
Doug Bunting 26a14a25ab Support overrides for client-side validation messages
- #2969
- `RemoteAttribute` did not support `IStringLocalizer` overrides
 - use same `MvcDataAnnotationsLocalizationOptions` property as for other `ValidationAttribute`s
- error message `NumericClientModelValidator` added could not be overridden
 - not related to `IStringLocalizer` because users have no way to set the resource lookup key
 - extend `IModelBindingMessageProvider` to add the necessary `Func<,>`
- also correct problem using resources with `RemoteAttribute` and add lots of tests
2016-01-29 11:23:57 -08:00
Derek Gray 8b726ddc0c Allow the use of the Prompt property of DisplayAttribute for the placeholder attribute of input fields (addresses #3723) 2016-01-27 16:18:23 -08:00
N. Taylor Mullen 3be7fbdf9f Rename AspNet 5 file contents.
See https://github.com/aspnet/Announcements/issues/144 for more information.
2016-01-22 12:18:33 -08:00
N. Taylor Mullen 6a6c8ca544 Rename AspNet 5 folders and files.
See https://github.com/aspnet/Announcements/issues/144 for more information.
2016-01-22 12:17:07 -08:00