diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs index 8850f96c6c..9109142b0a 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs +++ b/src/Microsoft.AspNet.Mvc.Abstractions/ModelBinding/ModelBindingResult.cs @@ -1,47 +1,99 @@ // 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; +using System.Diagnostics; +using System.Threading.Tasks; +using Microsoft.Framework.Internal; + namespace Microsoft.AspNet.Mvc.ModelBinding { /// /// Contains the result of model binding. /// - public class ModelBindingResult + public struct ModelBindingResult : IEquatable { /// - /// Creates a new indicating a fatal error. + /// A representing the lack of a result. The model binding + /// system will continue to execute other model binders. /// - /// The key using which was used to attempt binding the model. - public ModelBindingResult(string key) + public static readonly ModelBindingResult NoResult = new ModelBindingResult(); + + /// + /// Returns a completed representing the lack of a result. The model + /// binding system will continue to execute other model binders. + /// + public static readonly Task NoResultAsync = Task.FromResult(NoResult); + + /// + /// 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([NotNull] string key) + { + return new ModelBindingResult(key, model: null, isModelSet: false, validationNode: null); + } + + /// + /// Creates a completed representing a failed model binding operation. + /// + /// The key of the current model binding operation. + /// A completed representing a failed model binding operation. + public static Task FailedAsync([NotNull] string key) + { + return Task.FromResult(Failed(key)); + } + + /// + /// Creates a representing a successful model binding operation. + /// + /// The key of the current model binding operation. + /// The model value. May be null. + /// The . May be null. + /// A representing a successful model bind. + public static ModelBindingResult Success( + [NotNull] string key, + object model, + ModelValidationNode validationNode) + { + return new ModelBindingResult(key, model, isModelSet: true, validationNode: validationNode); + } + + /// + /// Creates a completed representing a successful model binding + /// operation. + /// + /// The key of the current model binding operation. + /// The model value. May be null. + /// The . May be null. + /// A completed representing a successful model bind. + public static Task SuccessAsync( + [NotNull] string key, + object model, + ModelValidationNode validationNode) + { + return Task.FromResult(Success(key, model, validationNode)); + } + + /// + /// Creates a new using the provided + /// + /// The key of the current model binding operation. + /// The other to copy from. + public ModelBindingResult([NotNull] string key, ModelBindingResult other) { Key = key; + + Model = other.Model; + IsModelSet = other.IsModelSet; + ValidationNode = other.ValidationNode; } - /// - /// Creates a new . - /// - /// The model which was created by the . - /// The key using which was used to attempt binding the model. - /// A value that represents if the model has been set by the - /// . - public ModelBindingResult(object model, string key, bool isModelSet) - : this(model, key, isModelSet, validationNode: null) - { - } - - /// - /// Creates a new . - /// - /// The model which was created by the . - /// The key using which was used to attempt binding the model. - /// A value that represents if the model has been set by the - /// . - /// A which captures the validation information. - /// - public ModelBindingResult(object model, string key, bool isModelSet, ModelValidationNode validationNode) + private ModelBindingResult(string key, object model, bool isModelSet, ModelValidationNode validationNode) { + Key = key; Model = model; - Key = key; IsModelSet = isModelSet; ValidationNode = validationNode; } @@ -76,5 +128,60 @@ namespace Microsoft.AspNet.Mvc.ModelBinding /// A associated with the current . /// public ModelValidationNode ValidationNode { get; } + + /// + public override bool Equals(object obj) + { + var other = obj as ModelBindingResult?; + if (other == null) + { + return false; + } + else + { + return Equals(other.Value); + } + } + + /// + public override int GetHashCode() + { + var hash = HashCodeCombiner.Start(); + hash.Add(Key, StringComparer.OrdinalIgnoreCase); + hash.Add(IsModelSet); + hash.Add(Model); + return hash.CombinedHash; + } + + /// + public bool Equals(ModelBindingResult other) + { + return + string.Equals(Key, other.Key, StringComparison.OrdinalIgnoreCase) && + IsModelSet == other.IsModelSet && + object.Equals(Model, other.Model); + } + + /// + /// Compares objects for equality. + /// + /// A . + /// A . + /// true if the objects are equal, otherwise false. + public static bool operator ==(ModelBindingResult x, ModelBindingResult y) + { + return x.Equals(y); + } + + /// + /// Compares objects for inequality. + /// + /// A . + /// A . + /// true if the objects are not equal, otherwise false. + public static bool operator !=(ModelBindingResult x, ModelBindingResult y) + { + return !x.Equals(y); + } } } diff --git a/src/Microsoft.AspNet.Mvc.Abstractions/project.json b/src/Microsoft.AspNet.Mvc.Abstractions/project.json index f31e7850b9..8fb6eeb58f 100644 --- a/src/Microsoft.AspNet.Mvc.Abstractions/project.json +++ b/src/Microsoft.AspNet.Mvc.Abstractions/project.json @@ -10,12 +10,25 @@ }, "dependencies": { "Microsoft.AspNet.Routing": "1.0.0-*", - "Microsoft.Framework.CopyOnWriteDictionary.Sources": { "version": "1.0.0-*", "type": "build" }, - "Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" }, - "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" } + "Microsoft.Framework.CopyOnWriteDictionary.Sources": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.Framework.HashCodeCombiner.Sources": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.Framework.NotNullAttribute.Sources": { + "version": "1.0.0-*", + "type": "build" + }, + "Microsoft.Framework.PropertyHelper.Sources": { + "version": "1.0.0-*", + "type": "build" + } }, "frameworks": { - "dnx451": {}, + "dnx451": { }, "dnxcore50": { "dependencies": { "Microsoft.CSharp": "4.0.1-beta-*", diff --git a/src/Microsoft.AspNet.Mvc.Core/Actions/DefaultControllerActionArgumentBinder.cs b/src/Microsoft.AspNet.Mvc.Core/Actions/DefaultControllerActionArgumentBinder.cs index c48230e017..f2650cc20f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Actions/DefaultControllerActionArgumentBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Actions/DefaultControllerActionArgumentBinder.cs @@ -81,8 +81,7 @@ namespace Microsoft.AspNet.Mvc.Actions parameter.Name); var modelBindingResult = await operationContext.ModelBinder.BindModelAsync(modelBindingContext); - if (modelBindingResult != null && - modelBindingResult.IsModelSet && + if (modelBindingResult.IsModelSet && modelBindingResult.ValidationNode != null) { var modelExplorer = new ModelExplorer( @@ -180,7 +179,7 @@ namespace Microsoft.AspNet.Mvc.Actions foreach (var parameter in parameterMetadata) { var modelBindingResult = await BindModelAsync(parameter, modelState, operationContext); - if (modelBindingResult != null && modelBindingResult.IsModelSet) + if (modelBindingResult.IsModelSet) { arguments[parameter.Name] = modelBindingResult.Model; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs index 4843261a2a..61b5e69fdc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ArrayModelBinder.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { if (bindingContext.ModelMetadata.IsReadOnly) { - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } return base.BindModelAsync(bindingContext); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BinderTypeBasedModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BinderTypeBasedModelBinder.cs index cc458805ae..295d45b40f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BinderTypeBasedModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BinderTypeBasedModelBinder.cs @@ -25,9 +25,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { if (bindingContext.BinderType == null) { - // Return null so that we are able to continue with the default set of model binders, + // Return NoResult so that we are able to continue with the default set of model binders, // if there is no specific model binder provided. - return null; + return ModelBindingResult.NoResult; } var requestServices = bindingContext.OperationBindingContext.HttpContext.RequestServices; @@ -45,9 +45,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await modelBinder.BindModelAsync(bindingContext); - var modelBindingResult = result != null ? + var modelBindingResult = result != ModelBindingResult.NoResult ? result : - new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + ModelBindingResult.Failed(bindingContext.ModelName); // A model binder was specified by metadata and this binder handles all such cases. // Always tell the model binding system to skip other model binders i.e. return non-null. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceModelBinder.cs index 440a202002..bc2b464ef2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BindingSourceModelBinder.cs @@ -74,14 +74,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { // Binding Sources are opt-in. This model either didn't specify one or specified something // incompatible so let other binders run. - return null; + return ModelBindingResult.NoResult; } var result = await BindModelCoreAsync(context); - var modelBindingResult = result != null ? + var modelBindingResult = result != ModelBindingResult.NoResult ? result : - new ModelBindingResult(model: null, key: context.ModelName, isModelSet: false); + ModelBindingResult.Failed(context.ModelName); // This model binder is the only handler for its binding source. // Always tell the model binding system to skip other model binders i.e. return non-null. diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs index c29cc298be..68c9c9a065 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/BodyModelBinder.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // 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. - return new ModelBindingResult(modelBindingKey); + return ModelBindingResult.Failed(modelBindingKey); } try @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { // Formatter added 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. - return new ModelBindingResult(modelBindingKey); + return ModelBindingResult.Failed(modelBindingKey); } var validationNode = new ModelValidationNode(modelBindingKey, bindingContext.ModelMetadata, model) @@ -73,11 +73,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding ValidateAllProperties = true }; - return new ModelBindingResult( - model, - key: modelBindingKey, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(modelBindingKey, model, validationNode); } catch (Exception ex) { @@ -86,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // 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. - return new ModelBindingResult(modelBindingKey); + return ModelBindingResult.Failed(modelBindingKey); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs index c1cd683223..1348855f74 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ByteArrayModelBinder.cs @@ -23,14 +23,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Check if this binder applies. if (bindingContext.ModelType != typeof(byte[])) { - return null; + return ModelBindingResult.NoResult; } // Check for missing data case 1: There was no element containing this data. var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (valueProviderResult == ValueProviderResult.None) { - return new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + return ModelBindingResult.Failed(bindingContext.ModelName); } bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult); @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var value = valueProviderResult.FirstValue; if (string.IsNullOrEmpty(value)) { - return new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + return ModelBindingResult.Failed(bindingContext.ModelName); } try @@ -50,11 +50,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelMetadata, model); - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); } catch (Exception ex) { @@ -63,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // 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. - return new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + return ModelBindingResult.Failed(bindingContext.ModelName); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CancellationTokenModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CancellationTokenModelBinder.cs index 534bc53a20..0ebdb0ca7c 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CancellationTokenModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CancellationTokenModelBinder.cs @@ -23,14 +23,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding SuppressValidation = true, }; - return Task.FromResult(new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs index 60f6a6131e..2582f954d1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CollectionModelBinder.cs @@ -43,14 +43,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelMetadata, model); - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); } - return null; + return ModelBindingResult.NoResult; } var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); @@ -85,11 +81,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding valueProviderResult); } - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: result.ValidationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, result.ValidationNode); } /// diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs index 93b2cff5e8..1156585055 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/CompositeModelBinder.cs @@ -38,14 +38,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (newBindingContext == null) { // Unable to find a value provider for this binding source. Binding will fail. - return null; + return ModelBindingResult.NoResult; } var modelBindingResult = await RunModelBinders(newBindingContext); - if (modelBindingResult == null) + if (modelBindingResult == ModelBindingResult.NoResult) { // Unable to bind or something went wrong. - return null; + return ModelBindingResult.NoResult; } var bindingKey = bindingContext.ModelName; @@ -76,11 +76,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - return new ModelBindingResult( - modelBindingResult.Model, - bindingKey, - modelBindingResult.IsModelSet, - modelBindingResult.ValidationNode); + return new ModelBindingResult(bindingKey, modelBindingResult); } private async Task RunModelBinders(ModelBindingContext bindingContext) @@ -90,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding foreach (var binder in ModelBinders) { var result = await binder.BindModelAsync(bindingContext); - if (result != null) + if (result != ModelBindingResult.NoResult) { // This condition is necessary because the ModelState entry would never be validated if // caller fell back to the empty prefix, leading to an possibly-incorrect !IsValid. In most @@ -110,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } // Either we couldn't find a binder, or the binder couldn't bind. Distinction is not important. - return null; + return ModelBindingResult.NoResult; } private static ModelBindingContext CreateNewBindingContext(ModelBindingContext oldBindingContext) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs index 85f229eb71..28043fdcf6 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/DictionaryModelBinder.cs @@ -78,8 +78,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var valueResult = await modelBinder.BindModelAsync(valueBindingContext); // Always add an entry to the dictionary but validate only if binding was successful. - model[convertedKey] = ModelBindingHelper.CastOrDefault(valueResult?.Model); - if (valueResult != null && valueResult.IsModelSet) + model[convertedKey] = ModelBindingHelper.CastOrDefault(valueResult.Model); + if (valueResult.IsModelSet) { validationNode.ChildNodes.Add(valueResult.ValidationNode); } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs index 7135bd52d2..97d7ccc934 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormCollectionModelBinder.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { if (bindingContext.ModelType != typeof(IFormCollection)) { - return null; + return ModelBindingResult.NoResult; } object model; @@ -43,11 +43,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding SuppressValidation = true, }; - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); } private class EmptyFormCollection : IFormCollection diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs index 119147d89f..914678f710 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/FormFileModelBinder.cs @@ -36,13 +36,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding else { // This binder does not support the requested type. - return null; + return ModelBindingResult.NoResult; } - - ModelValidationNode validationNode = null; - if (value != null) + + if (value == null) { - validationNode = + return ModelBindingResult.Failed(bindingContext.ModelName); + } + else + { + var validationNode = new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, value) { SuppressValidation = true, @@ -52,13 +55,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelName, rawValue: null, attemptedValue: null); - } - return new ModelBindingResult( - value, - bindingContext.ModelName, - isModelSet: value != null, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, value, validationNode); + } } private async Task> GetFormFilesAsync(ModelBindingContext bindingContext) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/GenericModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/GenericModelBinder.cs index 7c8dcc2dbc..36cc3097a1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/GenericModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/GenericModelBinder.cs @@ -27,20 +27,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding !collectionBinder.CanCreateInstance(bindingContext.ModelType)) { // Able to resolve a binder type but need a new model instance and that binder cannot create it. - return null; + return ModelBindingResult.NoResult; } var result = await binder.BindModelAsync(bindingContext); - var modelBindingResult = result != null ? + var modelBindingResult = result != ModelBindingResult.NoResult ? result : - new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + ModelBindingResult.Failed(bindingContext.ModelName); // Were able to resolve a binder type. - // Always tell the model binding system to skip other model binders i.e. return non-null. + // Always tell the model binding system to skip other model binders. return modelBindingResult; } - return null; + return ModelBindingResult.NoResult; } private static Type ResolveBinderType(ModelBindingContext context) diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/HeaderModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/HeaderModelBinder.cs index 21cd423056..ec7d2deb64 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/HeaderModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/HeaderModelBinder.cs @@ -53,10 +53,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - ModelValidationNode validationNode = null; - if (model != null) + if (model == null) { - validationNode = new ModelValidationNode( + return ModelBindingResult.FailedAsync(bindingContext.ModelName); + } + else + { + var validationNode = new ModelValidationNode( bindingContext.ModelName, bindingContext.ModelMetadata, model); @@ -65,14 +68,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelName, request.Headers.GetCommaSeparatedValues(headerName), request.Headers[headerName]); - } - return Task.FromResult( - new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: model != null, - validationNode: validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode); + } } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/KeyValuePairModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/KeyValuePairModelBinder.cs index acaf075d0f..7d11b6eb28 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/KeyValuePairModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/KeyValuePairModelBinder.cs @@ -32,13 +32,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelMetadata, model, childNodes); - - // Success - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: modelValidationNode); + + return ModelBindingResult.Success(bindingContext.ModelName, model, modelValidationNode); } else if (!keyResult.IsModelSet && valueResult.IsModelSet) { @@ -47,8 +42,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding Resources.KeyValuePair_BothKeyAndValueMustBePresent); // Were able to get some data for this model. - // Always tell the model binding system to skip other model binders i.e. return non-null. - return new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + // Always tell the model binding system to skip other model binders. + return ModelBindingResult.Failed(bindingContext.ModelName); } else if (keyResult.IsModelSet && !valueResult.IsModelSet) { @@ -57,8 +52,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding Resources.KeyValuePair_BothKeyAndValueMustBePresent); // Were able to get some data for this model. - // Always tell the model binding system to skip other model binders i.e. return non-null. - return new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: false); + // Always tell the model binding system to skip other model binders. + return ModelBindingResult.Failed(bindingContext.ModelName); } else { @@ -73,14 +68,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelMetadata, model); - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); } - return null; + return ModelBindingResult.NoResult; } } @@ -102,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelBindingResult = await propertyBindingContext.OperationBindingContext.ModelBinder.BindModelAsync( propertyBindingContext); - if (modelBindingResult != null) + if (modelBindingResult != ModelBindingResult.NoResult) { if (modelBindingResult.ValidationNode != null) { @@ -112,8 +103,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding return modelBindingResult; } - // Always return a ModelBindingResult to avoid an NRE in BindModelAsync. - return new ModelBindingResult(model: default(TModel), key: propertyModelName, isModelSet: false); + return ModelBindingResult.Failed(propertyModelName); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs index 484c04d9d5..a662a7eb6e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/MutableObjectModelBinder.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding ModelBindingHelper.ValidateBindingContext(bindingContext); if (!CanBindType(bindingContext.ModelMetadata)) { - return null; + return ModelBindingResult.NoResult; } var mutableObjectBinderContext = new MutableObjectBinderContext() @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (!(CanCreateModel(mutableObjectBinderContext))) { - return null; + return ModelBindingResult.NoResult; } // Create model first (if necessary) to avoid reporting errors about properties when activation fails. @@ -54,11 +54,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.Model = model; ProcessResults(bindingContext, results, validationNode); - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); } /// @@ -301,10 +297,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding model: model); var result = await bindingContext.OperationBindingContext.ModelBinder.BindModelAsync(propertyContext); - if (result == null) + if (result == ModelBindingResult.NoResult) { // Could not bind. Let ProcessResult() know explicitly. - result = new ModelBindingResult(model: null, key: propertyContext.ModelName, isModelSet: false); + result = ModelBindingResult.Failed(propertyContext.ModelName); } results[propertyMetadata] = result; @@ -424,9 +420,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // exceptions as necessary. foreach (var entry in results) { - var result = entry.Value; - if (result != null) + if (entry.Value != ModelBindingResult.NoResult) { + var result = entry.Value; var propertyMetadata = entry.Key; SetProperty(bindingContext, modelExplorer, propertyMetadata, result); diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ServicesModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ServicesModelBinder.cs index 69d3ae1e1c..f0071b876d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ServicesModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/ServicesModelBinder.cs @@ -32,11 +32,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding SuppressValidation = true }; - return Task.FromResult(new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs index 6a96ec335c..89f1fd09de 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs @@ -19,14 +19,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding if (bindingContext.ModelMetadata.IsComplexType) { // this type cannot be converted - return null; + return ModelBindingResult.NoResult; } var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (valueProviderResult == ValueProviderResult.None) { // no entry - return null; + return ModelBindingResult.NoResult; } bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult); @@ -45,8 +45,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding } } - var isModelSet = true; - // When converting newModel a null value may indicate a failed conversion for an otherwise required // model (can't set a ValueType to null). This detects if a null model value is acceptable given the // current bindingContext. If not, an error is logged. @@ -56,31 +54,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding bindingContext.ModelName, Resources.FormatCommon_ValueNotValidForProperty(model)); - isModelSet = false; + return ModelBindingResult.Failed(bindingContext.ModelName); } + else + { + var validationNode = new ModelValidationNode( + bindingContext.ModelName, + bindingContext.ModelMetadata, + model); - // Include a ModelValidationNode if binding succeeded. - var validationNode = isModelSet ? - new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model) : - null; - - return new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet, - validationNode); + return ModelBindingResult.Success(bindingContext.ModelName, model, validationNode); + } } catch (Exception ex) { bindingContext.ModelState.TryAddModelError(bindingContext.ModelName, ex); - } - // Were able to find a converter for the type but conversion failed. - // Tell the model binding system to skip other model binders i.e. return non-null. - return new ModelBindingResult( - model: null, - key: bindingContext.ModelName, - isModelSet: false); + // Were able to find a converter for the type but conversion failed. + // Tell the model binding system to skip other model binders. + return ModelBindingResult.Failed(bindingContext.ModelName); + } } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBindingHelper.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBindingHelper.cs index efd271518f..321588a5ae 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBindingHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBindingHelper.cs @@ -308,7 +308,7 @@ namespace Microsoft.AspNet.Mvc modelBindingContext.PropertyFilter = predicate; var modelBindingResult = await modelBinder.BindModelAsync(modelBindingContext); - if (modelBindingResult != null && modelBindingResult.IsModelSet) + if (modelBindingResult.IsModelSet) { var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, modelBindingResult.Model); var modelValidationContext = new ModelValidationContext(modelBindingContext, modelExplorer); diff --git a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs index ef22afbae6..0c638352a2 100644 --- a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/HttpRequestMessage/HttpRequestMessageModelBinder.cs @@ -24,14 +24,10 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim SuppressValidation = true, }; - return Task.FromResult(new ModelBindingResult( - model, - bindingContext.ModelName, - isModelSet: true, - validationNode: validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionArgumentBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionArgumentBinderTests.cs index 73276d9bb8..15a09c1a24 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionArgumentBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionArgumentBinderTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Actions { Name = "foo", ParameterType = typeof(object), - BindingInfo = new BindingInfo(), + BindingInfo = new BindingInfo(), }); var actionContext = GetActionContext(actionDescriptor); @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(result: null)); + .Returns(ModelBindingResult.NoResultAsync); var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, @@ -61,13 +61,13 @@ namespace Microsoft.AspNet.Mvc.Actions { Name = "foo", ParameterType = typeof(object), - BindingInfo = new BindingInfo(), + BindingInfo = new BindingInfo(), }); var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(new ModelBindingResult(null, "", false))); + .Returns(ModelBindingResult.FailedAsync(string.Empty)); var actionContext = new ActionContext( new DefaultHttpContext(), @@ -101,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.Actions { Name = "foo", ParameterType = typeof(string), - BindingInfo = new BindingInfo(), + BindingInfo = new BindingInfo(), }); var value = "Hello world"; @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.Actions { context.ModelMetadata = metadataProvider.GetMetadataForType(typeof(string)); }) - .Returns(Task.FromResult(result: new ModelBindingResult(value, key: string.Empty, isModelSet: true))); + .Returns(ModelBindingResult.SuccessAsync(string.Empty, value, validationNode: null)); var actionContext = new ActionContext( new DefaultHttpContext(), @@ -178,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.Actions { Name = "foo", ParameterType = typeof(object), - BindingInfo = new BindingInfo(), + BindingInfo = new BindingInfo(), }); var actionContext = new ActionContext( @@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var actionBindingContext = new ActionBindingContext() { @@ -263,7 +263,7 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var actionBindingContext = new ActionBindingContext() { @@ -362,8 +362,8 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult( - result: new ModelBindingResult(model: null, key: string.Empty, isModelSet: isModelSet))); + .Returns(ModelBindingResult.SuccessAsync(string.Empty, model: null, validationNode: null)); + var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, @@ -400,8 +400,8 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder .Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult( - result: new ModelBindingResult(model: null, key: string.Empty, isModelSet: true))); + .Returns(ModelBindingResult.SuccessAsync(key: string.Empty, model: null, validationNode: null)); + var actionBindingContext = new ActionBindingContext() { ModelBinder = binder.Object, @@ -542,8 +542,14 @@ namespace Microsoft.AspNet.Mvc.Actions .Returns(bindingContext => { object model; - var isModelSet = inputPropertyValues.TryGetValue(bindingContext.ModelName, out model); - return Task.FromResult(new ModelBindingResult(model, bindingContext.ModelName, isModelSet)); + if (inputPropertyValues.TryGetValue(bindingContext.ModelName, out model)) + { + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode: null); + } + else + { + return ModelBindingResult.FailedAsync(bindingContext.ModelName); + } }); var actionBindingContext = new ActionBindingContext { @@ -564,10 +570,10 @@ namespace Microsoft.AspNet.Mvc.Actions private static ActionContext GetActionContext(ActionDescriptor descriptor = null) { - return new ActionContext( - new DefaultHttpContext(), - new RouteData(), - descriptor ?? GetActionDescriptor()); + return new ActionContext( + new DefaultHttpContext(), + new RouteData(), + descriptor ?? GetActionDescriptor()); } private static ActionDescriptor GetActionDescriptor() @@ -594,8 +600,7 @@ namespace Microsoft.AspNet.Mvc.Actions .Returns(mbc => { var validationNode = new ModelValidationNode(string.Empty, mbc.ModelMetadata, model); - return Task.FromResult( - result: new ModelBindingResult(model, string.Empty, isModelSet: true, validationNode: validationNode)); + return ModelBindingResult.SuccessAsync(string.Empty, model, validationNode: validationNode); }); return new ActionBindingContext() diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionInvokerTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionInvokerTest.cs index 1f73ddd3e3..3e2a838cf1 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionInvokerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Actions/ControllerActionInvokerTest.cs @@ -2078,7 +2078,7 @@ namespace Microsoft.AspNet.Mvc.Actions var binder = new Mock(); binder.Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(result: null)); + .Returns(ModelBindingResult.NoResultAsync); var context = new Mock(); context.SetupGet(c => c.Items) .Returns(new Dictionary()); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ArrayModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ArrayModelBinderTest.cs index 82f398c658..679ca5158d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ArrayModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ArrayModelBinderTest.cs @@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } public static TheoryData ArrayModelData @@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } // Here "fails silently" means the call does not update the array but also does not throw or set an error. @@ -173,9 +173,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test if (value != ValueProviderResult.None) { var model = value.ConvertTo(mbc.ModelType); - return Task.FromResult(new ModelBindingResult(model, key: null, isModelSet: true)); + return ModelBindingResult.SuccessAsync(mbc.ModelName, model, validationNode: null); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; }); return mockIntBinder.Object; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BinderTypeBasedModelBinderModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BinderTypeBasedModelBinderModelBinderTest.cs index abbd71fb18..d6bec3962e 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BinderTypeBasedModelBinderModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BinderTypeBasedModelBinderModelBinderTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test public class BinderTypeBasedModelBinderModelBinderTest { [Fact] - public async Task BindModel_ReturnsNull_IfNoBinderTypeIsSet() + public async Task BindModel_ReturnsNoResult_IfNoBinderTypeIsSet() { // Arrange var bindingContext = GetBindingContext(typeof(Person)); @@ -26,11 +26,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binderResult = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(binderResult); + Assert.Equal(ModelBindingResult.NoResult, binderResult); } [Fact] - public async Task BindModel_ReturnsNotNull_EvenIfSelectedBinderReturnsNull() + public async Task BindModel_ReturnsFailedResult_EvenIfSelectedBinderReturnsNull() { // Arrange var bindingContext = GetBindingContext(typeof(Person), binderType: typeof(NullModelBinder)); @@ -41,7 +41,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binderResult = await binder.BindModelAsync(bindingContext); // Assert - Assert.NotNull(binderResult); + Assert.NotEqual(ModelBindingResult.NoResult, binderResult); + Assert.False(binderResult.IsModelSet); } [Fact] @@ -125,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { public Task BindModelAsync(ModelBindingContext bindingContext) { - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } @@ -142,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { var validationNode = new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, _model); - return Task.FromResult(new ModelBindingResult(_model, bindingContext.ModelName, true, validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, _model, validationNode); } } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BindingSourceModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BindingSourceModelBinderTest.cs index 6bd764325f..5e5506bcfa 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BindingSourceModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BindingSourceModelBinderTest.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); Assert.False(binder.WasBindModelCoreCalled); } @@ -64,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); Assert.False(binder.WasBindModelCoreCalled); } @@ -111,8 +111,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding protected override Task BindModelCoreAsync([NotNull] ModelBindingContext bindingContext) { WasBindModelCoreCalled = true; - return Task.FromResult( - new ModelBindingResult(model: null, key: bindingContext.ModelName, isModelSet: _isModelSet)); + + if (_isModelSet) + { + return ModelBindingResult.SuccessAsync( + bindingContext.ModelName, + model: null, + validationNode: null); + } + else + { + return ModelBindingResult.FailedAsync(bindingContext.ModelName); + } } } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BodyModelBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BodyModelBinderTests.cs index 04499a1c7e..365bdb4f0d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BodyModelBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/BodyModelBinderTests.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var binderResult = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(binderResult); + Assert.Equal(ModelBindingResult.NoResult, binderResult); } [Fact] @@ -142,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var binderResult = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(binderResult); + Assert.Equal(ModelBindingResult.NoResult, binderResult); } [Fact] diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs index a5ce295316..61ccc99619 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ByteArrayModelBinderTests.cs @@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binderResult = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(binderResult); + Assert.Equal(ModelBindingResult.NoResult, binderResult); } private static ModelBindingContext GetBindingContext(IValueProvider valueProvider, Type modelType) diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CancellationTokenModelBinderTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CancellationTokenModelBinderTests.cs index 31555f0e95..1968405430 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CancellationTokenModelBinderTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CancellationTokenModelBinderTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } private static ModelBindingContext GetBindingContext(Type modelType) diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs index 65bcf56bfa..08a63695cf 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CollectionModelBinderTest.cs @@ -318,7 +318,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } // Model type -> can create instance. @@ -368,7 +368,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { Assert.Equal("someName", mbc.ModelName); childValidationNode = new ModelValidationNode("someName", mbc.ModelMetadata, mbc.Model); - return Task.FromResult(new ModelBindingResult(42, mbc.ModelName, true, childValidationNode)); + return ModelBindingResult.SuccessAsync(mbc.ModelName, 42, childValidationNode); }); var modelBinder = new CollectionModelBinder(); @@ -413,18 +413,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test .Returns((ModelBindingContext mbc) => { var value = mbc.ValueProvider.GetValue(mbc.ModelName); - if (value != ValueProviderResult.None) + if (value == ValueProviderResult.None) { - var model = value.ConvertTo(mbc.ModelType); - var modelValidationNode = new ModelValidationNode(mbc.ModelName, mbc.ModelMetadata, model); - return Task.FromResult(new ModelBindingResult( - model, - mbc.ModelName, - model != null, - modelValidationNode)); + return ModelBindingResult.NoResultAsync; } - return Task.FromResult(null); + var model = value.ConvertTo(mbc.ModelType); + if (model == null) + { + return ModelBindingResult.FailedAsync(mbc.ModelName); + } + else + { + var validationNode = new ModelValidationNode(mbc.ModelName, mbc.ModelMetadata, model); + return ModelBindingResult.SuccessAsync(mbc.ModelName, model, validationNode); + } }); return mockIntBinder.Object; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs index 9fb43421fc..c854226bf7 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/CompositeModelBinderTest.cs @@ -40,9 +40,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test Assert.Equal("someName", context.ModelName); Assert.Same(bindingContext.ValueProvider, context.ValueProvider); - - return Task.FromResult( - new ModelBindingResult(model: 42, key: "someName", isModelSet: true)); + return ModelBindingResult.SuccessAsync("someName", 42, validationNode: null); }); var shimBinder = CreateCompositeBinder(mockIntBinder.Object); @@ -83,14 +81,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { if (!string.IsNullOrEmpty(mbc.ModelName)) { - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } Assert.Same(bindingContext.ModelMetadata, mbc.ModelMetadata); Assert.Equal("", mbc.ModelName); Assert.Same(bindingContext.ValueProvider, mbc.ValueProvider); - return Task.FromResult(new ModelBindingResult(expectedModel, string.Empty, true)); + return ModelBindingResult.SuccessAsync(string.Empty, expectedModel, validationNode: null); }); var shimBinder = CreateCompositeBinder(mockIntBinder.Object); @@ -125,7 +123,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var modelBinder = new Mock(); modelBinder .Setup(mb => mb.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(new ModelBindingResult(model: null, key: "someName", isModelSet: false))); + .Returns(ModelBindingResult.FailedAsync("someName")); var composite = CreateCompositeBinder(modelBinder.Object); @@ -133,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await composite.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } [Fact] @@ -160,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { Assert.Equal("someName", context.ModelName); }) - .Returns(Task.FromResult(new ModelBindingResult(model: null, key: "someName", isModelSet: false))) + .Returns(ModelBindingResult.FailedAsync("someName")) .Verifiable(); var composite = CreateCompositeBinder(modelBinder.Object); @@ -195,7 +193,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test Assert.Equal("someName", context.ModelName); context.ModelState.AddModelError(context.ModelName, "this is an error message"); }) - .Returns(Task.FromResult(new ModelBindingResult(model: null, key: "someName", isModelSet: false))) + .Returns(ModelBindingResult.FailedAsync("someName")) .Verifiable(); var composite = CreateCompositeBinder(modelBinder.Object); @@ -225,7 +223,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var modelBinder = new Mock(); modelBinder .Setup(mb => mb.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(new ModelBindingResult(model: null, key: "someName", isModelSet: true))); + .Returns(ModelBindingResult.SuccessAsync("someName", model: null, validationNode: null)); var composite = CreateCompositeBinder(modelBinder.Object); @@ -245,7 +243,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test // Arrange var mockListBinder = new Mock(); mockListBinder.Setup(o => o.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var shimBinder = mockListBinder.Object; @@ -261,7 +259,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await shimBinder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); Assert.True(bindingContext.ModelState.IsValid); mockListBinder.Verify(); } @@ -286,7 +284,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await shimBinder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } [Fact] @@ -378,12 +376,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var mockBinder = new Mock(); mockBinder .Setup(o => o.BindModelAsync(It.IsAny())) - .Returns( - delegate (ModelBindingContext context) - { - return Task.FromResult( - new ModelBindingResult(model: 42, key: "someName", isModelSet: false)); - }); + .Returns((ModelBindingContext context) => + { + return ModelBindingResult.FailedAsync("someName"); + }); + var binder = CreateCompositeBinder(mockBinder.Object); var bindingContext = CreateBindingContext(binder, valueProvider, typeof(SimplePropertiesModel)); @@ -391,7 +388,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } [Fact] @@ -401,7 +398,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var mockBinder = new Mock(); mockBinder .Setup(o => o.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var binder = CreateCompositeBinder(mockBinder.Object); var valueProvider = new SimpleValueProvider(); var bindingContext = CreateBindingContext(binder, valueProvider, typeof(SimplePropertiesModel)); @@ -410,7 +407,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } [Fact] @@ -423,13 +420,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var mockBinder = new Mock(); mockBinder .Setup(o => o.BindModelAsync(It.IsAny())) - .Returns( - delegate (ModelBindingContext context) - { - validationNode = new ModelValidationNode("someName", context.ModelMetadata, 42); - return Task.FromResult( - new ModelBindingResult(42, "someName", isModelSet: true, validationNode: validationNode)); - }); + .Returns((ModelBindingContext context) => + { + validationNode = new ModelValidationNode("someName", context.ModelMetadata, 42); + return ModelBindingResult.SuccessAsync("someName", 42, validationNode); + }); + var binder = CreateCompositeBinder(mockBinder.Object); var bindingContext = CreateBindingContext(binder, valueProvider, typeof(SimplePropertiesModel)); @@ -485,7 +481,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test return shimBinder; } - private class SimplePropertiesModel { public string FirstName { get; set; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs index 658826e1d3..3d5c5e3a02 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/DictionaryModelBinderTest.cs @@ -358,7 +358,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } // Model type -> can create instance. @@ -462,11 +462,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test KeyValuePair value; if (values.TryGetValue(mbc.ModelName, out value)) { - return Task.FromResult(new ModelBindingResult(value, mbc.ModelName, isModelSet: true)); + return ModelBindingResult.SuccessAsync(mbc.ModelName, value, validationNode: null); } else { - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } }); diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/FormCollectionModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/FormCollectionModelBinderTest.cs index bae7867255..a8ebba9d5d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/FormCollectionModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/FormCollectionModelBinderTest.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } // We only support IFormCollection here. Using the concrete type won't work. @@ -83,7 +83,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } [Fact] diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs index 1fa38234cb..81cb5d6917 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/KeyValuePairModelBinderTest.cs @@ -52,7 +52,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.NotNull(result); Assert.Null(result.Model); Assert.False(bindingContext.ModelState.IsValid); Assert.Null(result.ValidationNode); @@ -70,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var bindingContext = GetBindingContext(valueProvider); var mockBinder = new Mock(); mockBinder.Setup(o => o.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); bindingContext.OperationBindingContext.ModelBinder = mockBinder.Object; var binder = new KeyValuePairModelBinder(); @@ -79,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); Assert.True(bindingContext.ModelState.IsValid); Assert.Equal(0, bindingContext.ModelState.ErrorCount); } @@ -118,14 +117,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test [Theory] [InlineData(null, false)] [InlineData(null, true)] - [InlineData(42, false)] [InlineData(42, true)] - public async Task TryBindStrongModel_InnerBinderReturnsNotNull_ReturnsInnerBinderResult( + public async Task TryBindStrongModel_InnerBinderReturnsAResult_ReturnsInnerBinderResult( object model, - bool isModelSet) + bool isSuccess) { // Arrange - var innerResult = new ModelBindingResult(model, key: string.Empty, isModelSet: isModelSet); + ModelBindingResult innerResult; + if (isSuccess) + { + innerResult = ModelBindingResult.Success(string.Empty, model, validationNode: null); + } + else + { + innerResult = ModelBindingResult.Failed(string.Empty); + } + var innerBinder = new Mock(); innerBinder .Setup(o => o.BindModelAsync(It.IsAny())) @@ -143,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.TryBindStrongModel(bindingContext, "key", modelValidationNodeList); // Assert - Assert.Same(innerResult, result); + Assert.Equal(innerResult, result); Assert.Empty(bindingContext.ModelState); } @@ -201,7 +208,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var result = await binder.BindModelAsync(context); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } private static ModelBindingContext CreateContext() @@ -252,9 +259,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { var model = 42; var validationNode = new ModelValidationNode(mbc.ModelName, mbc.ModelMetadata, model); - return Task.FromResult(new ModelBindingResult(model, mbc.ModelName, true, validationNode)); + return ModelBindingResult.SuccessAsync(mbc.ModelName, model, validationNode); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; }); return mockIntBinder.Object; } @@ -270,9 +277,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { var model = "some-value"; var validationNode = new ModelValidationNode(mbc.ModelName, mbc.ModelMetadata, model); - return Task.FromResult(new ModelBindingResult(model, mbc.ModelName, true, validationNode)); + return ModelBindingResult.SuccessAsync(mbc.ModelName, model, validationNode); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; }); return mockStringBinder.Object; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs index fecafe5ba7..6ea79193d8 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/ModelBindingResultTest.cs @@ -1,6 +1,8 @@ // 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 Moq; using Xunit; namespace Microsoft.AspNet.Mvc.ModelBinding.Test @@ -8,20 +10,97 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test public class ModelBindingResultTest { [Fact] - public void Constructor_SetsProperties() + public void Success_SetsProperties() { // Arrange + var key = "someName"; + var model = "some model"; + var validationNode = new ModelValidationNode(key, null, model); // Act - var result = new ModelBindingResult( - "some string", - isModelSet: true, - key: "someName"); + var result = ModelBindingResult.Success(key, model, validationNode); // Assert - Assert.Equal("some string", result.Model); + Assert.Same(key, result.Key); Assert.True(result.IsModelSet); - Assert.Equal("someName", result.Key); + Assert.Same(model, result.Model); + Assert.Same(validationNode, result.ValidationNode); + } + + [Fact] + public async Task SuccessAsync_SetsProperties() + { + // Arrange + var key = "someName"; + var model = "some model"; + var validationNode = new ModelValidationNode(key, null, model); + + // Act + var result = await ModelBindingResult.SuccessAsync(key, model, validationNode); + + // Assert + Assert.Same(key, result.Key); + Assert.True(result.IsModelSet); + Assert.Same(model, result.Model); + Assert.Same(validationNode, result.ValidationNode); + } + + [Fact] + public void Failed_SetsProperties() + { + // Arrange + var key = "someName"; + + // Act + var result = ModelBindingResult.Failed(key); + + // Assert + Assert.Same(key, result.Key); + Assert.False(result.IsModelSet); + Assert.Null(result.Model); + Assert.Null(result.ValidationNode); + } + + [Fact] + public async Task FailedAsync_SetsProperties() + { + // Arrange + var key = "someName"; + + // Act + var result = await ModelBindingResult.FailedAsync(key); + + // Assert + Assert.Same(key, result.Key); + Assert.False(result.IsModelSet); + Assert.Null(result.Model); + Assert.Null(result.ValidationNode); + } + + [Fact] + public void NoResult_SetsProperties() + { + // Arrange & Act + var result = ModelBindingResult.NoResult; + + // Assert + Assert.Null(result.Key); + Assert.False(result.IsModelSet); + Assert.Null(result.Model); + Assert.Null(result.ValidationNode); + } + + [Fact] + public async Task NoResultAsync_SetsProperties() + { + // Arrange & Act + var result = await ModelBindingResult.NoResultAsync; + + // Assert + Assert.Null(result.Key); + Assert.False(result.IsModelSet); + Assert.Null(result.Model); + Assert.Null(result.ValidationNode); } } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs index 279c9d3c8f..d80f29afb1 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs @@ -253,7 +253,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding [InlineData(typeof(TypeWithUnmarkedAndBinderMetadataMarkedProperties), false)] [InlineData(typeof(TypeWithUnmarkedAndBinderMetadataMarkedProperties), true)] public void CanCreateModel_CreatesModelForValueProviderBasedBinderMetadatas_IfAValueProviderProvidesValue( - Type modelType, + Type modelType, bool valueProviderProvidesValue) { var mockValueProvider = new Mock(); @@ -407,7 +407,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var mockBinder = new Mock(); mockBinder .Setup(o => o.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var bindingContext = new ModelBindingContext { @@ -457,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var mockBinder = new Mock(); mockBinder .Setup(o => o.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var bindingContext = new ModelBindingContext { @@ -784,9 +784,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var nameProperty = containerMetadata.Properties[nameof(model.Name)]; - results[nameProperty] = new ModelBindingResult("John Doe", isModelSet: true, key: string.Empty); + results[nameProperty] = ModelBindingResult.Success(string.Empty, "John Doe", validationNode: null); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); var testableBinder = new TestableMutableObjectModelBinder(); @@ -835,9 +835,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var nameProperty = containerMetadata.Properties[nameof(model.Name)]; - results[nameProperty] = new ModelBindingResult("John Doe", isModelSet: true, key: string.Empty); + results[nameProperty] = ModelBindingResult.Success(string.Empty, "John Doe", validationNode: null); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); var testableBinder = new TestableMutableObjectModelBinder(); @@ -886,14 +886,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var propertyMetadata = containerMetadata.Properties[nameof(model.Name)]; - results[propertyMetadata] = new ModelBindingResult("John Doe", isModelSet: true, key: "theModel.Name"); + results[propertyMetadata] = ModelBindingResult.Success("theModel.Name", "John Doe", validationNode: null); // Attempt to set non-Nullable property to null. BindRequiredAttribute should not be relevant in this // case because the binding exists. propertyMetadata = containerMetadata.Properties[nameof(model.Age)]; - results[propertyMetadata] = new ModelBindingResult(model: null, isModelSet: true, key: "theModel.Age"); + results[propertyMetadata] = ModelBindingResult.Success("theModel.Age", model: null, validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -926,7 +926,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -949,7 +949,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -974,7 +974,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); // The [DefaultValue] on ValueTypeRequiredWithDefaultValue is ignored by model binding. @@ -982,17 +982,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding // Make ValueTypeRequired invalid. var propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequired)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(Person.ValueTypeRequired), model: null, - isModelSet: true, - key: "theModel." + nameof(Person.ValueTypeRequired)); + validationNode: null); // Make ValueTypeRequiredWithDefaultValue invalid propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequiredWithDefaultValue)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue), model: null, - isModelSet: true, - key: "theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue)); + validationNode: null); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -1044,21 +1044,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); // Make ValueTypeRequired invalid. var propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequired)]; - results[propertyMetadata] = new ModelBindingResult( - model: null, - isModelSet: false, - key: "theModel." + nameof(Person.ValueTypeRequired)); + results[propertyMetadata] = ModelBindingResult.Failed("theModel." + nameof(Person.ValueTypeRequired)); // Make ValueTypeRequiredWithDefaultValue invalid propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequiredWithDefaultValue)]; - results[propertyMetadata] = new ModelBindingResult( - model: null, - isModelSet: false, + results[propertyMetadata] = ModelBindingResult.Failed( key: "theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue)); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -1082,28 +1077,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); // Make ValueTypeRequired valid. var propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequired)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(Person.ValueTypeRequired), model: 41, - isModelSet: true, - key: "theModel." + nameof(Person.ValueTypeRequired)); + validationNode: null); // Make ValueTypeRequiredWithDefaultValue valid. propertyMetadata = containerMetadata.Properties[nameof(Person.ValueTypeRequiredWithDefaultValue)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue), model: 57, - isModelSet: true, - key: "theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue)); + validationNode: null); // Also remind ProcessResults about PropertyWithDefaultValue -- as BindPropertiesAsync() would. propertyMetadata = containerMetadata.Properties[nameof(Person.PropertyWithDefaultValue)]; - results[propertyMetadata] = new ModelBindingResult( - model: null, - isModelSet: false, + results[propertyMetadata] = ModelBindingResult.Failed( key: "theModel." + nameof(Person.PropertyWithDefaultValue)); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -1133,24 +1126,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); // Make ValueTypeProperty not have a value. var propertyMetadata = containerMetadata .Properties[nameof(ModelWithBindRequiredAndRequiredAttribute.ValueTypeProperty)]; - results[propertyMetadata] = new ModelBindingResult( - model: null, - isModelSet: false, + results[propertyMetadata] = ModelBindingResult.Failed( key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ValueTypeProperty)); // Make ReferenceTypeProperty have a value. propertyMetadata = containerMetadata .Properties[nameof(ModelWithBindRequiredAndRequiredAttribute.ReferenceTypeProperty)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ReferenceTypeProperty), model: "value", - isModelSet: true, - key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ReferenceTypeProperty)); + validationNode: null); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -1186,23 +1177,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var testableBinder = new TestableMutableObjectModelBinder(); // Make ValueTypeProperty have a value. var propertyMetadata = containerMetadata .Properties[nameof(ModelWithBindRequiredAndRequiredAttribute.ValueTypeProperty)]; - results[propertyMetadata] = new ModelBindingResult( + results[propertyMetadata] = ModelBindingResult.Success( + key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ValueTypeProperty), model: 17, - isModelSet: true, - key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ValueTypeProperty)); + validationNode: null); // Make ReferenceTypeProperty not have a value. propertyMetadata = containerMetadata .Properties[nameof(ModelWithBindRequiredAndRequiredAttribute.ReferenceTypeProperty)]; - results[propertyMetadata] = new ModelBindingResult( - model: null, - isModelSet: false, + results[propertyMetadata] = ModelBindingResult.Failed( key: "theModel." + nameof(ModelWithBindRequiredAndRequiredAttribute.ReferenceTypeProperty)); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); @@ -1241,19 +1230,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var bindingContext = CreateContext(containerMetadata, model); var results = containerMetadata.Properties.ToDictionary( property => property, - property => new ModelBindingResult(model: null, key: property.PropertyName, isModelSet: false)); + property => ModelBindingResult.Failed(property.PropertyName)); var firstNameProperty = containerMetadata.Properties[nameof(model.FirstName)]; - results[firstNameProperty] = new ModelBindingResult( - model: "John", - isModelSet: true, - key: nameof(model.FirstName)); + results[firstNameProperty] = ModelBindingResult.Success( + nameof(model.FirstName), + "John", + validationNode: null); var lastNameProperty = containerMetadata.Properties[nameof(model.LastName)]; - results[lastNameProperty] = new ModelBindingResult( - model: "Doe", - isModelSet: true, - key: nameof(model.LastName)); + results[lastNameProperty] = ModelBindingResult.Success( + nameof(model.LastName), + "Doe", + validationNode: null); var modelValidationNode = new ModelValidationNode(string.Empty, containerMetadata, model); var testableBinder = new TestableMutableObjectModelBinder(); @@ -1310,7 +1299,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.PropertyWithDefaultValue)]; - var result = new ModelBindingResult(model: null, isModelSet: false, key: "foo"); + var result = ModelBindingResult.Failed("foo"); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1333,8 +1322,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.PropertyWithInitializedValue)]; - // This value won't be used because IsModelBound = false. - var result = new ModelBindingResult(model: "bad-value", isModelSet: false, key: "foo"); + // The null model value won't be used because IsModelBound = false. + var result = ModelBindingResult.Failed("foo"); var testableBinder = new TestableMutableObjectModelBinder(); @@ -1359,8 +1348,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.PropertyWithInitializedValueAndDefault)]; - // This value won't be used because IsModelBound = false. - var result = new ModelBindingResult(model: "bad-value", isModelSet: false, key: "foo"); + // The null model value won't be used because IsModelBound = false. + var result = ModelBindingResult.Failed("foo"); var testableBinder = new TestableMutableObjectModelBinder(); @@ -1384,7 +1373,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.NonUpdateableProperty)]; - var result = new ModelBindingResult(model: null, isModelSet: false, key: "foo"); + var result = ModelBindingResult.Failed("foo"); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1429,10 +1418,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(type, model); var propertyMetadata = bindingContext.ModelMetadata.Properties[propertyName]; - var result = new ModelBindingResult( - model: new Simple { Name = "Hanna" }, - isModelSet: true, - key: propertyName); + var result = ModelBindingResult.Success( + propertyName, + new Simple { Name = "Hanna" }, + validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); @@ -1507,7 +1496,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(type, model); var propertyMetadata = bindingContext.ModelMetadata.Properties[propertyName]; - var result = new ModelBindingResult(model: collection, isModelSet: true, key: propertyName); + var result = ModelBindingResult.Success(propertyName, collection, validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1530,7 +1519,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.DateOfBirth)]; - var result = new ModelBindingResult(new DateTime(2001, 1, 1), key: "foo", isModelSet: true); + var result = ModelBindingResult.Success("foo", new DateTime(2001, 1, 1), validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1557,7 +1546,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.DateOfDeath)]; - var result = new ModelBindingResult(new DateTime(1800, 1, 1), isModelSet: true, key: "foo"); + var result = ModelBindingResult.Success("foo", new DateTime(1800, 1, 1), validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1582,7 +1571,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(Person), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.DateOfBirth)]; - var result = new ModelBindingResult(model: null, isModelSet: true, key: "foo.DateOfBirth"); + var result = ModelBindingResult.Success("foo.DateOfBirth", model: null, validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); // Act @@ -1610,7 +1599,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var modelExplorer = metadataProvider.GetModelExplorerForType(typeof(ModelWhosePropertySetterThrows), model); var propertyMetadata = bindingContext.ModelMetadata.Properties[nameof(model.NameNoAttribute)]; - var result = new ModelBindingResult(model: null, isModelSet: true, key: "foo.NameNoAttribute"); + var result = ModelBindingResult.Success("foo.NameNoAttribute", model: null, validationNode: null); var testableBinder = new TestableMutableObjectModelBinder(); // Act diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleTypeModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleTypeModelBinderTest.cs index c0dab16541..2c1b55bc1f 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleTypeModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/SimpleTypeModelBinderTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test [InlineData(typeof(object))] [InlineData(typeof(Calendar))] [InlineData(typeof(TestClass))] - public async Task BindModel_ReturnsNull_IfTypeCannotBeConverted(Type destinationType) + public async Task BindModel_ReturnsNoResult_IfTypeCannotBeConverted(Type destinationType) { // Arrange var bindingContext = GetBindingContext(destinationType); @@ -27,10 +27,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binder = new SimpleTypeModelBinder(); // Act - var retVal = await binder.BindModelAsync(bindingContext); + var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(retVal); + Assert.Equal(ModelBindingResult.NoResult, result); } [Theory] @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test [InlineData(typeof(DateTimeOffset))] [InlineData(typeof(double))] [InlineData(typeof(DayOfWeek))] - public async Task BindModel_ReturnsNotNull_IfTypeCanBeConverted(Type destinationType) + public async Task BindModel_ReturnsFailure_IfTypeCanBeConverted_AndConversionFails(Type destinationType) { if (TestPlatformHelper.IsMono && destinationType == typeof(DateTimeOffset)) @@ -61,10 +61,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binder = new SimpleTypeModelBinder(); // Act - var retVal = await binder.BindModelAsync(bindingContext); + var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.NotNull(retVal); + Assert.NotEqual(ModelBindingResult.NoResult, result); + Assert.False(result.IsModelSet); } [Theory] @@ -130,10 +131,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binder = new SimpleTypeModelBinder(); // Act - var retVal = await binder.BindModelAsync(bindingContext); + var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(retVal); + Assert.Equal(ModelBindingResult.NoResult, result); Assert.Empty(bindingContext.ModelState); } @@ -150,11 +151,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binder = new SimpleTypeModelBinder(); // Act - var retVal = await binder.BindModelAsync(bindingContext); + var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.NotNull(retVal); - Assert.Null(retVal.Model); + Assert.Null(result.Model); Assert.True(bindingContext.ModelState.ContainsKey("theModelName")); } @@ -171,11 +171,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test var binder = new SimpleTypeModelBinder(); // Act - var retVal = await binder.BindModelAsync(bindingContext); + var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.NotNull(retVal); - Assert.Equal(42, retVal.Model); + Assert.True(result.IsModelSet); + Assert.Equal(42, result.Model); Assert.True(bindingContext.ModelState.ContainsKey("theModelName")); } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBindingHelperTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBindingHelperTest.cs index 5ca128ae95..15e15817a7 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBindingHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBindingHelperTest.cs @@ -25,9 +25,8 @@ namespace Microsoft.AspNet.Mvc.Test { return new TheoryData { - null, - new ModelBindingResult("someKey"), // IsModelSet false. - new ModelBindingResult(model: null, key: "someKey", isModelSet: false), + ModelBindingResult.NoResult, + ModelBindingResult.Failed("someKey"), }; } } @@ -665,7 +664,7 @@ namespace Microsoft.AspNet.Mvc.Test var binder = new Mock(); binder.Setup(b => b.BindModelAsync(It.IsAny())) - .Returns(Task.FromResult(null)); + .Returns(ModelBindingResult.NoResultAsync); var model = new MyModel(); Func includePredicate = (context, propertyName) => true; diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs index 3957fdffeb..e8a3ea3375 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ActionParametersIntegrationTest.cs @@ -52,7 +52,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -98,7 +97,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -147,7 +145,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -194,7 +191,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -236,7 +232,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -281,7 +276,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -329,7 +323,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -373,8 +366,8 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Act var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); - - Assert.NotNull(modelBindingResult); + + // Assert Assert.True(modelBindingResult.IsModelSet); // Model diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs index d09579d992..8a0806508f 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ArrayModelBinderIntegrationTest.cs @@ -34,7 +34,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -79,7 +78,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -120,7 +118,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -161,7 +158,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Empty(Assert.IsType(modelBindingResult.Model)); @@ -197,7 +193,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -243,7 +238,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -285,7 +279,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -327,7 +320,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Empty(Assert.IsType(modelBindingResult.Model)); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs index 7ca53d6679..cfee10ddd2 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BinderTypeBasedModelBinderIntegrationTest.cs @@ -39,7 +39,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Null(modelBindingResult.Model); @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests } [Fact] - public async Task BindParameter_WithModelBinderType_NoData_ReturnsNull() + public async Task BindParameter_WithModelBinderType_NoData() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); @@ -72,9 +71,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - - // ModelBindingResult - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState (not set unless inner binder sets it) Assert.True(modelState.IsValid); @@ -86,7 +83,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests } [Fact] - public async Task BindParameter_WithModelBinderType_NonGreedy_NoData_ReturnsNull() + public async Task BindParameter_WithModelBinderType_NonGreedy_NoData() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); @@ -111,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState Assert.True(modelState.IsValid); @@ -120,9 +117,9 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // ModelBinderAttribute can be used without specifying the binder type. // In such cases BinderTypeBasedModelBinder acts like a non greedy binder where - // it returns a null ModelBindingResult allowing other ModelBinders to run. + // it returns an empty ModelBindingResult allowing other ModelBinders to run. [Fact] - public async Task BindParameter_WithOutModelBinderType_NoData() + public async Task BindParameter_WithOutModelBinderType() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); @@ -147,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState Assert.True(modelState.IsValid); @@ -182,7 +179,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.Equal("Success", modelBindingResult.Model); Assert.Equal("CustomParameter", modelBindingResult.Key); @@ -226,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); + Assert.True(modelBindingResult.IsModelSet); Assert.Equal(string.Empty, modelBindingResult.Key); // Model @@ -267,7 +263,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.Equal("CustomParameter", modelBindingResult.Key); // Model @@ -307,7 +302,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests ValidateAllProperties = true }; - return Task.FromResult(new ModelBindingResult(address, bindingContext.ModelName, true, validationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, address, validationNode); } } @@ -325,7 +320,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests bindingContext.ModelName, bindingContext.ModelMetadata, model); - return Task.FromResult(new ModelBindingResult(model, bindingContext.ModelName, true, modelValidationNode)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, modelValidationNode); } } @@ -333,7 +328,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests { public Task BindModelAsync(ModelBindingContext bindingContext) { - return Task.FromResult(new ModelBindingResult(null, bindingContext.ModelName, true)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model: null, validationNode: null); } } @@ -341,7 +336,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests { public Task BindModelAsync(ModelBindingContext bindingContext) { - return Task.FromResult(new ModelBindingResult(null, bindingContext.ModelName, false)); + return ModelBindingResult.FailedAsync(bindingContext.ModelName); } } @@ -349,7 +344,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests { public Task BindModelAsync(ModelBindingContext bindingContext) { - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } } diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs index 249b9e81ba..58d9df09e5 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/BodyValidationIntegrationTests.cs @@ -54,7 +54,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var boundPerson = Assert.IsType(modelBindingResult.Model); Assert.NotNull(boundPerson); @@ -96,7 +95,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Null(modelBindingResult.Model); @@ -141,7 +139,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var boundPerson = Assert.IsType(modelBindingResult.Model); @@ -201,7 +198,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var boundPerson = Assert.IsType(modelBindingResult.Model); Assert.NotNull(boundPerson); @@ -260,7 +256,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.IsType(modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs index 14fc763eb4..b2e42d08d8 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ByteArrayModelBinderIntegrationTest.cs @@ -50,7 +50,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -96,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState Assert.True(modelState.IsValid); @@ -135,7 +134,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs index 100a2c8870..f6e1345004 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/CancellationTokenModelBinderIntegrationTest.cs @@ -45,7 +45,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -80,7 +79,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -118,7 +116,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs index e4fdf5af97..49778d775c 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/CollectionModelBinderIntegrationTest.cs @@ -43,7 +43,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -90,7 +89,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -125,7 +123,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -158,7 +155,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Empty(Assert.IsType>(modelBindingResult.Model)); @@ -198,7 +194,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -238,7 +233,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -272,7 +266,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Empty(Assert.IsType>(modelBindingResult.Model)); @@ -311,7 +304,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -371,7 +363,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -423,7 +414,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -476,7 +466,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -520,7 +509,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -572,7 +560,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Empty(Assert.IsType>(modelBindingResult.Model)); @@ -623,7 +610,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.IsType(modelBindingResult.Model); @@ -681,7 +667,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.IsType(modelBindingResult.Model); @@ -721,7 +706,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); var address = Assert.Single(model); @@ -946,7 +930,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.IsType(expectedType, modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs index ac57f42e07..69669ee95f 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/DictionaryModelBinderIntegrationTest.cs @@ -38,7 +38,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -79,7 +78,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -118,7 +116,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -172,7 +169,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -208,7 +204,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -241,7 +236,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -303,7 +297,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -344,7 +337,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -384,7 +376,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -425,7 +416,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -537,7 +527,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.IsType(expectedType, modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs index 215b10f924..29e3b4e689 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormCollectionModelBindingIntegrationTest.cs @@ -57,7 +57,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -107,7 +106,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -149,7 +147,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); var collection = Assert.IsAssignableFrom(modelBindingResult.Model); // ModelState diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs index 2b636dc1bc..147493fac0 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/FormFileModelBindingIntegrationTest.cs @@ -57,7 +57,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -108,7 +107,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -154,9 +152,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - - // ModelBindingResult; expect null because binding failed. - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState Assert.True(modelState.IsValid); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs index 316849fea5..b84bf5684e 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/GenericModelBinderIntegrationTest.cs @@ -43,7 +43,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -82,7 +81,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -122,7 +120,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -160,10 +157,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests protected override Task BindModelCoreAsync(ModelBindingContext bindingContext) { - return Task.FromResult(new ModelBindingResult( - new Address(), - bindingContext.ModelName, - isModelSet: true)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, new Address(), validationNode: null); } } @@ -191,7 +185,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -226,7 +219,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -262,7 +254,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType[]>(modelBindingResult.Model); @@ -308,7 +299,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType[]>(modelBindingResult.Model); @@ -354,7 +344,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType[]>(modelBindingResult.Model); @@ -390,7 +379,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); @@ -435,7 +423,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); @@ -480,7 +467,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); @@ -517,7 +503,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); @@ -566,7 +551,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); @@ -615,7 +599,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>>(modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs index 7fc20ee589..072184ac4c 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/HeaderModelBinderIntegrationTest.cs @@ -51,7 +51,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -95,7 +94,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -138,7 +136,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -201,7 +198,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs index 83e87f5ee2..1cde6af8d4 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/KeyValuePairModelBinderIntegrationTest.cs @@ -35,7 +35,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -80,7 +79,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -121,7 +119,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -162,7 +159,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal(new KeyValuePair(), modelBindingResult.Model); @@ -199,7 +195,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -245,7 +240,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -287,7 +281,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -329,7 +322,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal(new KeyValuePair(), modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs index a7e0916773..94b099c8ca 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ModelPrefixSelectionIntegrationTest.cs @@ -51,7 +51,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal("parameter", modelBindingResult.Key); @@ -102,7 +101,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal("parameter", modelBindingResult.Key); @@ -143,7 +141,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal(string.Empty, modelBindingResult.Key); @@ -194,7 +191,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal(string.Empty, modelBindingResult.Key); @@ -242,7 +238,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); Assert.Equal(string.Empty, modelBindingResult.Key); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs index 1c1f0bde7f..00bbff2660 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs @@ -70,7 +70,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -116,7 +115,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -162,7 +160,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -208,7 +205,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -250,7 +246,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -299,7 +294,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -339,7 +333,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -382,7 +375,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -424,7 +416,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -473,7 +464,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -517,7 +507,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -561,7 +550,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -616,7 +604,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -661,7 +648,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -707,7 +693,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -754,7 +739,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -796,7 +780,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -838,7 +821,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -886,7 +868,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -933,7 +914,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -972,7 +952,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1015,7 +994,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1063,7 +1041,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1110,7 +1087,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1149,7 +1125,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1192,7 +1167,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1240,7 +1214,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1287,7 +1260,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1326,7 +1298,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1369,7 +1340,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1417,7 +1387,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1464,7 +1433,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1503,7 +1471,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1555,7 +1522,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1606,7 +1572,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1659,7 +1624,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1705,7 +1669,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1755,7 +1718,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1807,7 +1769,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1851,7 +1812,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1891,7 +1851,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1935,7 +1894,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -1979,7 +1937,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -2019,7 +1976,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -2064,7 +2020,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -2109,7 +2064,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs index f90bcd7a79..5cf06b3d6d 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs @@ -48,7 +48,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -82,7 +81,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -124,7 +122,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs index 570a178a17..f37020be15 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs @@ -46,7 +46,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -91,7 +90,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -137,7 +135,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -182,7 +179,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -227,7 +223,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.False(modelBindingResult.IsModelSet); // Model @@ -277,7 +272,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.False(modelBindingResult.IsModelSet); // Model @@ -322,7 +316,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model @@ -361,7 +354,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.Null(modelBindingResult); + Assert.Equal(ModelBindingResult.NoResult, modelBindingResult); // ModelState Assert.True(modelState.IsValid); @@ -414,7 +407,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests // Assert // ModelBindingResult - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs index 8eae291f33..a40d512057 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ValidationIntegrationTests.cs @@ -43,7 +43,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -81,7 +80,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -133,7 +131,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -172,7 +169,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -226,7 +222,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -266,7 +261,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -320,7 +314,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -360,7 +353,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -409,7 +401,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -448,7 +439,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -497,7 +487,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -535,7 +524,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -587,7 +575,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -625,7 +612,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -666,7 +652,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -725,7 +710,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -763,7 +747,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -834,7 +817,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -872,7 +854,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType(modelBindingResult.Model); @@ -924,7 +905,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -962,7 +942,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); @@ -1003,7 +982,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert - Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); var model = Assert.IsType>(modelBindingResult.Model); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs index 104777013d..c4cd694c4e 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineOptionsTest.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.Razor // Assert var accessor = serviceProvider.GetRequiredService>(); - Assert.Same(fileProvider, accessor.Options.FileProvider); + Assert.Same(fileProvider, accessor.Value.FileProvider); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs index 03048da0ea..a304e33ab2 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs @@ -1205,7 +1205,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.True(context.PropertyFilter(context, "Property1")); Assert.True(context.PropertyFilter(context, "Property2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, valueProvider); @@ -1238,7 +1238,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.True(context.PropertyFilter(context, "Property1")); Assert.True(context.PropertyFilter(context, "Property2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, valueProvider); @@ -1270,7 +1270,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.True(context.PropertyFilter(context, "Property1")); Assert.True(context.PropertyFilter(context, "Property2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, provider: null); @@ -1307,7 +1307,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.False(context.PropertyFilter(context, "exclude1")); Assert.False(context.PropertyFilter(context, "exclude2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, valueProvider); @@ -1344,7 +1344,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.False(context.PropertyFilter(context, "exclude1")); Assert.False(context.PropertyFilter(context, "exclude2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, provider: null); @@ -1378,7 +1378,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.False(context.PropertyFilter(context, "exclude1")); Assert.False(context.PropertyFilter(context, "exclude2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); @@ -1413,7 +1413,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.False(context.PropertyFilter(context, "exclude1")); Assert.False(context.PropertyFilter(context, "exclude2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, provider: null); @@ -1450,7 +1450,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.False(context.PropertyFilter(context, "exclude1")); Assert.False(context.PropertyFilter(context, "exclude2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, provider: null); @@ -1484,7 +1484,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.True(context.PropertyFilter(context, "Property1")); Assert.True(context.PropertyFilter(context, "Property2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, valueProvider); @@ -1517,7 +1517,7 @@ namespace Microsoft.AspNet.Mvc.Test Assert.True(context.PropertyFilter(context, "Property1")); Assert.True(context.PropertyFilter(context, "Property2")); }) - .Returns(Task.FromResult(null)) + .Returns(ModelBindingResult.NoResultAsync) .Verifiable(); var controller = GetController(binder.Object, valueProvider); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/ViewEngine/CompositeViewEngineTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/ViewEngine/CompositeViewEngineTest.cs index a7732021c3..23c3394390 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/ViewEngine/CompositeViewEngineTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/ViewEngine/CompositeViewEngineTest.cs @@ -176,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.Rendering engine.Setup(e => e.FindPartialView(It.IsAny(), It.IsAny())) .Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" })); var optionsAccessor = new MockMvcViewOptionsAccessor(); - optionsAccessor.Options.ViewEngines.Add(engine.Object); + optionsAccessor.Value.ViewEngines.Add(engine.Object); var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act diff --git a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/HttpRequestMessage/HttpRequestMessageModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/HttpRequestMessage/HttpRequestMessageModelBinderTest.cs index 47020514da..0582d15163 100644 --- a/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/HttpRequestMessage/HttpRequestMessageModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.WebApiCompatShimTest/HttpRequestMessage/HttpRequestMessageModelBinderTest.cs @@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim var result = await binder.BindModelAsync(bindingContext); // Assert - Assert.Null(result); + Assert.Equal(ModelBindingResult.NoResult, result); } private static ModelBindingContext GetBindingContext(Type modelType) diff --git a/test/WebSites/ModelBindingWebSite/Controllers/ModelBinderAttribute_ProductController.cs b/test/WebSites/ModelBindingWebSite/Controllers/ModelBinderAttribute_ProductController.cs index 8acdbdcbee..c17b407b47 100644 --- a/test/WebSites/ModelBindingWebSite/Controllers/ModelBinderAttribute_ProductController.cs +++ b/test/WebSites/ModelBindingWebSite/Controllers/ModelBinderAttribute_ProductController.cs @@ -73,13 +73,17 @@ namespace ModelBindingWebSite.Controllers // Doing something slightly different here to make sure we don't get accidentally bound // by the type converter binder. OrderStatus model; - var isModelSet = Enum.TryParse("Status" + request.Query["status"], out model); - var validationNode = - new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model); - return Task.FromResult(new ModelBindingResult(model, "status", isModelSet, validationNode)); + if (Enum.TryParse("Status" + request.Query["status"], out model)) + { + var validationNode = + new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, model); + return ModelBindingResult.SuccessAsync("status", model, validationNode); + } + + return ModelBindingResult.FailedAsync("status"); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } @@ -103,10 +107,10 @@ namespace ModelBindingWebSite.Controllers var validationNode = new ModelValidationNode(bindingContext.ModelName, bindingContext.ModelMetadata, value); - return Task.FromResult(new ModelBindingResult(model, key, true, validationNode)); + return ModelBindingResult.SuccessAsync(key, model, validationNode); } - return Task.FromResult(null); + return ModelBindingResult.NoResultAsync; } } } diff --git a/test/WebSites/ModelBindingWebSite/TestBindingSourceModelBinder.cs b/test/WebSites/ModelBindingWebSite/TestBindingSourceModelBinder.cs index 854a3b6dd0..67c080ddef 100644 --- a/test/WebSites/ModelBindingWebSite/TestBindingSourceModelBinder.cs +++ b/test/WebSites/ModelBindingWebSite/TestBindingSourceModelBinder.cs @@ -25,10 +25,10 @@ namespace ModelBindingWebSite if (!IsSimpleType(bindingContext.ModelType)) { model = Activator.CreateInstance(bindingContext.ModelType); - return Task.FromResult(new ModelBindingResult(model, bindingContext.ModelName, true)); + return ModelBindingResult.SuccessAsync(bindingContext.ModelName, model, validationNode: null); } - return Task.FromResult(new ModelBindingResult(null, bindingContext.ModelName, false)); + return ModelBindingResult.FailedAsync(bindingContext.ModelName); } private bool IsSimpleType(Type type)