Commit Graph

376 Commits

Author SHA1 Message Date
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 d8fc2d4009 Fix test failures
* Disable deps file generation in class library project. This workarounds known issue - https://github.com/dotnet/core-setup/issues/3726
* Update RazorProjectRouteModelProvider to not specify a trailing slash. This produces paths with a single slash as opposed to two slashes messing with route creation.
* React to Microsoft.AspNetCore.Mvc.Razor.Extensions.Reference that shows up in the deps file.
2018-04-15 16:31:41 -07:00
Doug Bunting cc5ae02b7d
Fix binding & validating dictionaries of non-simple types in jQuery requests
- #7423
- retry failed inner bindings with alternate syntax in `ModelStateDictionary`
  - use property syntax if first attempt tried index syntax and visa versa
- instantiate `ShortFormDictionaryValidationStrategy` with full `ModelState` keys
  - can now provide exact `ModelState` keys that `ModelStateDictionary` used in inner bindings
- normalize model names without a leading period in `JQueryKeyValuePairNormalizer`

nits:
- take a few VS suggestions
2018-04-14 10:41:00 -07:00
Kiran Challa e52933e4e3 Removed UrlTestEncoder references in tests
This is because with the following commit, Routing no longer depends on DI to get a UrlEncoder and always uses UrlEncoder.Default.
4184b2406d
2018-04-14 06:08:20 -07:00
Pranav K d995b0418a Allow BindPropertyAttribute to be specified on controller classes
Fixes #7350
2018-04-13 13:58:44 -07:00
John Luo c35030267c Update usage of TestSink 2018-04-13 10:21:41 -07:00
Pranav K e34b4e8335
Use DependencyContext.CompileLibraries to determine dependency graph (#7626)
* Use DependencyContext.CompileLibraries to determine dependency graph

Fixes https://github.com/aspnet/Mvc/issues/7617
2018-04-11 15:57:11 -07:00
Kiran Challa 62272ad56a Round off file result's LastModifiedDate to whole seconds for correct comparison with http header dates
[Fixes #7572] PhysicalFileResult does not respond 304 Not Modified
2018-04-11 06:43:50 -07:00
Pranav K ec31ff0c28
Throw if multiple Body bound parameters are discovered
Fixes #6963
2018-04-09 11:20:34 -07:00
Pranav K 5e019bd707
Add Microsoft.AspNetCore.All
Fixes https://github.com/aspnet/Mvc/issues/7605
2018-04-06 10:57:59 -07:00
Pranav K c515cece8e Use ModelMetadataProvider to infer BindingSource on application model 2018-04-02 09:48:49 -07:00
Kristian Hellang a16504b941 Added failing test for #7546 2018-04-02 09:48:49 -07:00
Ryan Nowak f20bf9ea02 Fix #7503 change to model name for IValidableObject
This change undoes a breaking change introduced by the 2.1 model
validation changes. Now an implementation of IValidableObject on a
top-level model will be called correctly with the 'empty' prefix instead
of the parameter name.

When fixing this we undid a workaround for another issue.

When validating a parameter that didn't bind we didn't correctly compute
the model name for 'fallback to empty prefix' cases.

(cherry picked from commit 7a1096a72b)
2018-03-29 21:35:59 -07:00
Ryan Nowak d360886b78 Fix #7558 infer [FromRoute] with parameter in ANY route
This changes the logic for when we infer [FromRoute] on an action
parameter from *ALL* to *ANY*.

This means that if a parameter occurs in any route on an ApiController,
we will treat it as [FromRoute]. We think this is the best decision
because it's less ambiguous. If a parameter appears in a route, it won't
be eligible to be bound from query. I think that's good.

If for some reason you want this kind of behavior (route or query) then
we suggest breaking up the actions. This isn't very documentation
friendly (swagger) so we don't suggest it.
2018-03-29 07:54:39 -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
Ryan Nowak c93c168df3 Add mapping service for action results
This allows the use of custom 'envelope' types like ActionResult<> with
a corresponding API Explorer implementation.

Basically this PR services to decouple a bunch of infrastructure from
ActionResult<>.
2018-03-27 17:13:41 -07:00
Kiran Challa 0c084fa28a [Fixes #7518] NullReferenceException thrown when Controller method uses Guid parameter default value 2018-03-27 05:22:20 -07:00
Doug Bunting 5e245da326
Add compatibility switch controlling parameter metadata and top-level validation
- #7413 part 1 of 2
- made all `ModelMetadataProvider` and `ObjectModelValidator`-specific code conditional
  - fortunately, `MvcOptions` easy to get; affected code is primarily `internal` or pub-`Internal`
  - remove unnecessary `ModelMetadataProvider` use in `ApiBehaviorApplicationModelProvider`
- run integration and functional tests with `CompatibilityVersion.Version_2_1`
  - functional test change depends on @javiercn's recent #7541 fix
  - remove test code now redundantly turning compatibility switches on

nits:
- correct spelling errors in `CompatibilitySwitch`
- take VS suggestions, mostly in test code
- rename methods in `ControllerBinderDelegateProviderTest` to match current API
- slightly refactor in `ApiBehaviorApplicationModelProvider`
2018-03-26 12:29:04 -07:00
Ryan Nowak 1ff5bdca79 Set model prefix for [ApiController]
Infers the 'empty' model prefix for complex types that are read from the value
providers. This gives us better defaults when using the parameter object
pattern with respect to swagger/API explorer.
2018-03-23 14:49:54 -07:00
Pranav K 1d6c09ab31 Make the use of Assembly.CodeBase more robust 2018-03-23 09:35:55 -07:00
Pranav K d6176ac7de ApplicationPartFactory: The works 2018-03-21 15:40:15 -07:00
Doug Bunting 390ebbb258
Do not bind `"[index]"` in `CollectionModelBinder` subsetting feature
- #7091
- add `IKeyRewriterValueProvider` to remove rewritten keys or value providers containing such keys
  - similar to `IBindingSourceValueProvider` except `CompositeValueProvider` keeps non-implementers around
- remove `after.Order == before.Order` special cases
  - a premature optimization that could lead to lost inner provider replacements
  - rework `EnumerableValueProviderTest` to ease test override in `CompositeValueProviderTest`
- add `EmptyValueProvider` fields to reduce `CompositeValueProvider` allocations

nits:
- remove Linq use in `CompositeValueProvider`
- do not create an unnecessary dictionary in `CompositeValueProvider.Filter(...)` methods
- accept VS suggestions, mostly pattern matching
2018-03-19 12:53:05 -07:00
Kiran Challa a0b1b15101 [Fixes #7412] AspNetCore 2.1 breaks integration with 3rd party validation libraries 2018-03-13 02:07:56 -07:00
Kiran Challa a952313f1c Added JQueryQueryStringValueProviderFactory and JQueryQueryStringValueProvider
[Fixes #6372] jQuery ajax request with complex data does not work with .net core 1.1 model bindings
2018-03-12 16:40:04 -07:00
Artak Mkrtchyan 7a13eb8b21 Addressed review feedback 2018-02-01 14:44:06 -08:00
Artak Mkrtchyan dea3eb7856 Not instantiating the RequestHeaders and not relying on TypedHeaders to parse AcceptCharset 2018-01-31 17:20:29 -08:00
Kiran Challa 0215740183 [Fixes #5859] Consider allowing binding header values to types other than string and string collections 2018-01-30 11:47:16 -08:00
Pranav K dbff416be6 Add support for running conventions on controller properties, Razor Page parameter and properties
Fixes #6935
2018-01-29 11:43:25 -08:00
Pranav K a74ef9dfd9 Error message for [ApiController] without attribute route needs to be better
Fixes #7277
2018-01-25 10:25:52 -08:00
Pranav K ebdb3c650a Smooth rough ApiBehavior edges
Fixes #7262
2018-01-22 09:53:21 -08:00
Javier Calvarro Nelson 1d6b02c1f5 [Fixes #7239] Add support for loading additional parts.
* Support loading parts through an assembly metadata attribute with a
  key of Microsoft.AspNetCore.Mvc.AdditionalReference and a value that
  describes the additional assembly to add to the list of parts and
  whether or not it should be added by default. The additional reference
  can only contain the file name of the assembly and it must be located
  side by side with the assembly where the additional reference is
  defined.
* Add an AdditionalAssemblyPart application parts to represent parts
  that are not part of the original application per se, like precompiled
  views.
* Update the ViewsFeatureProvider to search for razor views in the
  application part directly instead of trying to load the precompiled
  views assembly part.
2018-01-21 08:02:20 -08:00
John Luo 6751e3b7ca Discover assembly parts for Microsoft.AspnetCore.All 2018-01-17 13:20:09 -08:00
Jass Bagga 66c13ae5e5
Use weak comparison for If-None-Match header (#7237) 2018-01-12 12:40:51 -08:00
Ryan Nowak d342ebf8c8 Use compatibility switch for auth filters 2018-01-11 17:42:32 -08:00
Kiran Challa c922b0b90d Improving logging - model binding
Related to issue #6498: When enabling "Trace" logging for MVC loggers, I should be buried in log messages
2018-01-11 14:51:53 -08:00
Jass Bagga 9438a453b0
Do not serve response body for HEAD requests (#7230)
Addresses #7208
2018-01-11 12:19:43 -08:00
Doug Bunting 58026eacbd Correct a few model binding typos
- worst cases were incorrect references in doc comments
- also a few doc comments ended with `..` or `/`
- otherwise, address nits and take VS suggestions
2018-01-09 12:49:40 -08:00
Doug Bunting afc75a8296 Move `IHttpRequestStreamReaderFactory` from `.Internal` to `.Infrastructure`
- #7044
- move `IHttpResponseStreamWriterFactory` too
- add breaking change records e.g. for changes to `BodyModelBinder[Provider]` constructors
  - these changes relate to previously-"internal" constructors and one property

nits: take VS suggestions for changed files
2018-01-09 10:51:09 -08:00
Doug Bunting c9ac2e6c29 Add `DisplayMetadata.NullDisplayTextProvider` and similar properties
- #6730
- `DisplayFormatStringProvider`, `EditFormatStringProvider`

nits:
- use `<see langword="null"/>` more
- accept VS suggestions in changed files
2018-01-09 09:01:57 -08:00
Hao Kung 73bd09dc1c Add CombineAuthorizeFilters option 2018-01-08 11:59:30 -08:00
ASP.NET CI 2e73bab2a4 Move option for JSON errors to MvcJsonOptions
This was in the wrong place - JSON formatters have their own options
type already.

Moved the option to MvcJsonOptions and updated the naming + defaults to
reflect our plan.

Also did a bunch of general cleanup on these tests, which were a bit
sloppy.
2018-01-07 21:48:58 -08:00
Kiran Challa 40d027fca3 File results - logging 2018-01-04 23:49:13 -08:00
Ryan Nowak bf61ce2b8f Document compatiblity switch for input formatter exceptions 2018-01-03 11:23:05 -08:00
Ryan Nowak 64259fe51c Add skips for dotnet/standard#567
This issue causes problems with ValueTuple when used across assembly
boundaries between netstandard and net4X when net471 is installed. These
tests fail consistently in appveyor and will fail on any machine with
net471 installed.
2018-01-02 20:58:39 -08:00
Doug Bunting 5778f44bf7 Use `ExceptionDispatchInfo` in `MiddlewareFilterBuilder` if available
- #6596
- better-align this code with `ResourceInvoker.Rethrow()`

nits:
- take VS suggestions in `MiddlewareFilterBuilderTest`
- clean up names like `httpCtxt`
- remove unused `Pipeline2` class
2018-01-02 14:56:41 -08:00
Ryan Nowak 82e32240a4 Update the Enum Invalid Value setting for compat
Updated the naming to follow guidelines, and set the default for 2.0
apps to false. Note that I inverted the naming, which means that I had
to invert the logic in a few places.
2017-12-29 12:09:29 -08:00
Ryan Nowak 747420e5aa
Compatibility switches (#7142)
* [Design] Compatibility switches

This introduces a pattern for versioning breaking behaviour changes in
minor releases of MVC.

The general plan is that application developers choose a release version
(2.0, 2.1, Latest) as their baseline which determines the effective
'defaults' for some options. Anything the developer sets explicitly is
an override and always wins.

Then we add a version setting to the template to point to the current
release.

This allows us to be progressive with fixing issues and improving areas
that don't work well, but offers the developer some choice about when to
adopt new behaviours. In effect, we separate new behaviours from the
libraries that develiver them. Apps can update the version, and then opt
in to new behaviours as a separate change.

* Be more american

* improve docs, add example

* Fix visibility

* Fix broken test

* Add test

* Docs!

* The rest of the tests

* fix example

* Adding docs

* PR feedback
2017-12-28 09:43:24 -08:00
Pranav K dfa085afaf Add support for areas to Razor Pages
Fixes #6926
2017-12-19 15:03:05 -08:00
Kiran Challa c8cabde1f1 Improve logging - individual filters 2017-12-18 13:16:06 -08:00
Kiran Challa 4c4a7b3c6c Improve logging - filter pipeline execution
Related to issue #6498: When enabling "Trace" logging for MVC loggers, I should be buried in log messages
2017-12-14 11:22:13 -08:00