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.
* Broken InputFormatter into InputFormatter and TextInputFormatter
* Added an exception to ModelState inside ReadAsync on TextInputFormatter
when we can't find a valid encoding to read the body.
- This bit was missed when changing the `ViewComponent` invocation pattern resulting in the inability to invoke `ViewComponent`s with arguments in a `Controller`.
#4004
Closes#4007, Fixes#3622, Fixes#3621
Squashed commit of the following:
commit 4b3095671d945ae79baa4fc4ba22a2ce5ebe488e
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 15:05:58 2016 -0800
PR Feedback #4007
ModelBindingContext.ModelType. Need similar changes a couple of
other places in this class.
commit 7c45847d1d4c3eb02c48710bb4f100d4d1305385
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 15:01:13 2016 -0800
PR Feedback #4007
Please clean out the now-extra added usings for System.Diagnostics.
commit 13263fb29a0a12b472eab130eafe6760f6279262
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 14:58:52 2016 -0800
PR Feedback #4007
Confusing to read: How can overallResult be non-null here?
commit dfb52e1bd48397580eacf87be3541b159dbe79f1
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 14:47:28 2016 -0800
PR Feedback #4007
End these new guys with a period.
commit f4c745a0a805b960234cd4d810378bc40b8e5c8c
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 14:44:10 2016 -0800
Fixing unit tests
Also fixes rebase error in CancellationTokenModelBinder
commit f3874cc27388552e863d99d8e6631a2901f8e000
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 13:01:02 2016 -0800
PR Feedback #4007
Remove commented-out code.
commit 44ec1a5a3bd4fdeb4d1c4de9f0b402ff0fd34ffe
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 12:22:04 2016 -0800
PR Feedback #4007
Why now public?
commit 9aa45eda42ec9b11b7e6b73a14e887f1be8cb130
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Mon Feb 1 12:18:19 2016 -0800
PR Feedback #4007
Leave out .Test
commit 58d32d809797d25cc9b5b4c0516ae9e5992fa66e
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 15:41:14 2016 -0800
PR Feedback #4007
By making this async, we've undone an optimization here.
Notice BindModelAync now has a state machine.
commit f7503228b77803b786c19e06e60f618f6f5e15c5
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 15:30:54 2016 -0800
PR Feedback #4007
Don't need extra line
commit cf26f3e5125792d6af0ca2afda672e241fe0e164
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 15:28:23 2016 -0800
PR Feedback #4007
No longer need most of the using System.Diagnostics additions
commit e90c40c4e4315462efc9ade1585e2e8c085588a4
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 15:12:50 2016 -0800
PR Feedback #4007
Suggest Microsoft.AspNetCore.Mvc.Internal.
commit 5360599e9c09ab97b8136977ee0917fd88f51f76
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 14:57:28 2016 -0800
PR Feedback #4007
Remove this line.
commit ce63edba51721412684a54886109e6b2225c6c99
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 14:14:02 2016 -0800
PR Feedback #4007
incorrect mentions of DefaultModelBindingContext in doc comments
commit bbc738ca2304243839e8d68615ff4bbf14f3279c
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 13:59:50 2016 -0800
PR Feedback #4007
Could we convert most of these setups to avoid the
"async but not await" mess?
commit 0827e6917481e3fafb2905a3fa93cf90afb9be40
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Fri Jan 29 11:02:00 2016 -0800
PR Feedback #4007
remove the file
commit 3dd0d10d7f16c94df5f6d34ecb5f2efda62bccd8
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 13:34:31 2016 -0800
Revert "PR Feedback"
This reverts commit 589d3e65d406b127a0b833d86c05ad4a8c5172c8.
It seems the assignment of these properties is not appropriate
in both cases.
commit c8a97ada63fa16ee7df6c165031bf15b1c23e8a2
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 12:37:18 2016 -0800
PR Feedback
DefaultModelBindingContext should not be in Abstractions
commit 5e3b6a1486283f45867830693d4fd23cc967f06f
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 12:35:28 2016 -0800
PR Feedback
Is it still needed and, if so, where does the problem lie?
commit 44635a75af05034863f0d4b80b2eb857d43766b2
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 11:06:26 2016 -0800
PR Feedback
* this is either supported (shouldn't assert) or not supported (should throw). I don't feel like these asserts add much value
* this isn't something that should throw
commit 648975cad14ac5e3738ea454c490ca221f650155
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:54:28 2016 -0800
PR Feedback
remove the other static constructors for Task<ModelBindingResult>
they don't have a purpose anymore
commit d0e15211530668ec21406121342715b0d0f606a6
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:51:24 2016 -0800
PR Feedback
the reason for the separation was to put the implementation somewhere else
commit 2caf88df7a37664db829d660cbb5266cf6871f2c
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:48:25 2016 -0800
PR Feedback
* coding standards...
* yea
* private readonly
commit 6c2c640611686a554a8c417a407fe169c45a690e
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:46:12 2016 -0800
PR Feedback
* disposable -> <see cref="ModelBindingContextDisposable"/>
* Fill in the blanks.
commit df07891c798627ac9c8fce6a7598d9386e979615
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:44:07 2016 -0800
PR Feedback
Value to assign to the ... for modelName and model as well.
commit 8e9ade7378577eddc0ba8e939deafe8d12781b8a
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 28 10:43:50 2016 -0800
PR Feedback
Should this just be an abstract class rather than an interface?
commit a66685e2470a84b0acbf4e797eff5010a1a066ab
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 23:47:44 2016 -0800
PR Feedback
Suggest resetting FallbackToEmptyPrefix for current context as part
of PushContext().
commit d85e66f59d24e0959652f1683cb94c4b513d75c0
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 23:34:42 2016 -0800
PR Feedback
Add a using for the Internal namespace.
commit bef09536f881d400f15a83b7788c828903679a38
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 23:27:30 2016 -0800
PR Feedback
needs lots of /// doc love and blank lines
commit 4173488112f2889d662d5a7c55f249aefa821c22
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 23:06:49 2016 -0800
PR Feedback
Temp file accidentally added. Oops.
commit 6790d6104d5bd72ce7eab270bfe9a360cacf74f2
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 23:04:40 2016 -0800
PR Feedback
please remove the else bits after returns
commit 8d077ee27109133d18c5cddfe3b9b6c6e9a40e0e
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 22:57:38 2016 -0800
PR Feedback
The code at one point matched the comment -- always returning
something other than NoResult. Likely the comment needs
to change.
commit 0ea6c2186212444f46c7a48394b86b14190a9026
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 22:50:02 2016 -0800
PR Feedback
Don't recall why this was virtual but why remove that?
commit 0b27f3e62df6836e6e8751967c47c6192c3eec9a
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 22:35:57 2016 -0800
PR Feedback
No need for this line; just asserted that Result is already null.
commit c85648bb680bdbdb33381cd1af91133d04d56592
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 22:34:26 2016 -0800
PR Feedback
Comment needs some love since NoResult is no more.
commit a606cf32386de9e4566a678b34a195cc0720211a
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 22:18:55 2016 -0800
PR Feedback
* Long enough to start wrapping this. Same for a few other properties
in this class.
* Why is this check debug-only?
* /// docs and some blank lines between members
commit 7efce5675a78350a4a7fde4b54fcb7886fe18252
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 20:29:50 2016 -0800
PR Feedback
Why not use the Task helper used elsewhere?
commit eb5fe6f95a463eb2f162f51649ffea57db87e286
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 20:28:31 2016 -0800
PR Feedback
Sort usings
commit df3bd00c4b59d2434e3a7be28e637d3c8008ae32
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 20:27:38 2016 -0800
PR Feedback
Dead code
commit fe7ec17fbb5209f2904f067ec1f91169ab05fb33
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 20:26:04 2016 -0800
PR Feedback
Putting internal back in place
commit 496f1f97ac48b2e95572dd6d463ced3366f8d36c
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 20:21:03 2016 -0800
PR Feedback
stylecop 13040: Move these to the top of the file.
commit cd003d0bca6516a907a0ae889d2e6130ff473b57
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Wed Jan 27 19:38:15 2016 -0800
Renames to asp.net core
commit e1cf523119084e35b70f11f67f64f651c39e1c8b
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Jan 21 21:21:44 2016 -0800
Removing NoResult and fixing tests
commit 5af6223a4d60b6c4139c1fc62ebf297ab0e5454f
Author: Louis DeJardin <lodejard@microsoft.com>
Date: Thu Dec 17 11:49:08 2015 -0800
Reducing ModelBindingContext allocations
This is a fix for the specific case reported in #3743 and also a few
related cases where the object being validated does not come from user
input.
Because the CancellationToken is bound using the 'empty prefix',
suppressing validation causes the validation system to suppress ALL keys
in the MSD. This will wipe out validation info for other, unrelated model
data. The same can occur for [FromServices], IFormCollection, IFormFile,
and HttpRequestMessage (anythere when MSD key == null and
SuppressValidation == true).
The other change here is related to the [FromBody]. We don't want to
create an entry in the model state for a 'valid' model with the empty
prefix. This can cause the system to miss validation errors. If you end up
in a situation where there's an entry with the empty prefix for an invalid
state, you won't accidentally miss validation errors.
- #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
* Add an UnsupportedContentType to the ModelState dictionary when no formatter can read the body.
* Add a filter to the pipeline that searches for that specific exception and transforms the response into 415.
This change removes a layer of abstraction. These validators now just do
what they do now without creating a bunch of intermediate objects.
ModelClientValidationRule has been removed, and client validations
manipulate the attributes collection of a tag directly.
* Moved instantiation of view components into DefaultViewComponentActivator
* Introduced IViewComponentFactory to handling setup of new view component instances.
* Added a release method on IViewComponentActivator for handling tear down of view
component instances.
* Added a Release method to IControllerActivator
* Changed Create in IControllerActivator to take in a ControllerActionContext
* Move the check to determine if a controller can be instantiated into the controller activator.
* Move logic for disposing controllers into the controller activator and make release on the
controller factory delegate into the activator.
* Changed release methods to take in a controller context.
- have one test muted at the moment in our CI
- add `Reset()` action to the service, enabling `// Arrange` to bring `Index()` content to a known state
- add a couple more tests to `TagHelperSampleTest` covering the new action and empty `Index()` list
nits:
- use `ViewData`, not `ViewBag`
These changes are aimed at significantly improving the performance of
MVC/Razor when a large amount of content is in play or a large number of
TagHelpers are used.
A few issues addressed:
- Buffer sync writes after a flush has occurred so that we can write them
asyncronously. The issue is that an IHtmlContent can only do sync
writes. This is very bad for Kestrel in general. Doing these writes
async is better for our overall perf, and the buffer that we use for it
is from the pool.
- 'Flatten' ViewBuffers when possible. A page with lots of TagHelpers can
end up renting a ViewBuffer and only write 2-3 things into it. When a
ViewBuffer sees another ViewBuffer we can either steal its pages, or
copy data out and 'return' its pages. This lets us use 3-4 buffers for a
large Razor page instead of hundreds.
- #3215
- add new accessor properties to `IModelBindingMessageProvider` and plumb them through
- use in `ModelStateDictionary` when handling a `FormatException` or `OverflowException`
- use in `ValidationHelpers` when handling a `ModelError` with `null` `ErrorMessage`
- add new `ModelExplorer` parameter to `IHtmlGenerator.GenerateValidationMessage()`
- plumb through to `ValidationHelpers.GetModelErrorMessageOrDefault()`
Started from work @kichalla did on the `kiran/movemessages-to-messageprovider` branch in #3775.
nits:
- use helper methods more consistently in `HtmlHelper<T>`; slightly improves error checking
- remove unused `Resources` class from `Microsoft.AspNet.Mvc`
- make `ValidationHelpers` class `public`; already in `.Internal` namespace
- split `GetUserErrorMessageOrDefault()` in two; rename to `GetModelErrorMessageOrDefault()`
- fix some #YOLO wrapping
- aspnet/Razor#643 part 2: react to aspnet/Razor#653
- change test calls and delegates to include new parameter
- add tests specifically of the new feature
- add tag helpers using new feature to `TagHelpersTest` functional test
- note `HtmlEncoder`s used elsewhere e.g. in other `RazorPage` instances are unaffected
- i.e. changing one `RazorPage.HtmlEncoder` property only affects C# expressions in that page
Also simplify scope management, removing bizarre assertion when user does something odd.
nits:
- correct `// Act` and `// Act & Assert` content
- remove #YOLO wrapping
- #3386
- initialize comparison `HashSet` with unencoded values to ensure both are checked
- address perf and correctness issues in this code
- `context.Items[typeof(SelectTagHelper)]` entry read as `ICollection` but written as `IReadOnlyCollection`
- `IReadOnlyCollection` worse because it does not include `Contains()`, causing Linq use
- every `<option>` element recalculated the encoded values and created a `HashSet` to contain them
- add `CurrentValues` type to cache this `HashSet` in `context.Items`
- each `OptionTagHelper` created the additional `HashSet` even if `Value` was bound
This change adds a list of ApiRequestFormat objects to ApiDescription
object which include the content type and formatter for each supported
content type which can be understood by the action.
Computation is aware of the [Consumes] attribute via the
IApiRequestMetadataProvider metadata interface, and aware of Input
Formatters via the new IApiRequestFormatMetadataProvider interface.
This algorithm is essentially the same as what we do for
produces/output-formatters. We iterate the filters and ask them what
content types they think are supported. Then we cross check that list with
the formatters, and ask them which from that list are supported. If no
[Consumes] filters are used, the formatters will include everything they
support by default.
This feature and data is only available when an action has a [FromBody]
parameter, which will naturally exclude actions that handle GET or DELETE
and don't process the body.
- Validated that each of `TagHelperSample.Web`s sites work properly.
- Found that the `ConditionalCommentTagHelper` page wasn't working as intended due to never being updated after `TagHelperContent` encoding changes.
- Added content verification for the `TagHelper/ConditionalComment` endpoint only since it's static HTML.
#3530
Calling Flush[Async]() on the writer will NOT flush the stream.
Calling Flush[Async]() in Razor will flush both the writer and the stream.
Our normal flow will be to flush the writer, but not the stream. This
avoids chunking, but allows us to do a WriteAsync on the stream as part of
the call to FlushAsync. This is done to avoid a synchronous write due to
Dispose calling Flush on the writer, which needs to call Write on the
stream.
See issue for extensive background.
Adds the concept of an IAntiforgeryPolicy marker interface as well as
the ability to overide policy with a 'closer' filter.
Adds a new [IgnoreAntiforgeryToken] attribute for overriding a scoped
antiforgery policy.
Adds a new [AutoValidateAntiforgeryToken] attribute (good name tbd) for
applying an application-wide antiforgery token. The idea is that you can
configure this as a global filter if your site is acting as a pure
browser-based or 1st party SPA. This new attribute only validates the
token for unsafe HTTP methods, so you can apply it broadly.
- Check MVC services once at startup
- Make action selector sync
We've never really had a scenario for the action selector being async, it
just ended up that way. None of our extensibility here lets you do
anything async without replacing it wholesale, which we don't
recommend.
This change avoids a state machine allocation and a dictionary allocation
on the common case (no bound properties). Ugly? You bet. Worth it? Yeah,
seems worthwhile.
This is worth about 200 bytes/request - about 3% of allocated bytes in a
smallish API scenario.
- Always prepend with application name and let underlying `IStringLocalizerFactory` do the name gymnastics
- Use ExecutingFilePath instead of view name
- Trim off the file extension (so your resource doesn't have to have ".cshtml" in its name)
- Improved doc comments
- Added tests to cover ViewLocalizer behavior
- #3718
- #2767
- IHtmlLocalizer no longer derives from IStringLocalizer
- IHtmlLocalizer indexer now returns LocalizedHtmlString
- IHtmlLocalizer has GetString methods now that act the same as IStringLocalizer.GetString
- Made LocalizedHtmlString a struct to match LocalizedString
- Updated samples in response to aspnet/Localization#167
- Rename "ancestor" to "parent" for loc API
- Fixes some doc comments
- Fixed tests
- #3716
- #3612 subpart 2 of 2
- merge `ActionConstraintsWebSite`, `AntiforgeryTokenWebSite` and `ContentNegotiationWebSite` into `BasicWebSite`
- remove tests depending on `ErrorReporterMiddleware` in merged sites; not used in `BasicWebSite`
- delete `CompositeViewEngineWebSite`, `Microsoft.AspNet.Mvc.ViewEngines.CompositeViewEngineTest` covers cases
- delete `CorsMiddlewareWebsite`, soon to be in Cors repo (see aspnet/CORS#57)
- remove `SendFileMiddleware` from FilesWebSite, unused there
This change adds a base class for controllers to Mvc.Core that can be used
without a dependency on views, json, etc.
Most of the functionality on Controller moves to ControllerBase. I kept
the IActionFilter and IDisposable functionality on Controller since it's
not really a fit with the 'minimal' philosophy.
- Removes IExcludeTypeFilter
- Replaced with a property 'ValidateChildren' on ModelMetadata
- Teach ValidationVisitor to respect 'ValidateChildren' for enumerable
types.
The accessor for ElementMetadata can sometimes return null when
concurrently accessed.
This change solves this issue and simplified a bunch of lazy-computed
properties, by precomputing all type-related facets of ModelMetadata.
This also adds a ElementType property to ModelMetadata to maintain
the current separation of concerns as ModelMetadata is unaware of the
metadata provider.
- #3122 and #3123 (5 of 5)
- avoid concatenating values and wrapping them in an `HtmlString`
- switch from `string.Format()` to `AppendHtml()` in `LinkTagHelper`
- simplify `RazorPage` and `TagHelperContentExtensions` e.g. don't use a `TagHelperContentWrapperTextWriter`
- add some special cases in `UrlResolutionTagHelper`
- add `TagBuilder` and `StringHtmlContent` special cases to avoid `StringWriter` use when value is an `HtmlString`
- move `HtmlTextWriter` optimizations a bit lower and add missing checks for that type
nits:
- correct comments that incorrectly mention `HtmlString`s
- update comments in `JavaScriptStringArrayEncoder`
- part of #3123 (4 of 5)
- `LocalizedHtmlString` should not subclass `HtmlString`; now implements `IHtmlContent`
nits:
- clean up a few doc comments
- remove duplicate tests reported while testing these fixes in VS
This change removes the IActionContextAccessor as a dependency of
UrlHelper, and shifts UrlHelper to use a factory pattern. Consumers of
IUrlHelper should create an instance using the factory when needed.
This is the last part of MVC that has a dependency on IActionContext
accessor. As part of this change we no longer register it by default, and
treat it as an optional component.
This change removes the dependency of TempData on the IHttpContextAccessor
by creating an ITempDataDictionaryFactory abstraction. In general, no one
will replace the factory, it's just indirection.
This allows us to drop our dependency on IHttpContextAccessor, and move it
to the functional tests where we specifically depend on it.
The bulk of code churn here is to update tests that use TempData.
This change resolves#3512 and #3636 by removing 'magic' link generation
and adding an extension method to add routes to areas correctly using the new
pattern. This is pretty much exactly the same as how MapWebApiRoute works.
For site authors, we recommend adding area-specific routes in a way that
includes a default AND constraint for the area. Put your most specific
(for link generation) routes FIRST.
Ex:
routes.MapRoute(
"Admin/{controller}/{action}/{id?}",
defaults: new { area = "Admin" },
constraints: new { area = "Admin" });
The bulk of the changes here are to tests that unwittingly relied on the
old behavior.
- Prior to this change we were using `Linq` throughout our `TagHelper`s which resulted excess allocations.
- Also went through our data structures and changed some from `Enumerable<T>` to `IList<T>` where we were just not exposing the more accessible types (list).
- Changed several locations of `foreach` to `for` to remove the enumerator allocation.
#3599
This change simplifies IFormatFilter's API and removes the dependency on
IActionContext accessor.
The old API for IFormatFilter required computing state based on the
current request as part of the constructor, which in turn implied the use
of a context accessor. This isn't really needed. I didn't preserve caching of
the 'format' as that seems like an early optimization.
This is a companion change to make the RouteValueDictionary type more
promient. Using the concrete type here allows to avoid allocations in a
lot of common scenarios.
- #3123 (3 of 5 or so)
- react to rest of aspnet/Antiforgery@6a9b38d
- remove `HtmlEncoder` from localization requirements
- literal `hidden` is no longer HTML encoded (was a no-op anyhow)
- #3571 and part of #3123
- split `ContentViewComponentResult` in two
- add `HtmlEncoder` to `ViewComponentContext`
- remove use of `WebUtility.HtmlEncode()` and `HtmlDecode()`
nits: remove unused `using`s in files I had open
- #3428
- the `public` setter was not useful when this class is used as an attribute
- make property `virtual` to support other override patterns
- update existing test to use both override patterns
This change introduces ControllerContext for inside of Controllers, and
controller-specific extensibility points. ControllerContext carries with
it the model binding infrastructure needed to do all of the things that
controllers need to do.
- Removed `WriteTagHelperAsync` methods from `RazorPage`.
- Moved `WriteTagHelperAsync` tests into Razor since `TagHelperOutput` is now an `IHtmlContent`.
- Updated code generation test files.
aspnet/Razor#358
- `true` has the opposite meaning now but most changes are due to new parameters names in `IViewEngine`
- use name names in `Microsoft.AspNet.Mvc.ViewFound` and not found events
- remove `IRazorPage.IsPartial` and `RazorView.IsPartial`
- remove `IsPartial` properties from `Microsoft.AspNet.Mvc.Razor.BeginInstrumentationContext` and end events
- add parameter checks to `RazorView` constructor; instances are not retrieved from DI
nits:
- remove unused `cacheKey` parameter from `RazorViewEngine.CreateCacheResult()`
- correct duplicate test names in `RazorPageTest`
- also `...OnPageExecutionListenerContext` -> `...OnPageExecutionContext`
- `IRazorViewEngine.MakePathAbsolute()` -> `GetAbsolutePath()`
- set `IsPartial` on all `IRazorPage` instances
- improve consistency of methods in `HtmlHelperPartialExtensions`
- a couple unnecessarily passed `htmlHelper.ViewData`
- add missing tests of these extension methods
- restore parameter checks in `CompositeViewEngine`
- reduce `List<string>` and remove enumerator allocations in `CompositeViewEngine`
nits:
- correct a few comments
- use `<seealso/>`
- do not blindly use `FindPage()` / `FindView()` result in `Exception.Message` or returned results
- failure scenarios involve new `Any()` calls but rarely additional `List<string>()` allocations
- change `ViewEngine_ViewNotFound` resource to be consistent with similar errors
- remove trailing period at end of searched locations list
nit: remove remaining `null` checks of `SearchedLocations` in not found cases; never `null` then
- #3307
- relative paths are now supported in `View()` calls from components and view components,
`Html.PartialAsync()` and similar calls, and `RazorPage.Layout` settings.
- support absolute paths, relative paths, and view location lookups consistently / everywhere
- support view paths in `TemplateRenderer` e.g. passing an absolute path to `Html.EditorFor()`
- take a big swing at the `IRazorViewEngine` and `IViewEngine` interfaces
- split lookups (view names) from navigation (view paths)
- remove `Partial` separation; use parameters to set `IsPartial` properties
- correct `ViewContext` copy constructor and add unit test
- extend unit tests to cover relative paths
- fix existing tests to handle newly-required extension in an absolute path
- add functional test that chains relative paths
nits:
- remove some YOLO line wrapping
- `""` -> `string.Empty`
- Prior to this change the `<meta ...>` generated had a name attribute. As an alternative we're using the `content` attribute in conjunction with the `name` attribute to ensure compliance.
#3449
- wrong fix especially now that test encoders work as expected
- touch up `HtmlHelperTest` and `RazorViewTest` since test encoders are now consistent
- remove references to old `Microsoft.Extensions.WebEncoders.Testing` package
This reverts commit a9d5876cd9.
- but leave `FormTagHelperTest` and `ValidationMessageTagHelperTest` cleanup alone
nit: use `string.Empty` in `HtmlHelperLinkGenerationTest`
- #3140
- clone `MediaTypeHeaderValue` instance before updating it when content negotiation succeeds
- avoids changes to `MediaTypeConstants` properties and `OutputFormatter.SupportedMediaTypes` entries
- `MediaTypeHeaderValue.Clone()` does not exist in our DNX Core fork of this class
- in previous implementation, was called defensively rather than when required
- update `WebApiCompatShimBasicTest` functional tests to use `MvcTestFixture<TStartup>` everywhere
- #3140 blocked that final migration
- remove `TestHelper` since it's no longer referenced
nits:
- remove comments mentioning `TestHelper`
- correct spelling of "negotiation"
- test class can now use the `MvcTestFixture`
- #3139 part 3 of 3
- dump instrumentation data at end of `_Layout.cshtml`
- include `FilePath` in display
- compare against new `.html` resource
nits:
- normalize line endings to CRLF for consistency with other tests
- add `InstrumentionData` to avoid `Tuple`
- make `TestPageExecutionContext` class `private`
- remove newly-unused actions and associated `.cshtml` files
- remove tests already thoroughly covered in unit tests
- #3139 part 2 of 3
- make checks of `<form>` tag helper more consistent with others
- use a tag helper initializer but testing every variant; covered in unit tests
- remove `MvcStartupTest` and associated web site
- scenario covered elsewhere
- remove `PrecompilationTest.PrecompiledView_RendersCorrectly()`
- scenario covered elsewhere and shouldn't do I/O on checked-in files
- use `MvcTestFixture` instead of `TestHelper`
- part of #3139
- continue to test e2e interaction of `FlushAsync()` with sections, partials, et cetera
- remove `FlushPointTest.FlushBeforeCallingLayout()`
- `RazorPageTest.FlushAsync_ThrowsIfTheLayoutHasBeenSet()` unit test covers the scenario
- Added functional tests to validate data created from a `SelectTagHelper` does not impact following `<select>` tags.
- Also moved the new `SelectTagHelper` communication flow into `TagHelper.Init`.
#3347
- #3227
- much of change is to tests, creating and passing `ModelMetadata`
- updated `InputFormatterContext` to make `ModelMetadata` available to `JsonInputFormatter`
- walk `ModelMetadata` tree to get information about property with an issue
- add missing `null` checks in `ModelStateDictionaryExtensions`
- Changed all `GetChildContentAsync` calls to come from `TagHelperOutput` instead of `TagHelperContext`.
- Updated `ReaderAtEndOfFormTagHelper` to properly detect changes inside of a `Form`s body by calling the `Init` method.
- Add test to `RenderAtEndOfFormTagHelperTest`.
aspnet/Razor#571
The missing piece here is is that StringOutputFormatter needs to set the
ContentType so that it gets overridden. The problem is that the formatter
is likely called with something like application/json, but decides to
write a string anyway. So because we're saying 'yes we can write' we also
need to override what we're writing.
This change rewrites simple and safe Expression<Func<T, U>> expressions
into accesses to readonly fields. This allows us to cache the actual
expression and avoid repeatedly allocating and compiling it.
The rewrite is limited to cases where we know that the expression doesn't
capture, and where we support that kind of expression for evaluating
viewdata. In practice this means 'indentity' and property accessors are
allowed.
- #2994
- Affects both HtmlHelper and TagHelper scenarios
- Checkboxes not enclosed in a form will generate inline hidden tags
- Added necessary properties to FormContext
- Added some functional and unit tests
- aspnet/Mvc#3138 part 2/2
- request's Content-Type header must be a subset of what an `IInputFormatter` can consume
- `[Consumes]` is similar
- what an `IOutputFormatter` produces must be a subset of the request's Accept header
- `FormatFilter` and `ObjectResult` are similar
- `ObjectResult` no longer falls back to `Content-Type` header if no `Accept` value is acceptable
- left `WebApiCompatShim` code alone for consistency with down-level `System.Net.Http.Formatting`
- correct tests to match new behaviour
- do not test `Accept` values containing a `charset` parameter; that case is not valid
WIP:
- four test failures; something about comparing media types w/ charset included
- why do some localization tests fail in VS?
nits:
- add `InputFormatterTests`
- add / update comments and doc comments
- correct xUnit attributes in `ActionResultTest`; odd it doesn't show up in command-line runs
- test `[FromServices]` for a defined type without a `BinderModelName`
- test `[FromServices]` for a service not available in DI
- test `[FromServices]` for `IEnumerable<TService>` properties
nit: correct name of `ServicesModelBinderTest` to match the model binder class
- Make ViewExecutor a service
- Add facades for ViewResult/PartialViewResult
- Add eventing for ViewFound/NotFound in PartialViewResult
- Add eventing around view execution
- Cleanup of some various eventing & our tests code
- #2969
- add `ModelBindingMessages` for configuration and `IBindingMetadataProvider` overrides
- use `interface` to avoid `new` oddities when adding a setter to an `abstract` property
- add `IModelBindingMessages` to `ModelMetadata` for use in rest of the product code
- plumb the various bits through the system
- add integration tests using a custom `IBindingMetadataProvider`s to override messages
nits:
- remove unused resources
- use `AttemptedValue` and not `model` in `SimpleTypeModelBinder`
- Added generic add model error and remove extensions for
ModelStateDictionary, to avoid using hard coded strings then specifying
model state dictionary keys.
- Added generic removal all extension for ModelStateDictionary, to
support removing all the model state keys for given expression.
aspnet/Mvc#3164
This solves a perf issue for views which produce content that is smaller
than the buffer size of HttpResponseStreamWriter. In this case, the writer
ends up synchronously writing to the Response as part of Dispose which
affects perf.
This change makes ViewComponentResult respect an existing Content-Type
setting on the HttpResponse. Code is very similar to the code in
ViewExector, and includes the same quirks.
Abstractions - Core MVC extensibility
Controllers - MVC implementations of .Abstractions and supporting
contracts
Infrastructure - General purpose support APIs. Metadata APIs that don't
fit clearly with a feature or with .Abstraction
We don't want these extensions methods defined in a wierd namespace, it's
straightforward and future-proof to just make these strongly-typed
collections.
- avoid warning when building Microsoft.AspNet.Mvc.FunctionalTests project
- now consistent w/ other web sites in this repo
- all but MvcMinimalSample.Web and that isn't used in functional tests
- #2722
- make communication of errors from formatters to `BodyModelBinder` explicit
- `JsonInputFormatter` now adds errors to `ModelStateDictionary` with correct key
- change `InputFormatter.SelectCharacterEncoding()` to add an error and return `null` when it fails
- one less `Exception` case and removes some duplicate code
nits:
- improve some doc comments (more `<inheritdoc/>`, `<paramref/>` and `<see/>`)
- add another two `BodyValidationIntegrationTests` tests
Improves authoring experience when using TagBuilder by taking advantage of
IHtmlContentBuilder an its extension methods.
TagBuilder.InnerHtml is no longer settable.
- #3066
- reduce `TestServer` -> `PhysicalFileProvider` -> `FileSystemWatcher` count enough to run with Core CLR on Linux
- remove use of `HttpClient.DefaultRequestHeaders`; any client change affects other tests
- remove use of `RequestBuilder` class; creates a per-test `HttpClient` and requires the `TestServer`
- updated a few expectations because `CommonTestEncoder` does JavaScript a bit differently
- "JavaScriptEncode[[...]]" -> "JavaScriptStringEncode[[...]]"
- side benefit: xUnit reports functional tests execute for only ~12.4s; was >30s before this change
Infrastructure: Enhance `MvcTestFixture`
- handle `ConfigureServices()` methods that are not `void`
- handle `Configure(IApplicationBuilder, ILoggerFactory)`
- ensure server is initialized with consistent `CurrentCulture` and `CurrentUICulture`
- add `FilteredDefaultAssemblyProviderFixture<TStartup>` and `MvcEncodedTestFixture<TStartup>`
- add `MvcTextFixture.AddAdditionalServices()` extension point supporting these
- do not expose the `TestServer`; an anti-pattern for tests to manipulate the server
- update class names to match containing files
- use existing `TestApplicationEnvironment`
- apply some `MvcTestFixture` improvements to the shared `TestApplicationEnvironment` class
- remove unused methods from `TestHelper`
nits:
- touched-up some leftover `_app` &c declarations to be more explicit and minimize `using`s
- moved statements into correct sections of methods in `RoutingTests`
- removed `TestLoggerFactory` and related classes from `TagHelperSampleTest`
- use `[ConditionalFact]` or `[ConditionalTheory]` instead
- in some cases test was already conditional
- move other `IsMono` checks into data sets where possible
- not reported as skipped but at least not counted as successful
nit: switch from `[ConditionalTheory]` to `[ConditionalFact]` as appropriate
- slightly more efficient since xUnit won't check for data
- use consistent line endings on all platforms so that hashes and file versions match
- add another `.gitattribute` file
- move files to avoid required index recreation in all Linux repos
Adds a new property, FieldName, to ModelBindingContext. The FieldName is
the name of whatever code-element is being bound, regardless of what
model-prefix is in use.
This is needed for cases like the Header model binder. We always want to
use the property/parameter name and we don't care about model prefixes.
- The corresponding Razor change results in `HelperResult`s being rendered with async lambdas.
- This change enables `TagHelper`s and other async code to exist inside of `HelperResult` blocks.
- Added test to validate Templates (they generate `HelperResult`s) can utilize `TagHelper`s correctly.
- Rename `RazorPage`s `RenderBodyDelegate` to `RenderBodyDelegateAsync`.
aspnet/Razor#494
- #2993
- use `ClosedGenericMatcher` to handle e.g. non-generic model types implementing requested interfaces
- reduce `IsAssignableFrom()` use since created binders use explicit casts i.e. handle explicit implementations
- also add more integration tests covering various collection key formats, some with validation errors
- merge a few `[Fact]`s into `[Theory]`s
- #2992
- use new properties to replace common helper methods
- still a few `Nullable.GetUnderlyingType()` calls
- creating `ModelMetadata` or sites lacking `ModelMetadata` access e.g. `ModelBindingHelper.ConvertTo()`
- #2941
- honor `ModelBindingResult.IsModelSet` and use `ModelBindingResult.ValidationNode`
- enable correct validation of collections or after model binding falls back to the empty prefix
- code previously matched `Controller.TryValidateModel()`; less context available in that case
- `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` now default to using `output.Attributes["href|src"]` if it's present when they run. This enables other `TagHelper`s to run prior and add those attributes.
- Added unit tests to validate this behavior.
- Updated `ImageTagHelper` functional test resources. Now that we're always defaulting to `output.Attributes["src"]` for `ImageTagHelper.Src` we're properly copying attributes back into the `output.Attributes` collection in the correct order (isntead of appending to the end).
#2902
- Updated implementation to do a best guess at copying an attribute back into `TagHelperOutput.Attributes`.
- Updated existing functional and unit tests to account for maintained attribute order.
- Added a set of complex order based unit tests to validate `CopyHtmlAttribute` properly maintains order.
#2639