Commit Graph

28 Commits

Author SHA1 Message Date
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
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
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
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 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
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 b54c326ee6 Updating Associated Metadata Provider to follow the existing pattern. 2014-11-26 16:56:32 -08:00
Doug Bunting 5e067cdb9e Delete trailing whitespace
- #EngineeringDay
- Total replaced: 660  Matching files: 270 in *.cs
- Total replaced: 250  Matching files: 32 in all other files
- Total replaced: 22  Matching files: 8 in a few stragglers

Did not change files under following directories
- test\Microsoft.AspNet.Mvc.Razor.Host.Test\TestFiles\Output
- test\Microsoft.AspNet.Mvc.FunctionalTests\compiler\resources
- test\WebSites\TagHelpersWebSite
(Razor generates trailing whitespace in a case or two)
2014-11-20 16:18:09 -08:00
Kirthi Krishnamraju a0629f4d23 Fix #298 - Added ModelMetadata.Container property and unit tests. 2014-11-20 15:45:02 -08:00
Doug Bunting 90e41b905a Add `ModelMetadata.HtmlEncode` property
- use new `ModelMetadata.HtmlEncode` property in HTML helpers
 - specifically in default HTML display and editor object templates (e.g.
   `@Html.DisplayFor()`) when value is non-`null` and the template is invoked
   with template depth greater than 1
- similar to MVC 5.2 commit [2b12791aee4f](https://aspnetwebstack.codeplex.com/SourceControl/changeset/2b12791aee4ffc56c7928b623bb45ee425813021)

nits:
- remove dupe `null` check in `DefaultDisplayTemplates.ObjectTemplate()`
- move backing fields initialized with constants together in `ModelMetadata`
2014-11-03 12:23:33 -08:00
David Fowler 34add2249e Updated to use the new target framework in project.json 2014-09-04 02:02:40 -07:00
jacalvar b6fb7ac7df Take advantage of nameof to improve our usage of MemberData across the code base.
Substituted all instances of [MemberData("PropertyName")] for [MemberData(nameof(PropertyName))]
This change enables us to take advantage of IDE features like Navigate to source,
find all references, etc. When using Visual Studio.
2014-09-02 13:53:03 -07:00
dougbu 98e23075dd Test `DisplayFormatString`, `EditFormatString`, and `HasNonDefaultEditFormat`
- `DisplayFormatString` and `EditFormatString` now based on attributes
- `HasNonDefaultEditFormat` is new
- confirm `DataType` and `ScaffoldColumn` in `CachedDataAnnotationsMetadataAttributes`
2014-08-20 10:07:55 -07:00
dougbu 1a4bd25e0f Add `[HiddenInput]`, `ModelMetadata.HideSurroundingHtml`, and `.Properties` tests
nits:
- add a few missing default `ModelMetadata` property value checks
- cleanup some redundancies in test data initializers
2014-08-15 12:33:58 -07:00
dougbu 3746e44dc3 Add more `ModelMetadata` and HTML helper tests
- add `CachedDataAnnotationsMetadataAttributesTest`
- add `CachedDataAnnotationsModelMetadataTest`
- confirm more default property values in `ModelMetadataTest`
- confirm use of `DisplayName` in `ModelMetadataTest`
- add `HtmlHelperDisplayNameExtensionsTest`
- add `HtmlHelperLabelExtensionsTest`
- add `HtmlHelperNameExtensionsTest`
2014-07-24 18:32:35 -07:00
sornaks 28516a0ae9 Changes to support DisplayColumn attribute. Updating the MvcSample as well to start using DisplayColumn attribute. Adding UnitTests for the same. 2014-06-10 16:45:55 -07:00
Pranav K 7396f58d99 Support ModelMetaData.IsRequired
* Update DataAnnotationsModelValidatorProvider to use ModelMetadata.IsRequired
* Adding tests and updating existing ones that didn't work with IsRequired

Fixes #533
2014-06-10 10:20:24 -07:00
Pranav K 97e06138ed Cleaning up StyleCop errors 2014-06-04 13:28:30 -07:00
Andrew Peters f13865dedc Updating copyright headers 2014-05-08 23:01:20 -07:00
anpete 8208cd6b2f Update file headers 2014-05-01 17:42:33 -07:00
sornaks d63d998e95 Introducing DisplayText, DisplayTextFor, Id, IdFor, IdForModel.
Fixing CachedDataAnnotationsModelMetadata to support NullDisplayText.
2014-04-30 10:23:25 -07:00
Pranav K a2cea18529 Replacing argument not null checks in ModelBinding with NotNullAttribute
* Removing not null guard tests in ModelBinding
2014-03-25 12:35:33 -07:00
dougbu 4bc7c36522 Merge two `TypeExtensions` classes into Common\TypeExtensions.cs
- add missing `[NotNull]` attributes
- remove now-unneeded usings for ...ModelBinding.Internal namespace

Also get ModelBinding test project working under CoreCLR
- create separate k10 and net45 folders under test in VS
- add `[InternalsVisibleTo]` to make `TypeExtensions` visible to test assembly
- correct tests' `CultureInfo` use to compile under CoreCLR
- ifdef out CoreCLR tests depending on Moq, ReadOnly, ...
- remove a couple of tests expecting TypeConverter to work
2014-03-19 09:53:40 -07:00
dougbu ed1b2ddcc3 Run unit tests during builds
- add "test" command
- use latest (forked) XUnit packages
  update package references
  [PropertyData] -> [MemberData]
  Xunit.Extensions -> Xunit or Xunit.SDK
  Moq now available for .NET 4.5 only
- delete a couple of unit tests checking for ArgumentNullException
- provide TestCommon classes in Razor and Razor.Host test projects
- make ReplaceCulture internal because it's a shared source
2014-03-17 16:28:25 -07:00
Pranav K b6c78de4ea Reintroduce model binding 2014-02-23 15:23:58 -08:00