Make ModelBindingResult a struct.

This commit is contained in:
Ryan Nowak 2015-08-28 09:05:52 -07:00
parent 2b52942faf
commit 076ce6a8a1
63 changed files with 576 additions and 603 deletions

View File

@ -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
{
/// <summary>
/// Contains the result of model binding.
/// </summary>
public class ModelBindingResult
public struct ModelBindingResult : IEquatable<ModelBindingResult>
{
/// <summary>
/// Creates a new <see cref="ModelBindingResult"/> indicating a fatal error.
/// A <see cref="ModelBinding"/> representing the lack of a result. The model binding
/// system will continue to execute other model binders.
/// </summary>
/// <param name="key">The key using which was used to attempt binding the model.</param>
public ModelBindingResult(string key)
public static readonly ModelBindingResult NoResult = new ModelBindingResult();
/// <summary>
/// Returns a completed <see cref="Task{ModelBindingResult}"/> representing the lack of a result. The model
/// binding system will continue to execute other model binders.
/// </summary>
public static readonly Task<ModelBindingResult> NoResultAsync = Task.FromResult(NoResult);
/// <summary>
/// Creates a <see cref="ModelBindingResult"/> representing a failed model binding operation.
/// </summary>
/// <param name="key">The key of the current model binding operation.</param>
/// <returns>A <see cref="ModelBindingResult"/> representing a failed model binding operation.</returns>
public static ModelBindingResult Failed([NotNull] string key)
{
return new ModelBindingResult(key, model: null, isModelSet: false, validationNode: null);
}
/// <summary>
/// Creates a completed <see cref="Task{ModelBindingResult}"/> representing a failed model binding operation.
/// </summary>
/// <param name="key">The key of the current model binding operation.</param>
/// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a failed model binding operation.</returns>
public static Task<ModelBindingResult> FailedAsync([NotNull] string key)
{
return Task.FromResult(Failed(key));
}
/// <summary>
/// Creates a <see cref="ModelBindingResult"/> representing a successful model binding operation.
/// </summary>
/// <param name="key">The key of the current model binding operation.</param>
/// <param name="model">The model value. May be <c>null.</c></param>
/// <param name="validationNode">The <see cref="ModelValidationNode"/>. May be <c>null</c>.</param>
/// <returns>A <see cref="ModelBindingResult"/> representing a successful model bind.</returns>
public static ModelBindingResult Success(
[NotNull] string key,
object model,
ModelValidationNode validationNode)
{
return new ModelBindingResult(key, model, isModelSet: true, validationNode: validationNode);
}
/// <summary>
/// Creates a completed <see cref="Task{ModelBindingResult}"/> representing a successful model binding
/// operation.
/// </summary>
/// <param name="key">The key of the current model binding operation.</param>
/// <param name="model">The model value. May be <c>null.</c></param>
/// <param name="validationNode">The <see cref="ModelValidationNode"/>. May be <c>null</c>.</param>
/// <returns>A completed <see cref="Task{ModelBindingResult}"/> representing a successful model bind.</returns>
public static Task<ModelBindingResult> SuccessAsync(
[NotNull] string key,
object model,
ModelValidationNode validationNode)
{
return Task.FromResult(Success(key, model, validationNode));
}
/// <summary>
/// Creates a new <see cref="ModelBindingResult"/> using the provided <paramref cref="key"/>
/// </summary>
/// <param name="key">The key of the current model binding operation.</param>
/// <param name="other">The other <see cref="ModelBindingResult" /> to copy from.</param>
public ModelBindingResult([NotNull] string key, ModelBindingResult other)
{
Key = key;
Model = other.Model;
IsModelSet = other.IsModelSet;
ValidationNode = other.ValidationNode;
}
/// <summary>
/// Creates a new <see cref="ModelBindingResult"/>.
/// </summary>
/// <param name="model">The model which was created by the <see cref="IModelBinder"/>.</param>
/// <param name="key">The key using which was used to attempt binding the model.</param>
/// <param name="isModelSet">A value that represents if the model has been set by the
/// <see cref="IModelBinder"/>.</param>
public ModelBindingResult(object model, string key, bool isModelSet)
: this(model, key, isModelSet, validationNode: null)
{
}
/// <summary>
/// Creates a new <see cref="ModelBindingResult"/>.
/// </summary>
/// <param name="model">The model which was created by the <see cref="IModelBinder"/>.</param>
/// <param name="key">The key using which was used to attempt binding the model.</param>
/// <param name="isModelSet">A value that represents if the model has been set by the
/// <see cref="IModelBinder"/>.</param>
/// <param name="validationNode">A <see cref="ModelValidationNode"/> which captures the validation information.
/// </param>
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 <see cref="ModelValidationNode"/> associated with the current <see cref="ModelBindingResult"/>.
/// </summary>
public ModelValidationNode ValidationNode { get; }
/// <inheritdoc />
public override bool Equals(object obj)
{
var other = obj as ModelBindingResult?;
if (other == null)
{
return false;
}
else
{
return Equals(other.Value);
}
}
/// <inheritdoc />
public override int GetHashCode()
{
var hash = HashCodeCombiner.Start();
hash.Add(Key, StringComparer.OrdinalIgnoreCase);
hash.Add(IsModelSet);
hash.Add(Model);
return hash.CombinedHash;
}
/// <inheritdoc />
public bool Equals(ModelBindingResult other)
{
return
string.Equals(Key, other.Key, StringComparison.OrdinalIgnoreCase) &&
IsModelSet == other.IsModelSet &&
object.Equals(Model, other.Model);
}
/// <summary>
/// Compares <see cref="ModelBindingResult"/> objects for equality.
/// </summary>
/// <param name="x">A <see cref="ModelBindingResult"/>.</param>
/// <param name="y">A <see cref="ModelBindingResult"/>.</param>
/// <returns><c>true</c> if the objects are equal, otherwise <c>false</c>.</returns>
public static bool operator ==(ModelBindingResult x, ModelBindingResult y)
{
return x.Equals(y);
}
/// <summary>
/// Compares <see cref="ModelBindingResult"/> objects for inequality.
/// </summary>
/// <param name="x">A <see cref="ModelBindingResult"/>.</param>
/// <param name="y">A <see cref="ModelBindingResult"/>.</param>
/// <returns><c>true</c> if the objects are not equal, otherwise <c>false</c>.</returns>
public static bool operator !=(ModelBindingResult x, ModelBindingResult y)
{
return !x.Equals(y);
}
}
}

