diff --git a/src/Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs b/src/Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs index 15bb1001ca..ca126dcd7e 100644 --- a/src/Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs +++ b/src/Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs @@ -46,7 +46,7 @@ public object Convert(string input, Type destinationType, BindingContext context { return true; } - return null; + throw; } } } diff --git a/test/Nancy.Tests/Unit/ModelBinding/DefaultBinderFixture.cs b/test/Nancy.Tests/Unit/ModelBinding/DefaultBinderFixture.cs index 16f4bfeed0..7cb05e17b8 100644 --- a/test/Nancy.Tests/Unit/ModelBinding/DefaultBinderFixture.cs +++ b/test/Nancy.Tests/Unit/ModelBinding/DefaultBinderFixture.cs @@ -294,25 +294,6 @@ public void Should_call_convert_on_type_converter_if_available() .MustHaveHappened(Repeated.Exactly.Once); } - [Fact] - public void Should_ignore_properties_that_cannot_be_converted() - { - // Given - var binder = this.GetBinder(typeConverters: new[] { new FallbackConverter() }); - var context = new NancyContext { Request = new FakeRequest("GET", "/") }; - context.Request.Form["StringProperty"] = "Test"; - context.Request.Form["IntProperty"] = "12"; - context.Request.Form["DateProperty"] = "Broken"; - - // When - var result = (TestModel)binder.Bind(context, typeof(TestModel), null, BindingConfig.Default); - - // Then - result.StringProperty.ShouldEqual("Test"); - result.IntProperty.ShouldEqual(12); - result.DateProperty.ShouldEqual(default(DateTime)); - } - [Fact] public void Should_throw_ModelBindingException_if_convertion_of_a_property_fails() { @@ -321,6 +302,7 @@ public void Should_throw_ModelBindingException_if_convertion_of_a_property_fails var context = new NancyContext { Request = new FakeRequest("GET", "/") }; context.Request.Form["IntProperty"] = "badint"; context.Request.Form["AnotherIntProperty"] = "morebad"; + context.Request.Form["DateProperty"] = "bad dates"; // Indiana Jones' monkey is dead :) // Then Type modelType = typeof(TestModel); @@ -333,6 +315,9 @@ public void Should_throw_ModelBindingException_if_convertion_of_a_property_fails && exception.PropertyBindingExceptions.Any(pe => pe.PropertyName == "AnotherIntProperty" && pe.AttemptedValue == "morebad") + && exception.PropertyBindingExceptions.Any(pe => + pe.PropertyName == "DateProperty" + && pe.AttemptedValue == "bad dates") && exception.PropertyBindingExceptions.All(pe => pe.InnerException.Message.Contains(pe.AttemptedValue) && pe.InnerException.Message.Contains(modelType.GetProperty(pe.PropertyName).PropertyType.Name)));