Beispiel #1
0
        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'");
        }
Beispiel #2
0
        public void TryParseShouldReturnCorrectVersion()
        {
            var version = VersionValidator.TryParse("1.1", TestObjectFactory.GetFailingValidationAction());

            Assert.Equal(1, version.Major);
            Assert.Equal(1, version.Minor);
        }
Beispiel #3
0
        public void ValidateAndGetWellFormedUriStringShouldThrowExceptionWithIncorrectString()
        {
            string uriAsString = "http://somehost!@#?Query==true";

            var uri = LocationValidator.ValidateAndGetWellFormedUriString(
                uriAsString,
                TestObjectFactory.GetFailingValidationAction());
        }
Beispiel #4
0
        public void ValidateContentNegotiatorShouldThrowExceptionIfContentValidatorIsNotCorrect()
        {
            var actionResultWithContentNegotiator = new OkNegotiatedContentResult <int>(5, MyWebApi.Controller <WebApiController>().Controller);

            ContentNegotiatorValidator.ValidateContentNegotiator(
                actionResultWithContentNegotiator,
                new CustomContentNegotiator(),
                TestObjectFactory.GetFailingValidationAction());
        }
Beispiel #5
0
        public void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat()
        {
            var exception = Assert.Throws <NullReferenceException>(() =>
            {
                VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction());
            });

            Assert.Equal("version valid version string invalid one", exception.Message);
        }
Beispiel #6
0
        public void ValidateLocationShouldNotThrowExceptionWithCorrectPassingPredicate()
        {
            var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test");

            LocationValidator.ValidateLocation(
                actionResultWithLocation,
                location => location.Passing(uri => uri.Host == "somehost.com"),
                TestObjectFactory.GetFailingValidationAction());
        }
Beispiel #7
0
        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());
        }
Beispiel #9
0
        public void ValidateUriShouldNotThrowExceptionWithProperUriWithCorrectString()
        {
            var actionResultWithLocation = new CreatedNegotiatedContentResult <int>(
                TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController());

            LocationValidator.ValidateUri(
                actionResultWithLocation,
                TestObjectFactory.GetUri(),
                TestObjectFactory.GetFailingValidationAction());
        }
Beispiel #10
0
        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());
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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());
        }
Beispiel #16
0
        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'");
        }
Beispiel #17
0
        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());
        }
Beispiel #19
0
        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());
        }
Beispiel #20
0
        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());
        }
Beispiel #21
0
 public void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat()
 {
     VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction());
 }