diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs index 72f63cc851..7887f6d3a0 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Threading.Tasks; using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -15,39 +14,24 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// /// Creates a representing a failed model binding operation. /// - /// The key of the current model binding operation. /// A representing a failed model binding operation. - public static ModelBindingResult Failed(string key) + public static ModelBindingResult Failed() { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - return new ModelBindingResult(key, model: null, isModelSet: false); + return new ModelBindingResult(model: null, isModelSet: false); } /// /// Creates a representing a successful model binding operation. /// - /// The key of the current model binding operation. /// The model value. May be null. /// A representing a successful model bind. - public static ModelBindingResult Success( - string key, - object model) + public static ModelBindingResult Success(object model) { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - return new ModelBindingResult(key, model, isModelSet: true); + return new ModelBindingResult( model, isModelSet: true); } - private ModelBindingResult(string key, object model, bool isModelSet) + private ModelBindingResult(object model, bool isModelSet) { - Key = key; Model = model; IsModelSet = isModelSet; } @@ -57,16 +41,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public object Model { get; } - /// - /// - /// Gets the model name which was used to bind the model. - /// - /// - /// This property can be used during validation to add model state for a bound model. - /// - /// - public string Key { get; } - /// /// /// Gets a value indicating whether or not the value has been set. @@ -96,7 +70,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public override int GetHashCode() { var hashCodeCombiner = HashCodeCombiner.Start(); - hashCodeCombiner.Add(Key, StringComparer.OrdinalIgnoreCase); hashCodeCombiner.Add(IsModelSet); hashCodeCombiner.Add(Model); @@ -107,7 +80,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public bool Equals(ModelBindingResult other) { return - string.Equals(Key, other.Key, StringComparison.OrdinalIgnoreCase) && IsModelSet == other.IsModelSet && object.Equals(Model, other.Model); } @@ -115,17 +87,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public override string ToString() { - if (Key == null) + if (IsModelSet) { - return "No Result"; - } - else if (IsModelSet) - { - return $"Success {Key} -> '{Model}'"; + return $"Success '{Model}'"; } else { - return $"Failed {Key}"; + return $"Failed"; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerArgumentBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerArgumentBinder.cs index 3cf2cc1f52..12239046a2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerArgumentBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerArgumentBinder.cs @@ -194,7 +194,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _validator.Validate( controllerContext, modelBindingContext.ValidationState, - modelBindingResult.Value.Key, + modelBindingContext.ModelName, modelBindingResult.Value.Model); } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs index b6ee8319d9..3f78504e00 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs @@ -185,11 +185,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } set { - if (value.HasValue && value.Value == default(ModelBindingResult)) - { - throw new ArgumentException(nameof(ModelBindingResult)); - } - _state.Result = value; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs index 74e66212a7..52e5db1e7f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public Task BindModelAsync(ModelBindingContext bindingContext) { - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BinderTypeModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BinderTypeModelBinder.cs index 3aa7b7b5ac..1e39a0112a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BinderTypeModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BinderTypeModelBinder.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (bindingContext.Result == null) { - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs index 36de8bb856..51822782ad 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // This model binder is the only handler for the Body binding source and it cannot run twice. Always // tell the model binding system to skip other model binders and never to fall back i.e. indicate a // fatal error. - bindingContext.Result = ModelBindingResult.Failed(modelBindingKey); + bindingContext.Result = ModelBindingResult.Failed(); return; } @@ -109,11 +109,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { // Formatter encountered an error. Do not use the model it returned. As above, tell the model // binding system to skip other model binders and never to fall back. - bindingContext.Result = ModelBindingResult.Failed(modelBindingKey); + bindingContext.Result = ModelBindingResult.Failed(); return; } - bindingContext.Result = ModelBindingResult.Success(modelBindingKey, model); + bindingContext.Result = ModelBindingResult.Success(model); return; } catch (Exception ex) @@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // This model binder is the only handler for the Body binding source and it cannot run twice. Always // tell the model binding system to skip other model binders and never to fall back i.e. indicate a // fatal error. - bindingContext.Result = ModelBindingResult.Failed(modelBindingKey); + bindingContext.Result = ModelBindingResult.Failed(); return; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs index 3547582763..c3e4c25f3a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (valueProviderResult == ValueProviderResult.None) { - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } @@ -34,14 +34,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var value = valueProviderResult.FirstValue; if (string.IsNullOrEmpty(value)) { - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } try { var model = Convert.FromBase64String(value); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; } catch (Exception exception) @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Matched the type (byte[]) only this binder supports. As in missing data cases, always tell the model // binding system to skip other model binders i.e. return non-null. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CancellationTokenModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CancellationTokenModelBinder.cs index c76ce816cd..c61f837503 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CancellationTokenModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CancellationTokenModelBinder.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // DO NOT simplify this code by removing the cast. var model = (object)bindingContext.HttpContext.RequestAborted; bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true }); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs index 8194a58375..b9aa9544cb 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders model = CreateEmptyCollection(bindingContext.ModelType); } - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); } return; @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders valueProviderResult); } - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); } /// diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs index 1b55ddbf7c..896e7ad3a9 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs @@ -90,12 +90,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders model: propertyModel)) { await BindProperty(bindingContext); - result = bindingContext.Result ?? ModelBindingResult.Failed(modelName); + result = bindingContext.Result ?? ModelBindingResult.Failed(); } if (result.IsModelSet) { - SetProperty(bindingContext, property, result); + SetProperty(bindingContext, modelName, property, result); } else if (property.IsBindingRequired) { @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders } } - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, bindingContext.Model); + bindingContext.Result = ModelBindingResult.Success(bindingContext.Model); } /// @@ -335,10 +335,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders /// Updates a property in the current . /// /// The . + /// The model name. /// The for the property to set. /// The for the property's new value. protected virtual void SetProperty( ModelBindingContext bindingContext, + string modelName, ModelMetadata propertyMetadata, ModelBindingResult result) { @@ -347,6 +349,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders throw new ArgumentNullException(nameof(bindingContext)); } + if (modelName == null) + { + throw new ArgumentNullException(nameof(modelName)); + } + if (propertyMetadata == null) { throw new ArgumentNullException(nameof(propertyMetadata)); @@ -372,12 +379,13 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders } catch (Exception exception) { - AddModelError(exception, bindingContext, result); + AddModelError(exception, modelName, bindingContext, result); } } private static void AddModelError( Exception exception, + string modelName, ModelBindingContext bindingContext, ModelBindingResult result) { @@ -389,11 +397,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Do not add an error message if a binding error has already occurred for this property. var modelState = bindingContext.ModelState; - var modelStateKey = result.Key; - var validationState = modelState.GetFieldValidationState(modelStateKey); + var validationState = modelState.GetFieldValidationState(modelName); if (validationState == ModelValidationState.Unvalidated) { - modelState.AddModelError(modelStateKey, exception, bindingContext.ModelMetadata); + modelState.AddModelError(modelName, exception, bindingContext.ModelMetadata); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs index 2d93d5dadd..ce123c9276 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders model = new EmptyFormCollection(); } - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); } private class EmptyFormCollection : IFormCollection diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs index c68e22855e..a03c51cd0b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { // Silently fail and stop other model binders running if unable to create an instance or use the // current instance. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return; } @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (postedFiles.Count == 0) { // Silently fail if the named file does not exist in the request. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return; } @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders { // Silently fail if no files match. Will bind to an empty collection (treat empty as a success // case and not reach here) if binding to a top-level object. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return; } @@ -111,7 +111,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders rawValue: null, attemptedValue: null); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, value); + bindingContext.Result = ModelBindingResult.Success(value); } private async Task GetFormFilesAsync( diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs index 3a5364a672..81053db11f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Silently fail if unable to create an instance or use the current instance. Also reach here in the // typeof(string) case if the header does not exist in the request and in the // typeof(IEnumerable) case if the header does not exist and this is not a top-level object. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); } else { @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders request.Headers.GetCommaSeparatedValues(headerName), request.Headers[headerName]); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); } return TaskCache.CompletedTask; diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs index 273969fbdb..ba097606a7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs @@ -47,8 +47,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders throw new ArgumentNullException(nameof(bindingContext)); } - var keyResult = await TryBindStrongModel(bindingContext, _keyBinder, "Key"); - var valueResult = await TryBindStrongModel(bindingContext, _valueBinder, "Value"); + var keyModelName = ModelNames.CreatePropertyModelName(bindingContext.ModelName, "Key"); + var keyResult = await TryBindStrongModel(bindingContext, _keyBinder, "Key", keyModelName); + + var valueModelName = ModelNames.CreatePropertyModelName(bindingContext.ModelName, "Value"); + var valueResult = await TryBindStrongModel(bindingContext, _valueBinder, "Value", valueModelName); if (keyResult.IsModelSet && valueResult.IsModelSet) { @@ -56,31 +59,31 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders ModelBindingHelper.CastOrDefault(keyResult.Model), ModelBindingHelper.CastOrDefault(valueResult.Model)); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return; } if (!keyResult.IsModelSet && valueResult.IsModelSet) { bindingContext.ModelState.TryAddModelError( - keyResult.Key, + keyModelName, bindingContext.ModelMetadata.ModelBindingMessageProvider.MissingKeyOrValueAccessor()); // Were able to get some data for this model. // Always tell the model binding system to skip other model binders. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return; } if (keyResult.IsModelSet && !valueResult.IsModelSet) { bindingContext.ModelState.TryAddModelError( - valueResult.Key, + valueModelName, bindingContext.ModelMetadata.ModelBindingMessageProvider.MissingKeyOrValueAccessor()); // Were able to get some data for this model. // Always tell the model binding system to skip other model binders. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return; } @@ -89,17 +92,17 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (bindingContext.IsTopLevelObject) { var model = new KeyValuePair(); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); } } internal async Task TryBindStrongModel( ModelBindingContext bindingContext, IModelBinder binder, - string propertyName) + string propertyName, + string propertyModelName) { var propertyModelMetadata = bindingContext.ModelMetadata.Properties[propertyName]; - var propertyModelName = ModelNames.CreatePropertyModelName(bindingContext.ModelName, propertyName); using (bindingContext.EnterNestedScope( modelMetadata: propertyModelMetadata, @@ -116,7 +119,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders } else { - return ModelBindingResult.Failed(propertyModelName); + return ModelBindingResult.Failed(); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ServicesModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ServicesModelBinder.cs index a909d378c8..27f8cbf6e2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ServicesModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ServicesModelBinder.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true }); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs index 46a3394a14..5955f5c6f3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (valueProviderResult == ValueProviderResult.None) { // no entry - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } @@ -77,12 +77,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders bindingContext.ModelMetadata.ModelBindingMessageProvider.ValueMustNotBeNullAccessor( valueProviderResult.ToString())); - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } else { - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; } } @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Were able to find a converter for the type but conversion failed. // Tell the model binding system to skip other model binders. - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs index 758f0f4cfe..0bcbad5195 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs @@ -455,7 +455,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal objectModelValidator.Validate( actionContext, modelBindingContext.ValidationState, - modelBindingResult.Value.Key, + modelBindingContext.ModelName, modelBindingResult.Value.Model); return modelState.IsValid; diff --git a/src/Microsoft.AspNetCore.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs b/src/Microsoft.AspNetCore.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs index b7da750ae7..94d22b6fde 100644 --- a/src/Microsoft.AspNetCore.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs +++ b/src/Microsoft.AspNetCore.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.WebApiCompatShim { var model = bindingContext.HttpContext.GetHttpRequestMessage(); bindingContext.ValidationState.Add(model, new ValidationStateEntry() { SuppressValidation = true }); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerArgumentBinderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerArgumentBinderTests.cs index f0473c174a..d0b1b5a1ba 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerArgumentBinderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerArgumentBinderTests.cs @@ -103,7 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal .Callback((ModelBindingContext context) => { context.ModelMetadata = metadataProvider.GetMetadataForType(typeof(string)); - context.Result = ModelBindingResult.Success(string.Empty, value); + context.Result = ModelBindingResult.Success(value); }) .Returns(TaskCache.CompletedTask); var factory = GetModelBinderFactory(binder.Object); @@ -374,7 +374,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var controller = new TestController(); var arguments = new Dictionary(StringComparer.Ordinal); - var binder = new StubModelBinder(ModelBindingResult.Success(string.Empty, model: null)); + var binder = new StubModelBinder(ModelBindingResult.Success(model: null)); var factory = GetModelBinderFactory(binder); var argumentBinder = GetArgumentBinder(factory); @@ -406,7 +406,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var controller = new TestController(); var arguments = new Dictionary(StringComparer.Ordinal); - var binder = new StubModelBinder(ModelBindingResult.Success(key: string.Empty, model: null)); + var binder = new StubModelBinder(ModelBindingResult.Success(model: null)); var factory = GetModelBinderFactory(binder); var argumentBinder = GetArgumentBinder(factory); @@ -548,11 +548,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal object model; if (inputPropertyValues.TryGetValue(bindingContext.FieldName, out model)) { - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result = ModelBindingResult.Success( model); } else { - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); } }); @@ -605,7 +605,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal .Setup(b => b.BindModelAsync(It.IsAny())) .Returns(mbc => { - mbc.Result = ModelBindingResult.Success(string.Empty, model); + mbc.Result = ModelBindingResult.Success(model); return TaskCache.CompletedTask; }); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ArrayModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ArrayModelBinderTest.cs index 20799e6772..919c4d08cd 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ArrayModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ArrayModelBinderTest.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); var array = Assert.IsType(result.Model); Assert.Equal(new[] { 42, 84 }, array); @@ -59,10 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); - Assert.Empty(Assert.IsType(result.Model)); - Assert.Equal("modelName", result.Key); Assert.True(result.IsModelSet); } @@ -134,7 +131,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.Same(model, result.Model); @@ -153,7 +149,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (value != ValueProviderResult.None) { var model = value.ConvertTo(mbc.ModelType); - return ModelBindingResult.Success(mbc.ModelName, model); + return ModelBindingResult.Success(model); } return null; }); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/BinderTypeModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/BinderTypeModelBinderTest.cs index 70542b123c..bc1a9a45d4 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/BinderTypeModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/BinderTypeModelBinderTest.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; +using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.DependencyInjection; using Moq; @@ -26,7 +26,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binderResult = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), binderResult); Assert.False(binderResult.IsModelSet); } @@ -116,8 +115,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders public Task BindModelAsync(ModelBindingContext bindingContext) { - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, _model); - return Task.FromResult(0); + bindingContext.Result = ModelBindingResult.Success(_model); + return TaskCache.CompletedTask; } } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ByteArrayModelBinderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ByteArrayModelBinderTests.cs index d6c32f6ad8..5b9cf1de3c 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ByteArrayModelBinderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ByteArrayModelBinderTests.cs @@ -29,7 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Assert Assert.NotNull(binderResult); Assert.False(binderResult.IsModelSet); - Assert.Equal("foo", binderResult.Key); Assert.Null(binderResult.Model); var modelState = Assert.Single(bindingContext.ModelState); @@ -100,7 +99,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Assert Assert.NotNull(binderResult); Assert.False(binderResult.IsModelSet); - Assert.Equal("foo", binderResult.Key); Assert.Null(binderResult.Model); Assert.Empty(bindingContext.ModelState); // No submitted data for "foo". diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CancellationTokenModelBinderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CancellationTokenModelBinderTests.cs index 1c71bf0989..b3cf4e72db 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CancellationTokenModelBinderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CancellationTokenModelBinderTests.cs @@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.Equal(bindingContext.HttpContext.RequestAborted, result.Model); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CollectionModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CollectionModelBinderTest.cs index 6eacf77b2b..faf7d96b1c 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CollectionModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/CollectionModelBinderTest.cs @@ -84,7 +84,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); var list = Assert.IsAssignableFrom>(result.Model); @@ -116,7 +115,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.Same(list, result.Model); @@ -143,7 +141,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); var list = Assert.IsAssignableFrom>(result.Model); @@ -170,7 +167,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.Same(list, result.Model); @@ -192,7 +188,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.NotNull(result.Model); @@ -236,10 +231,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); - Assert.Empty(Assert.IsType>(result.Model)); - Assert.Equal("modelName", result.Key); Assert.True(result.IsModelSet); } @@ -269,11 +261,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); - Assert.Same(list, result.Model); Assert.Empty(list); - Assert.Equal("modelName", result.Key); Assert.True(result.IsModelSet); } @@ -343,7 +332,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var elementBinder = new StubModelBinder(mbc => { Assert.Equal("someName", mbc.ModelName); - mbc.Result = ModelBindingResult.Success(mbc.ModelName, 42); + mbc.Result = ModelBindingResult.Success(42); }); var modelBinder = new CollectionModelBinder(elementBinder); @@ -395,11 +384,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var model = value.ConvertTo(mbc.ModelType); if (model == null) { - return ModelBindingResult.Failed(mbc.ModelName); + return ModelBindingResult.Failed(); } else { - return ModelBindingResult.Success(mbc.ModelName, model); + return ModelBindingResult.Success(model); } }); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs index 2f6fae638d..3906221630 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ComplexTypeModelBinderTest.cs @@ -540,7 +540,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var bindingContext = CreateContext(GetMetadataForType(model.GetType()), model); var binder = CreateBinder(bindingContext.ModelMetadata); - binder.Results[property] = ModelBindingResult.Failed("theModel.Age"); + binder.Results[property] = ModelBindingResult.Failed(); // Act await binder.BindModelAsync(bindingContext); @@ -575,7 +575,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = CreateBinder(bindingContext.ModelMetadata); var property = GetMetadataForProperty(model.GetType(), nameof(ModelWithDataMemberIsRequired.Age)); - binder.Results[property] = ModelBindingResult.Failed("theModel.Age"); + binder.Results[property] = ModelBindingResult.Failed(); // Act await binder.BindModelAsync(bindingContext); @@ -612,7 +612,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Attempt to set non-Nullable property to null. BindRequiredAttribute should not be relevant in this // case because the property did have a result. var property = GetMetadataForProperty(model.GetType(), nameof(ModelWithBindRequired.Age)); - binder.Results[property] = ModelBindingResult.Success("theModel.Age", model: null); + binder.Results[property] = ModelBindingResult.Success(model: null); // Act await binder.BindModelAsync(bindingContext); @@ -642,7 +642,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = CreateBinder(bindingContext.ModelMetadata); var property = GetMetadataForProperty(model.GetType(), nameof(BindingOptionalProperty.ValueTypeRequired)); - binder.Results[property] = ModelBindingResult.Failed("theModel.ValueTypeRequired"); + binder.Results[property] = ModelBindingResult.Failed(); // Act await binder.BindModelAsync(bindingContext); @@ -662,7 +662,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = CreateBinder(bindingContext.ModelMetadata); var property = GetMetadataForProperty(model.GetType(), nameof(NullableValueTypeProperty.NullableValueType)); - binder.Results[property] = ModelBindingResult.Failed("theModel.NullableValueType"); + binder.Results[property] = ModelBindingResult.Failed(); // Act await binder.BindModelAsync(bindingContext); @@ -684,7 +684,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = CreateBinder(bindingContext.ModelMetadata); var property = GetMetadataForProperty(model.GetType(), nameof(Person.ValueTypeRequired)); - binder.Results[property] = ModelBindingResult.Failed("theModel." + nameof(Person.ValueTypeRequired)); + binder.Results[property] = ModelBindingResult.Failed(); // Act await binder.BindModelAsync(bindingContext); @@ -706,9 +706,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = CreateBinder(bindingContext.ModelMetadata); var property = GetMetadataForProperty(model.GetType(), nameof(Person.ValueTypeRequired)); - binder.Results[property] = ModelBindingResult.Success( - key: "theModel." + nameof(Person.ValueTypeRequired), - model: 57); + binder.Results[property] = ModelBindingResult.Success(model: 57); // Act await binder.BindModelAsync(bindingContext); @@ -736,18 +734,14 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders foreach (var property in containerMetadata.Properties) { - binder.Results[property] = ModelBindingResult.Failed(property.PropertyName); + binder.Results[property] = ModelBindingResult.Failed(); } var firstNameProperty = containerMetadata.Properties[nameof(model.FirstName)]; - binder.Results[firstNameProperty] = ModelBindingResult.Success( - nameof(model.FirstName), - "John"); + binder.Results[firstNameProperty] = ModelBindingResult.Success("John"); var lastNameProperty = containerMetadata.Properties[nameof(model.LastName)]; - binder.Results[lastNameProperty] = ModelBindingResult.Success( - nameof(model.LastName), - "Doe"); + binder.Results[lastNameProperty] = ModelBindingResult.Success("Doe"); // Act await binder.BindModelAsync(bindingContext); @@ -769,11 +763,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(typeof(Person)); var propertyMetadata = metadata.Properties[nameof(model.PropertyWithDefaultValue)]; - var result = ModelBindingResult.Failed("foo"); + var result = ModelBindingResult.Failed(); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert var person = Assert.IsType(bindingContext.Model); @@ -792,12 +786,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var propertyMetadata = metadata.Properties[nameof(model.PropertyWithInitializedValue)]; // The null model value won't be used because IsModelBound = false. - var result = ModelBindingResult.Failed("foo"); + var result = ModelBindingResult.Failed(); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert var person = Assert.IsType(bindingContext.Model); @@ -816,12 +810,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var propertyMetadata = metadata.Properties[nameof(model.PropertyWithInitializedValueAndDefault)]; // The null model value won't be used because IsModelBound = false. - var result = ModelBindingResult.Failed("foo"); + var result = ModelBindingResult.Failed(); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert var person = Assert.IsType(bindingContext.Model); @@ -839,11 +833,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(typeof(Person)); var propertyMetadata = metadata.Properties[nameof(model.NonUpdateableProperty)]; - var result = ModelBindingResult.Failed("foo"); + var result = ModelBindingResult.Failed(); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert // If didn't throw, success! @@ -882,14 +876,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(type); var propertyMetadata = bindingContext.ModelMetadata.Properties[propertyName]; - var result = ModelBindingResult.Success( - propertyName, - new Simple { Name = "Hanna" }); + var result = ModelBindingResult.Success(new Simple { Name = "Hanna" }); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, propertyName, propertyMetadata, result); // Assert Assert.Equal("Joe", propertyAccessor(model)); @@ -908,12 +900,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var propertyMetadata = GetMetadataForProperty(model.GetType(), nameof(CollectionContainer.ReadOnlyList)); var bindingContext = CreateContext(modelMetadata, model); - var result = ModelBindingResult.Success(propertyMetadata.PropertyName, new List() { "hi" }); + var result = ModelBindingResult.Success(new List() { "hi" }); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, propertyMetadata.PropertyName, propertyMetadata, result); // Assert Assert.Same(originalCollection, model.ReadOnlyList); @@ -930,11 +922,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(typeof(Person)); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.DateOfBirth)]; - var result = ModelBindingResult.Success("foo", new DateTime(2001, 1, 1)); + var result = ModelBindingResult.Success(new DateTime(2001, 1, 1)); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert Assert.True(bindingContext.ModelState.IsValid); @@ -956,11 +948,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(typeof(Person)); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.DateOfDeath)]; - var result = ModelBindingResult.Success("foo", new DateTime(1800, 1, 1)); + var result = ModelBindingResult.Success(new DateTime(1800, 1, 1)); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo", propertyMetadata, result); // Assert Assert.Equal("Date of death can't be before date of birth." + Environment.NewLine @@ -980,11 +972,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var metadata = GetMetadataForType(typeof(ModelWhosePropertySetterThrows)); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.NameNoAttribute)]; - var result = ModelBindingResult.Success("foo.NameNoAttribute", model: null); + var result = ModelBindingResult.Success(model: null); var binder = CreateBinder(bindingContext.ModelMetadata); // Act - binder.SetPropertyPublic(bindingContext, propertyMetadata, result); + binder.SetPropertyPublic(bindingContext, "foo.NameNoAttribute", propertyMetadata, result); // Assert Assert.False(bindingContext.ModelState.IsValid); @@ -1363,18 +1355,20 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders public virtual void SetPropertyPublic( ModelBindingContext bindingContext, + string modelName, ModelMetadata propertyMetadata, ModelBindingResult result) { - base.SetProperty(bindingContext, propertyMetadata, result); + base.SetProperty(bindingContext, modelName, propertyMetadata, result); } protected override void SetProperty( ModelBindingContext bindingContext, + string modelName, ModelMetadata propertyMetadata, ModelBindingResult result) { - SetPropertyPublic(bindingContext, propertyMetadata, result); + SetPropertyPublic(bindingContext, modelName, propertyMetadata, result); } } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/DictionaryModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/DictionaryModelBinderTest.cs index c7a2f789f5..271538253c 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/DictionaryModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/DictionaryModelBinderTest.cs @@ -150,7 +150,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders // Assert Assert.True(result.IsModelSet); - Assert.Equal(modelName, result.Key); var resultDictionary = Assert.IsAssignableFrom>(result.Model); Assert.Equal(dictionary, resultDictionary); @@ -186,9 +185,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); - Assert.Equal("prefix", result.Key); var resultDictionary = Assert.IsAssignableFrom>(result.Model); Assert.Empty(resultDictionary); @@ -238,9 +235,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); - Assert.Equal("prefix", result.Key); var resultDictionary = Assert.IsAssignableFrom>(result.Model); Assert.Equal(dictionary, resultDictionary); @@ -287,9 +282,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); - Assert.Equal("prefix", result.Key); var resultDictionary = Assert.IsAssignableFrom>(result.Model); Assert.Equal(dictionary, resultDictionary); @@ -335,9 +328,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); - Assert.Equal(modelName, result.Key); var resultDictionary = Assert.IsAssignableFrom>(result.Model); Assert.Equal(expectedDictionary, resultDictionary); @@ -366,10 +357,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); - Assert.Empty(Assert.IsType>(result.Model)); - Assert.Equal("modelName", result.Key); Assert.True(result.IsModelSet); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormCollectionModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormCollectionModelBinderTest.cs index 130173f095..3777c31b54 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormCollectionModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormCollectionModelBinderTest.cs @@ -32,9 +32,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); - Assert.Empty(bindingContext.ValidationState); var form = Assert.IsAssignableFrom(result.Model); @@ -55,7 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); var form = Assert.IsAssignableFrom(result.Model); Assert.Empty(form); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormFileModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormFileModelBinderTest.cs index cea8b9cbd1..fc2f3ad6c1 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormFileModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/FormFileModelBinderTest.cs @@ -29,7 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); var entry = bindingContext.ValidationState[result.Model]; @@ -51,7 +50,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); var entry = bindingContext.ValidationState[result.Model]; @@ -84,7 +82,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.IsAssignableFrom(destinationType, result.Model); Assert.Equal(formFiles, result.Model as IEnumerable); @@ -103,7 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); var file = Assert.IsAssignableFrom(result.Model); Assert.Equal("file1.txt", file.FileName); } @@ -121,7 +118,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } @@ -140,7 +136,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } @@ -167,7 +162,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); var file = Assert.IsAssignableFrom(result.Model); @@ -188,7 +182,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } @@ -207,7 +200,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } @@ -225,7 +217,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } @@ -243,7 +234,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); Assert.Null(result.Model); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs index f611191e3a..8a40349adb 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/HeaderModelBinderTests.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.False(result.IsModelSet); } [Fact] @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); Assert.Equal(headerValue.Split(','), result.Model); } @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); Assert.Equal(headerValue, result.Model); } @@ -95,7 +95,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.IsAssignableFrom(destinationType, result.Model); Assert.Equal(headerValue.Split(','), result.Model as IEnumerable); @@ -117,9 +116,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); - Assert.Equal("modelName", result.Key); Assert.Null(result.Model); } @@ -139,9 +136,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); - Assert.Equal("modelName", result.Key); Assert.Null(result.Model); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/KeyValuePairModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/KeyValuePairModelBinderTest.cs index 2e2864d0fc..aa9eafa776 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/KeyValuePairModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/KeyValuePairModelBinderTest.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.False(result.IsModelSet); Assert.Null(result.Model); Assert.False(bindingContext.ModelState.IsValid); Assert.Equal("someName", bindingContext.ModelName); @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.True(result.IsModelSet); Assert.Equal(new KeyValuePair(42, "some-value"), result.Model); } @@ -106,11 +106,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders ModelBindingResult? innerResult; if (isSuccess) { - innerResult = ModelBindingResult.Success("somename.Key", model); + innerResult = ModelBindingResult.Success(model); } else { - innerResult = ModelBindingResult.Failed("somename.Key"); + innerResult = ModelBindingResult.Failed(); } var innerBinder = new StubModelBinder(context => @@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var binder = new KeyValuePairModelBinder(innerBinder, innerBinder); // Act - var result = await binder.TryBindStrongModel(bindingContext, innerBinder, "Key"); + var result = await binder.TryBindStrongModel(bindingContext, innerBinder, "Key", "someName.Key"); // Assert Assert.Equal(innerResult.Value, result); @@ -155,11 +155,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(context); // Assert - Assert.NotEqual(default(ModelBindingResult), result); - var model = Assert.IsType>(result.Model); Assert.Equal(default(KeyValuePair), model); - Assert.Equal("modelName", result.Key); Assert.True(result.IsModelSet); } @@ -226,7 +223,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (mbc.ModelType == typeof(int) && success) { var model = 42; - return ModelBindingResult.Success(mbc.ModelName, model); + return ModelBindingResult.Success(model); } return null; }); @@ -240,7 +237,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders if (mbc.ModelType == typeof(string) && success) { var model = "some-value"; - return ModelBindingResult.Success(mbc.ModelName, model); + return ModelBindingResult.Success(model); } return null; }); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ServicesModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ServicesModelBinderTest.cs index f82b033a50..776356d5a3 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ServicesModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/ServicesModelBinderTest.cs @@ -25,10 +25,8 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(modelBindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.True(result.IsModelSet); Assert.NotNull(result.Model); - Assert.Equal("modelName", result.Key); var entry = modelBindingContext.ValidationState[result.Model]; Assert.True(entry.SuppressValidation); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/SimpleTypeModelBinderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/SimpleTypeModelBinderTest.cs index 1d1f2111cc..3e6965c673 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/SimpleTypeModelBinderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/Binders/SimpleTypeModelBinderTest.cs @@ -53,7 +53,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); Assert.False(result.IsModelSet); } @@ -104,7 +103,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.NotEqual(default(ModelBindingResult), result); + Assert.False(result.IsModelSet); Assert.Null(result.Model); Assert.False(bindingContext.ModelState.IsValid); var error = Assert.Single(bindingContext.ModelState["theModelName"].Errors); @@ -122,7 +121,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders var result = await binder.BindModelResultAsync(bindingContext); // Assert - Assert.Equal(ModelBindingResult.Failed("theModelName"), result); + Assert.Equal(ModelBindingResult.Failed(), result); Assert.Empty(bindingContext.ModelState); } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs index 2dbf983bac..8219609fab 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingHelperTest.cs @@ -11,11 +11,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.DataAnnotations; using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal; -using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Test; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Moq; using Xunit; @@ -31,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding return new TheoryData { null, - ModelBindingResult.Failed("someKey"), + ModelBindingResult.Failed(), }; } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs index 07998f9734..9fa90d53dc 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Threading.Tasks; using Xunit; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test @@ -12,14 +11,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test public void Success_SetsProperties() { // Arrange - var key = "someName"; var model = "some model"; // Act - var result = ModelBindingResult.Success(key, model); + var result = ModelBindingResult.Success(model); // Assert - Assert.Same(key, result.Key); Assert.True(result.IsModelSet); Assert.Same(model, result.Model); } @@ -27,14 +24,10 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Test [Fact] public void Failed_SetsProperties() { - // Arrange - var key = "someName"; - - // Act - var result = ModelBindingResult.Failed(key); + // Arrange & Act + var result = ModelBindingResult.Failed(); // Assert - Assert.Same(key, result.Key); Assert.False(result.IsModelSet); Assert.Null(result.Model); } diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs index bf09cc06a8..b051ca396d 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs @@ -181,8 +181,8 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert // ModelBindingResult + Assert.True(modelBindingResult.IsModelSet); Assert.Equal("Success", modelBindingResult.Model); - Assert.Equal("CustomParameter", modelBindingResult.Key); // ModelState Assert.True(modelState.IsValid); @@ -225,7 +225,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // ModelBindingResult Assert.True(modelBindingResult.IsModelSet); - Assert.Equal(string.Empty, modelBindingResult.Key); // Model var boundPerson = Assert.IsType(modelBindingResult.Model); @@ -264,7 +263,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Equal("CustomParameter", modelBindingResult.Key); + Assert.True(modelBindingResult.IsModelSet); // Model var boundPerson = Assert.IsType(modelBindingResult.Model); @@ -301,7 +300,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests new string[] { address.Street }, address.Street); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, address); + bindingContext.Result = ModelBindingResult.Success(address); return TaskCache.CompletedTask; } } @@ -322,7 +321,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests new string[] { model }, model); - bindingContext.Result =ModelBindingResult.Success(bindingContext.ModelName, model); + bindingContext.Result =ModelBindingResult.Success(model); return TaskCache.CompletedTask; } } @@ -337,7 +336,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests } Debug.Assert(bindingContext.Result == null); - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, model: null); + bindingContext.Result = ModelBindingResult.Success(model: null); return TaskCache.CompletedTask; } } @@ -352,7 +351,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests } Debug.Assert(bindingContext.Result == null); - bindingContext.Result = ModelBindingResult.Failed(bindingContext.ModelName); + bindingContext.Result = ModelBindingResult.Failed(); return TaskCache.CompletedTask; } } diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs index a5dd00d5ef..ee06975fbd 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs @@ -186,7 +186,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests return TaskCache.CompletedTask; } - bindingContext.Result = ModelBindingResult.Success(bindingContext.ModelName, new Address()); + bindingContext.Result = ModelBindingResult.Success(new Address()); return TaskCache.CompletedTask; } } diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs index 03de807248..a350b3ae77 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs @@ -51,7 +51,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert Assert.True(modelBindingResult.IsModelSet); - Assert.Equal("parameter", modelBindingResult.Key); var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Name); @@ -101,7 +100,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert Assert.True(modelBindingResult.IsModelSet); - Assert.Equal("parameter", modelBindingResult.Key); var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Name); @@ -141,7 +139,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert Assert.True(modelBindingResult.IsModelSet); - Assert.Equal(string.Empty, modelBindingResult.Key); var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Name); @@ -191,7 +188,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert Assert.True(modelBindingResult.IsModelSet); - Assert.Equal(string.Empty, modelBindingResult.Key); var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Name); @@ -238,7 +234,6 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert Assert.True(modelBindingResult.IsModelSet); - Assert.Equal(string.Empty, modelBindingResult.Key); var model = Assert.IsType(modelBindingResult.Model); Assert.Null(model.Name); diff --git a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs index 2ae49f3d0e..d67da2af89 100644 --- a/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs @@ -462,7 +462,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Equal(ModelBindingResult.Failed(string.Empty), modelBindingResult); + Assert.Equal(ModelBindingResult.Failed(), modelBindingResult); // ModelState Assert.True(modelState.IsValid);