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 void TryParseShouldReturnCorrectVersion() { var version = VersionValidator.TryParse("1.1", TestObjectFactory.GetFailingValidationAction()); Assert.Equal(1, version.Major); Assert.Equal(1, version.Minor); }
public void ValidateAndGetWellFormedUriStringShouldThrowExceptionWithIncorrectString() { string uriAsString = "http://somehost!@#?Query==true"; var uri = LocationValidator.ValidateAndGetWellFormedUriString( uriAsString, TestObjectFactory.GetFailingValidationAction()); }
public void ValidateContentNegotiatorShouldThrowExceptionIfContentValidatorIsNotCorrect() { var actionResultWithContentNegotiator = new OkNegotiatedContentResult <int>(5, MyWebApi.Controller <WebApiController>().Controller); ContentNegotiatorValidator.ValidateContentNegotiator( actionResultWithContentNegotiator, new CustomContentNegotiator(), TestObjectFactory.GetFailingValidationAction()); }
public void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat() { var exception = Assert.Throws <NullReferenceException>(() => { VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction()); }); Assert.Equal("version valid version string invalid one", exception.Message); }
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 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 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 ValidateMediaTypeFormattersBuilderShouldThrowExceptionWithIncorrectBuilder() { var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>( TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController()); MediaTypeFormatterValidator.ValidateMediaTypeFormattersBuilder( actionResultWithFormatters, formatters => formatters .ContainingMediaTypeFormatterOfType <CustomMediaTypeFormatter>(), TestObjectFactory.GetFailingValidationAction()); }
public void ValidateAndGetWellFormedUriStringShouldReturnProperUriWithCorrectString() { string uriAsString = "http://somehost.com/someuri/1?query=Test"; var uri = LocationValidator.ValidateAndGetWellFormedUriString( uriAsString, TestObjectFactory.GetFailingValidationAction()); Assert.IsNotNull(uri); Assert.AreEqual(uriAsString, uri.OriginalString); }
public void ValidateAndGetWellFormedUriStringShouldThrowExceptionWithIncorrectString() { string uriAsString = "http://somehost!@#?Query==true"; var exception = Assert.Throws <NullReferenceException>(() => { var uri = LocationValidator.ValidateAndGetWellFormedUriString( uriAsString, TestObjectFactory.GetFailingValidationAction()); }); Assert.Equal("location to be URI valid instead received http://somehost!@#?Query==true", exception.Message); }
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 void ValidateAndGetWellFormedUrtringShouldThrowExceptionWithIncorrectString() { string uriAsString = "http://somehost!@#?Query==true"; Test.AssertException <NullReferenceException>( () => { LocationValidator.ValidateAndGetWellFormedUriString( uriAsString, TestObjectFactory.GetFailingValidationAction()); }, "location to be URI valid instead received 'http://somehost!@#?Query==true'"); }
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 ValidateMediaTypeFormatterShouldNotThrowExceptionWithSingleCorrectMediaTypeFormatter() { var actionResultWithFormatter = new FormattedContentResult <int>( HttpStatusCode.OK, 5, TestObjectFactory.GetCustomMediaTypeFormatter(), new MediaTypeHeaderValue(TestObjectFactory.MediaType), MyWebApi.Controller <WebApiController>().AndProvideTheController()); MediaTypeFormatterValidator.ValidateMediaTypeFormatter( actionResultWithFormatter, TestObjectFactory.GetCustomMediaTypeFormatter(), TestObjectFactory.GetFailingValidationAction()); }
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 void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat() { VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction()); }