Commit Graph

179 Commits

Author SHA1 Message Date
Ryan Nowak fc00aff7c5 Add TestCommon project 2015-03-16 13:49:29 -07:00
N. Taylor Mullen 385fa29407 Update xunit.runner.kre => xunit.runner.aspnet. 2015-03-12 18:01:41 -07:00
N. Taylor Mullen c1a026cbf7 Update .kproj => .xproj. 2015-03-11 14:01:43 -07:00
Kirthi Krishnamraju 7b18d1d3f1 Clear ModelState errors of model before TryValidateModel or TryUpdateModel 2015-03-11 10:14:28 -07:00
N. Taylor Mullen 1d578ca2fd Remove BOM from project.json, *.cmd, *.sh and *.shade files. 2015-03-09 12:56:42 -07:00
N. Taylor Mullen e829ba7646 Update aspnet50/aspnetcore50 => dnx451/dnxcore50. 2015-03-08 12:52:24 -07:00
Ryan Nowak 15bb080b7d Remove commented out legacy tests
Reviewed with @HarshGMSFT - we don't think there's anything here that
isn't already covered elsewhere.
2015-03-05 14:13:23 -08:00
Ryan Nowak df358f8b98 fix build break in razor tests and tests for resources 2015-03-05 13:54:24 -08:00
Ryan Nowak 90cef3b9ca Refactor of the model metadata provider
Separates the MMP into two phases:
1). Creation of the ModelMetadata, discovery of properties and attributes
(reflection) is part of the MMP
2). Lookup of details based on attributes is now part of another phase,
and has its results cached.

Users can now implements and register an IFooMetadataProvider to customize
a single aspect of metadata (see how data annotations does it).
2015-03-05 13:19:10 -08:00
Hao Kung c290e897b0 React to DI 2015-03-04 19:26:54 -08:00
Doug Bunting 28561e9924 Follow up to `ModelExplorer` creation
- see commit 9d5364c
- never correct to pass a `Func<object>` to `GetExplorerForExpression()`
- `<label/>` tests succeeded because that tag helper doesn't use expression result
- `<select/>` tests succeeded because that tag helper gets result from `ViewData`
 - does not use `ModelExplorer` due to #1468

nit: update variable names `metadata` -> `modelExplorer`
2015-03-01 09:39:36 -08:00
Ryan Nowak 9d5364cf9b Removing ModelMetadata.Model 2015-02-23 19:56:59 -08:00
N. Taylor Mullen df4b92b1c1 Update MVC projects to utilize Common repo classes.
- Had to add extra dependencies to work around aspnet/XRE#1237.
- Updated src and test projects.
2015-02-22 18:23:28 -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
Stephen Halter 5de210f527 Fix for #1416 - Remove all uses of ITypeActivator and use the static method instead
- ITypeActivator is being removed
- Where an ITypeActivator was used before, use the static ActivatorUtilities
2015-02-16 16:02:39 -08:00
Doug Bunting 0549769fd0 Set `ModelMetadata.TemplateHint` based on data annotations
- add `CachedDataAnnotationsMetadataAttributes.UIHint`
- set `ModelMetadata.TemplateHint` using `UIHintAttribute` or `HiddenInputAttribute`
- add doc comments for `TemplateHint`-related properties and methods
- add unit tests and use these attributes in functional tests

nits:
- cache and seal `CachedModelMetadata.IsCollectionType`
- correct doc comments for `ModelMetadata.RealModelType`
- add doc comments for `IsCollectionType`-related properties and methods
- add doc comments for `IsComplexType`-related properties and methods
- move `CachedModelMetadata.IsComplexType` right below `IsCollectionType`
 - same for related fields and methods
2015-02-13 15:28:45 -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 ca65b1b6ed Correct recent checkins
- correct typo in 3303286288
 - really seal `CachedModelMetadata.Properties`
- make a couple of test methods `public` (!!)
- add Microsoft.AspNet.PageExecutionInstrumentation to Mvc.sln
- remove `<RootNamespace/>`, `<ProjectExtensions/>`, etc. from .kproj files
2015-02-12 08:53:17 -08:00
Doug Bunting f93fca1077 PR comments
- change `AdditionalValues` type to `IDictionary<object, object>`
- copy `ModelMetadata.AdditionalValues` in `AssociatedMetadataProvider` sub-classes

nits:
- add XML comments
- correct indentation in `CachedModelMetadata`
2015-02-09 16:24:28 -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
Ryan Nowak 12f8f23ccb Make BindingSource extensible
This is a major refactor of how IBinderMetadata interacts with model
binders and value providers. We're doing this to support better
extensibility for metadata in ApiExplorer.

You'll notice a bunch of deleted code in DefaultApiDescriptionProvider
that maps metadata marker interfaces to a fixed list of Api sources. This
is replaced now with IBindingSourceMetadata - which also replaces the
hierarchy of marker interfaces. Now user code can create an arbitrary
binding source and have a consistent API for model-binders,
value-providers and full-visibility in ApiExplorer as
well.

