Пример #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'");
        }
Пример #2
0
 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
         }
     });
 }
Пример #4
0
        public void ValidateLocationShouldNotThrowExceptionWithCorrectPassingPredicate()
        {
            var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test");

            LocationValidator.ValidateLocation(
                actionResultWithLocation,
                location => location.Passing(uri => uri.Host == "somehost.com"),
                TestObjectFactory.GetFailingValidationAction());
        }
Пример #5
0
        public void ValidateUrhouldNotThrowExceptionWithProperUriWithCorrectString()
        {
            var actionResultWithLocation = new CreatedResult(TestObjectFactory.GetUri(), "Test");

            LocationValidator.ValidateUri(
                actionResultWithLocation,
                TestObjectFactory.GetUri().OriginalString,
                TestObjectFactory.GetFailingValidationAction());
        }
Пример #6
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 ValidateMediaTypeFormatterShouldThrowExceptionWithIncorrectMediaTypeFormatter()
        {
            var actionResultWithFormatters = new CreatedNegotiatedContentResult <int>(
                TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().Controller);

            MediaTypeFormatterValidator.ValidateMediaTypeFormatter(
                actionResultWithFormatters,
                TestObjectFactory.GetCustomMediaTypeFormatter(),
                TestObjectFactory.GetFailingValidationAction());
        }
Пример #9
0
        public void ValidateUriShouldNotThrowExceptionWithProperUriWithCorrectString()
        {
            var actionResultWithLocation = new CreatedNegotiatedContentResult <int>(
                TestObjectFactory.GetUri(), 5, MyWebApi.Controller <WebApiController>().AndProvideTheController());

            LocationValidator.ValidateUri(
                actionResultWithLocation,
                TestObjectFactory.GetUri(),
                TestObjectFactory.GetFailingValidationAction());
        }
Пример #10
0
 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());
        }
Пример #12
0
        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>),
     });
 }
Пример #15
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'");
        }
Пример #16
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());
        }
Пример #17
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());
        }
Пример #18
0
 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));
 }