View File

@ -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-*",

View File

@ -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;
}

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{
if (bindingContext.ModelMetadata.IsReadOnly)
{
return Task.FromResult<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
return base.BindModelAsync(bindingContext);

View File

@ -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.

View File

@ -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.

View File

@ -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);
}
}
}

View File

@ -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 <input ... /> 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);
}
}
}

View File

@ -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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
}
}

View File

@ -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);
}
/// <inheritdoc />

View File

@ -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<ModelBindingResult> 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)

View File

@ -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<TValue>(valueResult?.Model);
if (valueResult != null && valueResult.IsModelSet)
model[convertedKey] = ModelBindingHelper.CastOrDefault<TValue>(valueResult.Model);
if (valueResult.IsModelSet)
{
validationNode.ChildNodes.Add(valueResult.ValidationNode);
}

View File

@ -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

View File

@ -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<List<IFormFile>> GetFormFilesAsync(ModelBindingContext bindingContext)

View File

@ -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)

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
/// <summary>
@ -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);

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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);

View File

@ -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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
}
}

View File

@ -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<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(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<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(null));
.Returns(ModelBindingResult.NoResultAsync);
var actionBindingContext = new ActionBindingContext()
{
@ -263,7 +263,7 @@ namespace Microsoft.AspNet.Mvc.Actions
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(null));
.Returns(ModelBindingResult.NoResultAsync);
var actionBindingContext = new ActionBindingContext()
{
@ -362,8 +362,8 @@ namespace Microsoft.AspNet.Mvc.Actions
var binder = new Mock<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<IModelBinder>();
binder
.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<ModelBindingContext>(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<ModelBindingContext>(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()

View File

@ -2078,7 +2078,7 @@ namespace Microsoft.AspNet.Mvc.Actions
var binder = new Mock<IModelBinder>();
binder.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(result: null));
.Returns(ModelBindingResult.NoResultAsync);
var context = new Mock<HttpContext>();
context.SetupGet(c => c.Items)
.Returns(new Dictionary<object, object>());

View File

@ -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<int[]> 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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
});
return mockIntBinder.Object;
}