Additonally, there's some error checking in place that better enforces the
constraints we already have in the system. IE you can't create a 'greedy'
model binder that uses value-provider data.

Two additional enhancements are planned for followup PRs:
1. Add a BindingSource property to model-metadata. This will remove some
duplication, but I want to delay it because it would touch another 10 or
so files.

2. Add an extensibility interface for our 'special' model binders like the
file binder so these can show up in ApiExplorer as well.
2015-02-05 13:41:31 -08:00
Ajay Bhargav Baaskaran 5e704cd5ef Added custom exception message for Format Exception 2015-02-05 10:51:32 -08:00
Harsh Gupta e805e67b4c [Fix for #1929] HeaderModelBinder needs to honor explicit name. 2015-02-03 19:36:48 -08:00
Doug Bunting 80b004678d Get `[Remote]` and supporting classes building
- #439 (2 of 3)
- correct namespaces
- correct `Resources` class and member names; add new resources
- add `RequestServices` property to `ClientModelValidationContext`
- adjust to modern `IUrlHelper` API
- add `IClientModelValidator` support in `DataAnnotationsModelValidator`
- move previously-unused `StringSplit()` to `RemoteAttribute` and rename
- rewrite `RemoteAttributeTest`
 - improve test method names

Reduce number of `[Remote]` constructor overloads
- remove `AreaReference` enum and related `[Remote]` constructor overload
 - use `null` or empty `string` as explicit reference to the root area
- generally reduce parameter validation; match `UrlHelper`

Cleanup
- correct Engineering Guidelines violations
 - especially: add doc comments
- correct spelling error in `_additonalFieldsSplit`

nits:
- minimize `null` checks in `AdditionalFields`
- make `GetClientValidationRules` `virtual`; some subclasses use `new` today
- add tests of `DataAnnotationsModelValidator.GetClientValidationRules()`
- remove `builder.ToString()` calls since it appears
  https://roslyn.codeplex.com/workitem/246 has been resolved or Moq has
  worked around that issue.
2015-01-30 12:26:48 -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
Ryan Nowak 42df4cf2ed Fix for #1538 and #1891
Changes here are all focused around MaxModelErrors on
ModelStateDictionary.

MaxAllowedErrors now defaults to 200 (same as options). This means that
constructing a new ModelStateDictionary with the default constructor will
use this default. There's a new constructor for creating a
MaxAllowedErrors with a non-default value.

The ControllerActionArgumentBinder is now responsible for setting the
value from options onto ActionContext.ModelState. This results in better
layering and guarantees the option is respected if someone uses
extensibility to call model binding.

ModelStateDictionary.CanAddErrors is renamed to MaxErrorsReached. We
wanted to change the behavior of this property, but realized that it's
very useful inside the model validation code, so opted to renamed.

There's also a bunch of doc cleanup inside ModelStateDictionary to
simplify things and improve clarity.
2015-01-28 16:53:28 -08:00
Ryan Nowak 8399dc5f4e Add a custom collection type for ModelMetadata.Properties
This is a cleanup PR to improve the common usage of
ModelMetadata.Properties.

We found placed in code where both .Count and the ability to index by
property name would be useful. I was able to cascade this and simplify the
ModelBindingContext as well.
2015-01-26 14:36:40 -08:00
N. Taylor Mullen 14bd7dcd5e Handle trailing semicolon after @inject.
- Made @inject handle trailing semicolons identical to @using; essentially ignores it.
- Added parser, runtime/designtime codegen and functional tests.
- Added Microsoft.AspNet.Mvc.Common.Test.
- Transitioned pre-existing Microsoft.AspNet.Mvc.Common tests to the new test project.
- Updated transitioned tests to also work in CoreCLR (except ones with moq).

#1857
2015-01-22 14:01:10 -08:00
Ryan Nowak 09928a2818 Adds parameter information to ApiExplorer
This change makes ApiDescription and ApiParameterDescription aware of all
of the new features we built into model binding for enhanced DTO support
(uber-binding).

The main change is that instead of sticking just to the declared
parameters on the action itself, we now traverse model metadata and break
the parameters down based on their logical data source.

This means that a model like the below will yield 3 parameters:

public class ProductChangeCommandDTO
{
    public int Id { get; set; }

    [FromBody]
    public ProductDetails Changes { get; set; }

    [FromQuery]
    public string AdminComments { get; set; }

    [FromServices]
    public IProductRepository Repository { get; set; }
}

The 'Repository' will be hidden, as it's not related to user input.

Additionally, we treat different sources differently. In the
above example, 'Changes' is from the body and will be treated as a
leaf-node.

However if you use nested DTOs that are bound from the query string (using
[FromQuery]) or similar, we'll recursively explore to find as much
structure as possible.

This information is combined with data from the route template to give a
much more complete picture than we ever could in the past for parameters,
especially when DTO/Command pattern is used.
2015-01-22 13:30:41 -08:00
Ajay Bhargav Baaskaran 67b078862e Fixed content-disposition quoted filename bug 2015-01-19 13:15:18 -08:00
Ryan Nowak 51e7812e7e Fix for #1722 - FromHeader does not respect default value
This change adds support for our three-valued logic to the default value
handling part of the MutableObjectModelBinder.

The issue is that we want to look up a default value when a 'greedy' model
binder returns true but doesn't find a value.

We also don't want to call the property setter unless there is:
1). A value from model binding OR
2). A default value
2015-01-16 17:59:00 -08:00
Ryan Nowak 3dea6b11a3 Issue #1695 - Create a pattern for a 'greedy' model binder.
See #1695 for a detailed explanation. This change builds support into the
system for the case that a model binder returns true without setting a
value for the Model.

