diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/TypeExtensions.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/TypeExtensions.cs index b4e18196e1..117d413f0f 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/TypeExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/TypeExtensions.cs @@ -5,23 +5,23 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal { public static class TypeExtensions { - public static bool IsCompatibleWith(this Type type, object value) + public static bool IsCompatibleWith([NotNull] this Type type, object value) { return (value == null && AllowsNullValue(type)) || - type.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()); + (value != null && type.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo())); } - public static bool IsNullableValueType(this Type type) + public static bool IsNullableValueType([NotNull] this Type type) { return Nullable.GetUnderlyingType(type) != null; } - public static bool AllowsNullValue(this Type type) + public static bool AllowsNullValue([NotNull] this Type type) { return (!type.GetTypeInfo().IsValueType || IsNullableValueType(type)); } - public static bool HasStringConverter(this Type type) + public static bool HasStringConverter([NotNull] this Type type) { // TODO: This depends on TypeConverter which does not exist in the CoreCLR. // return TypeDescriptor.GetConverter(type).CanConvertFrom(typeof(string)); @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal return false; } - public static Type[] GetTypeArgumentsIfMatch(Type closedType, Type matchingOpenType) + public static Type[] GetTypeArgumentsIfMatch([NotNull] Type closedType, Type matchingOpenType) { TypeInfo closedTypeInfo = closedType.GetTypeInfo(); if (!closedTypeInfo.IsGenericType) diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ComplexModelDtoResultTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ComplexModelDtoResultTest.cs index 7c7c78ee8a..d8d0cf0e53 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ComplexModelDtoResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/ComplexModelDtoResultTest.cs @@ -4,14 +4,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test { public class ComplexModelDtoResultTest { - [Fact] - public void Constructor_ThrowsIfValidationNodeIsNull() - { - // Act & assert - ExceptionAssert.ThrowsArgumentNull( - () => new ComplexModelDtoResult("some string"), - "validationNode"); - } + // TODO: Validation + ////[Fact] + ////public void Constructor_ThrowsIfValidationNodeIsNull() + ////{ + //// // Act & assert + //// ExceptionAssert.ThrowsArgumentNull( + //// () => new ComplexModelDtoResult("some string"), + //// "validationNode"); + ////} // TODO: Validation //[Fact] diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/TypeConverterModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/TypeConverterModelBinderTest.cs index 1802148a18..68d42fbea7 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/TypeConverterModelBinderTest.cs +++ b/test/Microsoft.AspNet.Mvc.ModelBinding.Test/Binders/TypeConverterModelBinderTest.cs @@ -24,30 +24,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test // Act bool retVal = binder.BindModel(bindingContext); - // Assert - Assert.False(retVal); - Assert.Equal("The value 'not an integer' is not valid for Int32.", bindingContext.ModelState["theModelName"].Errors[0].ErrorMessage); - } - - [Fact] - public void BindModel_Error_FormatExceptionsTurnedIntoStringsInModelState_ErrorNotAddedIfCallbackReturnsNull() - { - // Arrange - ModelBindingContext bindingContext = GetBindingContext(typeof(int)); - bindingContext.ValueProvider = new SimpleHttpValueProvider - { - { "theModelName", "not an integer" } - }; - - TypeConverterModelBinder binder = new TypeConverterModelBinder(); - - // Act - bool retVal = binder.BindModel(bindingContext); - // Assert Assert.False(retVal); Assert.Null(bindingContext.Model); - Assert.True(bindingContext.ModelState.IsValid); + Assert.False(bindingContext.ModelState.IsValid); + Assert.Equal("Input string was not in a correct format.", bindingContext.ModelState["theModelName"].Errors[0].ErrorMessage); } // TODO: TypeConverter