public void Ctor_should_set_empty_property_exceptions_list_if_none_are_provided()
        {
            //When
            var exception = new ModelBindingException(typeof (string));

            //Then
            exception.PropertyBindingExceptions.Any().ShouldBeFalse();
        }
        public void Message_should_contain_bound()
        {
            //When
            var exception = new ModelBindingException(typeof (string));

            //then
            exception.Message.ShouldEqual(String.Format("Unable to bind to type: {0}", typeof(string)));
        }
Esempio n. 3
0
        public void Message_should_contain_only_bound_type_if_no_property_is_provided()
        {
            //When
            var exception = new ModelBindingException(typeof (string));

            //Then
            exception.Message.ShouldEqual("Unable to bind to type: " + typeof(string));
        }
Esempio n. 4
0
        public void Message_should_contain_bound_type_and_property_name()
        {
            //When
            var exception = new ModelBindingException(typeof (string), "PropName");

            //then
            exception.Message.ShouldEqual(String.Format("Unable to bind to type: {0}; Property: {1}", typeof(string), "PropName"));
        }
        public void Ctor_should_set_property_exceptions_and_bound_type()
        {
            //When
            var propertyExceptions = new List<PropertyBindingException>();
            var exception = new ModelBindingException(typeof (string), propertyExceptions);

            //Then
            exception.BoundType.ShouldBeOfType<string>();
            exception.PropertyBindingExceptions.ShouldBeSameAs(propertyExceptions);
        }
Esempio n. 6
0
        public void Ctor_should_set_property_name_and_bound_type_and_inner_exception()
        {
            //When
            var inner = new Exception();
            var exception = new ModelBindingException(typeof (string), "Length", inner);

            //Then
            exception.BoundType.ShouldBeOfType<string>();
            exception.PropertyName.ShouldEqual("Length");
            exception.InnerException.ShouldBeSameAs(inner);
        }
            public void GivenExceptionIsModelBindingException_WhenRunningPipeline_ThenReturnsBadRequestWithExceptionDetails()
            {
                var modelBindingException = new ModelBindingException(typeof(object), new[] { new PropertyBindingException("SomeProperty", "1") });
                var expectedExceptionModel = modelBindingException.Message;

                var result = _sut.Invoke(A.Dummy<NancyContext>(), modelBindingException) as Negotiator;

                result.Should().NotBeNull();
                result.NegotiationContext.StatusCode.Should().Be(HttpStatusCode.BadRequest);
                var actualExceptionModel = result.NegotiationContext.GetModelForMediaRange("application/json") as object;
                actualExceptionModel.Should().BeAssignableTo<string>();
                ((string)actualExceptionModel).ShouldBeEquivalentTo(expectedExceptionModel);
            }