In this case, validation will be skipped if it's a top-level object.

Note that explicitly setting null will still run validation.
2015-01-15 16:32:50 -08:00
Chris Ross 9aff289dfe Handle PipelineCore rename. 2015-01-15 15:25:17 -08:00
Pranav K bef9af4679 Fixing build break
* Run ModelBinding test that uses Moq to run under ASPNET50
* Update AssociatedValidatorProviderTest to reflect API changes
2015-01-15 14:20:00 -08:00
Pranav K fe1bcc7a24 ElementalValueProvider performs incorrect prefix check in
ContainsPrefixAsync

Fixes #1814
2015-01-15 14:02:41 -08:00
Ajay Bhargav Baaskaran 437eb93bde File upload model binder
- Support for binding posted file to type IFormFile
- Support for multipart/form-data in FormValueProviderFactory
- Updated Mvc Sample
- Added relevant unit and functional tests
2015-01-15 13:41:14 -08:00
Kirthi Krishnamraju 6a824a4394 Added ModelMetadataType Attribute and logic to get attributes from ModelMetadata class 2015-01-15 13:19:10 -08:00
Ryan Nowak 5ac5c53c09 Adding Resource Filters
This is a new filter stage that surrounds the existing model binding,
action, and result parts of the pipeline. Resource Filters run after
Authorization Filters.

The other major change is to support one of the primary scenarios for
Resource Filters. We want a filter to be able to modify the inputs the
model binding (formatters, model binders, value providers, etc) -- this
means that those changes need to be held on a context object and preserved
so that they can be used in the controller.

So, IActionBindingContextProvider is removed - the ActionBindingContext
will be created by the invoker. For now it will be part of the action
context.
2015-01-12 14:18:20 -08:00
Ajay Bhargav Baaskaran 52a984c52d react to aspnet/HttpAbstractions#146 changes 2015-01-07 17:53:35 -08:00
Pranav K 22ac7c45e5 Update Mvc to use official xunit runner 2014-12-17 11:27:07 -08:00
Doug Bunting 3e26142de1 Remove use of `Assert.DoesNotThrow()`
- no longer in xunit 😃
2014-12-11 15:51:15 -08:00
Ryan Nowak 1631ca1a47 Fix for #1681 - Model state errors are wrong with attributes like [FromHeader]
The issue here is that a model state error is added with the model name
'doubled'. This is on a fairly obscure code path and the code dates back
to the original WSR git checkin of webapi. There are no wsr tests that
verify this behavior.

The cause here is that our 'greedy' model binders (like
FromHeaderModelBinder) return 'true' whether or not they successfully
found a model, because they don't want other model binders to run.

This also has an effect on the validation system. That means that
validators will run and attempt to validate the model (which may be null).
That's that rare case where we get to this code path.
2014-12-10 14:03:51 -08:00
Harsh Gupta d7094fd32d Adding Support for TryUpdateModel using include expressions and predicate. 2014-12-05 17:28:43 -08:00
Ryan Nowak ca714c5149 CR feedback from [ModelBinderAttribute] 2014-12-05 16:10:07 -08:00
Harsh Gupta e9bcc3f0e8 Adding support for ModelMetadataAttribute in core. 2014-12-05 12:00:19 -08:00
Kiran Challa 00b61ec1e6 [Partial fix for #1372]Added SimpleTypesExcludeFilter to exlcude validation on simple types and also added tests to cover scenarios. 2014-12-03 14:09:51 -08:00
Harsh Gupta b54c326ee6 Updating Associated Metadata Provider to follow the existing pattern. 2014-11-26 16:56:32 -08:00
Ryan Nowak ff3282827a Fix a test based on the resolution of #1609
This old test (from WSR) was commented out pending the resolution of
issue #1609.

I've updated the test to track the current semantics.
2014-11-26 11:48:01 -08:00
Ajay Bhargav Baaskaran 9f1cb655f6 matched classnames with filenames 2014-11-25 11:21:17 -08:00
Victor Hurdugaci 99b5f430ff Add schema version to kproj files 2014-11-25 10:57:58 -08:00