public void ValidateLocationShouldThrowExceptionWithIncorrectLocationBuilder() { Test.AssertException <NullReferenceException>( () => { var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test"); LocationValidator.ValidateLocation( actionResultWithLocation, location => location .WithHost("somehost12.com") .AndAlso() .WithAbsolutePath("/someuri/1") .AndAlso() .WithPort(80) .AndAlso() .WithScheme("http") .AndAlso() .WithFragment(string.Empty) .AndAlso() .WithQuery("?query=Test"), TestObjectFactory.GetFailingValidationAction()); }, "URI to be 'http://somehost12.com/someuri/1?query=Test' was in fact 'http://somehost.com/someuri/1?query=Test'"); }
public IHttpActionResult CreatedActionWithCustomContentNegotiator() { return(new CreatedNegotiatedContentResult <ICollection <ResponseModel> >( TestObjectFactory.GetUri(), this.responseModel, TestObjectFactory.GetCustomContentNegotiator(), TestObjectFactory.GetCustomHttpRequestMessage(), TestObjectFactory.GetFormatters())); }
public IActionResult CreatedActionWithFormatter(IOutputFormatter formatter) { return(new CreatedResult(TestObjectFactory.GetUri(), this.responseModel) { Formatters = new FormatterCollection <IOutputFormatter> { formatter } }); }
public void ValidateLocationShouldNotThrowExceptionWithCorrectPassingPredicate() { var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test"); LocationValidator.ValidateLocation( actionResultWithLocation, location => location.Passing(uri => uri.Host == "somehost.com"), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateUrhouldNotThrowExceptionWithProperUriWithCorrectString() { var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test"); LocationValidator.ValidateUri( actionResultWithLocation, TestObjectFactory.GetUri().OriginalString, TestObjectFactory.GetFailingValidationAction()); }
public void ValidateUriShouldThrowExceptionWithIncorrectString() { var actionResultWithLocation = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); LocationValidator.ValidateUri( actionResultWithLocation, new Uri("http://somehost.com/"), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateMediaTypeFormattersShouldNotThrowExceptionWithCorrectMediaTypeFormatter() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); MediaTypeFormatterValidator.ValidateMediaTypeFormatters( actionResultWithFormatters, MediaTypeFormatterValidator.GetDefaultMediaTypeFormatters(), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateMediaTypeFormatterShouldThrowExceptionWithIncorrectMediaTypeFormatter() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().Controller); MediaTypeFormatterValidator.ValidateMediaTypeFormatter( actionResultWithFormatters, TestObjectFactory.GetCustomMediaTypeFormatter(), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateUriShouldNotThrowExceptionWithProperUriWithCorrectString() { var actionResultWithLocation = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); LocationValidator.ValidateUri( actionResultWithLocation, TestObjectFactory.GetUri(), TestObjectFactory.GetFailingValidationAction()); }
public void AndAlsoShouldWorkCorrectly() { MyWebApi .Controller <WebApiController>() .Calling(c => c.CreatedActionWithCustomContentNegotiator()) .ShouldReturn() .Created() .AtLocation(TestObjectFactory.GetUri()) .AndAlso() .ContainingMediaTypeFormatterOfType <JsonMediaTypeFormatter>(); }
public void ValidateMediaTypeFormattersBuilderShouldThrowExceptionWithIncorrectBuilder() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); MediaTypeFormatterValidator.ValidateMediaTypeFormattersBuilder( actionResultWithFormatters, formatters => formatters .ContainingMediaTypeFormatterOfType <CustomMediaTypeFormatter>(), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateBindingShouldThrowExceptionWithInvalidPropertyCall() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().Controller); RuntimeBinderValidator.ValidateBinding(() => { var contentNegotiator = (actionResultWithFormatters as dynamic).ModelState; Assert.IsNotNull(contentNegotiator); }); }
public void ValidateMediaTypeFormattersBuilderShouldNotThrowExceptionWithCorrectBuilder() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().Controller); MediaTypeFormatterValidator.ValidateMediaTypeFormattersBuilder( actionResultWithFormatters, formatters => formatters .ContainingMediaTypeFormatter(new JsonMediaTypeFormatter()) .AndAlso() .ContainingMediaTypeFormatterOfType <FormUrlEncodedMediaTypeFormatter>(), TestObjectFactory.GetFailingValidationAction()); }
public IActionResult FullCreatedAction() { return(new CreatedResult(TestObjectFactory.GetUri(), this.responseModel) { ContentTypes = new MediaTypeCollection { new MediaTypeHeaderValue(ContentType.ApplicationJson), new MediaTypeHeaderValue(ContentType.ApplicationXml) }, StatusCode = StatusCodes.Status201Created, Formatters = new FormatterCollection <IOutputFormatter> { TestObjectFactory.GetOutputFormatter(), new CustomOutputFormatter() }, DeclaredType = typeof(List <ResponseModel>), }); }
public void ValidateUrhouldThrowExceptionWithIncorrectString() { Test.AssertException <NullReferenceException>( () => { var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test"); LocationValidator.ValidateUri( actionResultWithLocation, "http://somehost.com/", TestObjectFactory.GetFailingValidationAction()); }, "location to be 'http://somehost.com/' instead received 'http://somehost.com/someuri/1?query=Test'"); }
public void ValidateLocationShouldNotThrowExceptionWithCorrectLocationBuilder() { var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test"); LocationValidator.ValidateLocation( actionResultWithLocation, location => location .WithHost("somehost.com") .AndAlso() .WithAbsolutePath("/someuri/1") .AndAlso() .WithPort(80) .AndAlso() .WithScheme("http") .AndAlso() .WithFragment(string.Empty) .AndAlso() .WithQuery("?query=Test"), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateLocationShouldThrowExceptionWithIncorrectLocationBuilder() { var actionResultWithLocation = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); LocationValidator.ValidateLocation( actionResultWithLocation, location => location .WithHost("somehost12.com") .AndAlso() .WithAbsolutePath("/someuri/1") .AndAlso() .WithPort(80) .AndAlso() .WithScheme("http") .AndAlso() .WithFragment(string.Empty) .AndAlso() .WithQuery("?query=Test"), TestObjectFactory.GetFailingValidationAction()); }
public IHttpActionResult RedirectActionWithUri() { return(this.Redirect(TestObjectFactory.GetUri())); }
public IActionResult CreatedActionWithUri() { return(this.Created(TestObjectFactory.GetUri(), this.responseModel)); }
public IActionResult CreatedAction() { return(this.Created(TestObjectFactory.GetUri().OriginalString, this.responseModel)); }
public IActionResult RedirectActionWithUri() { return(this.Redirect(TestObjectFactory.GetUri().OriginalString)); }