View File

@ -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<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
return Task.FromResult<ModelBindingResult>(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);
}
}
}

View File

@ -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<ModelBindingResult> 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);
}
}
}
}

View File

@ -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]

View File

@ -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)

View File

@ -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)

View File

@ -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<int>();
@ -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<ModelBindingResult>(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;
}

View File

@ -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<ModelBindingResult>(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<IModelBinder>();
modelBinder
.Setup(mb => mb.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<IModelBinder>();
modelBinder
.Setup(mb => mb.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<IModelBinder>();
mockListBinder.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(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<IModelBinder>();
mockBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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<IModelBinder>();
mockBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(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<IModelBinder>();
mockBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.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; }

View File

@ -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<int, string> 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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
});

View File

@ -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]

View File

@ -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<IModelBinder>();
mockBinder.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(null));
.Returns(ModelBindingResult.NoResultAsync);
bindingContext.OperationBindingContext.ModelBinder = mockBinder.Object;
var binder = new KeyValuePairModelBinder<int, string>();
@ -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<IModelBinder>();
innerBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
@ -143,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
var result = await binder.TryBindStrongModel<int>(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<ModelBindingResult>(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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
});
return mockStringBinder.Object;
}

View File

@ -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);
}
}
}

View File

@ -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<IValueProvider>();
@ -407,7 +407,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var mockBinder = new Mock<IModelBinder>();
mockBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(null));
.Returns(ModelBindingResult.NoResultAsync);
var bindingContext = new ModelBindingContext
{
@ -457,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var mockBinder = new Mock<IModelBinder>();
mockBinder
.Setup(o => o.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(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

View File

@ -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"));
}

View File

@ -25,9 +25,8 @@ namespace Microsoft.AspNet.Mvc.Test
{
return new TheoryData<ModelBindingResult>
{
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<IModelBinder>();
binder.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
.Returns(Task.FromResult<ModelBindingResult>(null));
.Returns(ModelBindingResult.NoResultAsync);
var model = new MyModel();
Func<ModelBindingContext, string, bool> includePredicate =
(context, propertyName) => true;

View File

@ -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

View File

@ -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<int[]>(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<int[]>(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<int[]>(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<int[]>(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<Person[]>(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<Person[]>(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<Person[]>(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<Person[]>(modelBindingResult.Model));

View File

@ -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<ModelBindingResult> 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<ModelBindingResult> 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<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{
return Task.FromResult<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
}
}

View File

@ -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<Person>(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<Person4>(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<Person2>(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<Person3>(modelBindingResult.Model);

View File

@ -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<byte[]>(modelBindingResult.Model);

View File

@ -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

View File

@ -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<List<int>>(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<List<int>>(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<List<int>>(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<List<int>>(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<List<Person>>(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<List<Person>>(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<List<Person>>(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<List<Person2>>(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<List<Person2>>(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<List<Person2>>(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<List<int>>(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<List<Person2>>(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<List<Person2>>(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<Person4>(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<Person5>(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<List<Address5>>(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);

View File

@ -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<Dictionary<string, int>>(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<Dictionary<string, int>>(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<Dictionary<string, int>>(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<Dictionary<string, int>>(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<Dictionary<string, int>>(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<Dictionary<string, int>>(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<Dictionary<string, Person>>(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<Dictionary<string, Person>>(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<Dictionary<string, Person>>(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<Dictionary<string, Person>>(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);

View File

@ -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<IFormCollection>(modelBindingResult.Model);
// ModelState

View File

@ -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);

View File

@ -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<List<IFormCollection>>(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<List<IFormCollection>>(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<List<IFormCollection>>(modelBindingResult.Model);
@ -160,10 +157,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
protected override Task<ModelBindingResult> 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<Address[]>(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<Address[]>(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<Dictionary<string, int>[]>(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<Dictionary<string, int>[]>(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<Dictionary<string, int>[]>(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<List<KeyValuePair<string, int>>>(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<List<KeyValuePair<string, int>>>(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<List<KeyValuePair<string, int>>>(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<Dictionary<string, List<int>>>(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<Dictionary<string, List<int>>>(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<Dictionary<string, List<int>>>(modelBindingResult.Model);

View File

@ -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

View File

@ -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<KeyValuePair<string, int>>(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<KeyValuePair<string, int>>(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<KeyValuePair<string, int>>(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<string, int>(), 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<KeyValuePair<string, Person>>(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<KeyValuePair<string, Person>>(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<KeyValuePair<string, Person>>(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<string, Person>(), modelBindingResult.Model);

View File

@ -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);

View File

@ -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<Order1>(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<Order1>(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<Order1>(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<Order1>(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<Order1>(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<Order2>(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<Order2>(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<Order2>(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<Order2>(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<Order3>(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<Order3>(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<Order3>(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<Order4>(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<Order4>(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<Order4>(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<Order4>(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<Order4>(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<Order5>(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<Order5>(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<Order5>(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<Order5>(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<Order6>(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<Order6>(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<Order6>(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<Order6>(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<Order7>(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<Order7>(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<Order7>(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<Order7>(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<Order8>(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<Order8>(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<Order8>(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<Order8>(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<Order9>(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<Order10>(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<Order11>(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<Order11>(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<Order11>(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<Order12>(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<Order12>(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<Order12>(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<Order13>(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<Order13>(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<Order13>(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<Order14>(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<Order14>(modelBindingResult.Model);

View File

@ -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

View File

@ -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

View File

@ -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<Order1>(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<Order1>(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<Order2>(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<Order2>(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<Order3>(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<Order3>(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<Order4>(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<Order4>(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<List<Order5>>(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<List<Order5>>(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<Order6>(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<Order6>(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<Order7>(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<Order7>(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<Order7>(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<Order8>(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<Order8>(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<Order9>(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<Order9>(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<List<Order10>>(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<List<Order10>>(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<List<Order10>>(modelBindingResult.Model);

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.Razor
// Assert
var accessor = serviceProvider.GetRequiredService<IOptions<RazorViewEngineOptions>>();
Assert.Same(fileProvider, accessor.Options.FileProvider);
Assert.Same(fileProvider, accessor.Value.FileProvider);
}
}
}

View File

@ -1205,7 +1205,7 @@ namespace Microsoft.AspNet.Mvc.Test
Assert.True(context.PropertyFilter(context, "Property1"));
Assert.True(context.PropertyFilter(context, "Property2"));
})
.Returns(Task.FromResult<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(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<ModelBindingResult>(null))
.Returns(ModelBindingResult.NoResultAsync)
.Verifiable();
var controller = GetController(binder.Object, valueProvider);

View File

@ -176,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
engine.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
.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

View File

@ -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)

View File

@ -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<OrderStatus>("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<OrderStatus>("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<ModelBindingResult>(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<ModelBindingResult>(null);
return ModelBindingResult.NoResultAsync;
}
}
}

View File

@ -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)