Example #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'");
        }
Example #2
0
 /// <summary>
 /// Tests whether created result has specific location provided by builder.
 /// </summary>
 /// <param name="uriTestBuilder">Builder for expected URI.</param>
 /// <returns>The same created test builder.</returns>
 public IAndCreatedTestBuilder AtLocation(Action <IUriTestBuilder> uriTestBuilder)
 {
     LocationValidator.ValidateLocation(
         this.ActionResult,
         uriTestBuilder,
         this.ThrowNewCreatedResultAssertionException);
     return(this);
 }
        /// <inheritdoc />
        public IAndRedirectTestBuilder ToUrl(Action <IUriTestBuilder> uriTestBuilder)
        {
            LocationValidator.ValidateLocation(
                this.GetRedirectResult <RedirectResult>(Location),
                uriTestBuilder,
                this.ThrowNewRedirectResultAssertionException);

            return(this);
        }
Example #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());
        }
Example #5
0
        /// <inheritdoc />
        public IAndCreatedTestBuilder AtLocation(Action <IUriTestBuilder> uriTestBuilder)
        {
            var createdResult = this.GetCreatedResult <CreatedResult>(Location);

            LocationValidator.ValidateLocation(
                createdResult,
                uriTestBuilder,
                this.ThrowNewCreatedResultAssertionException);

            return(this);
        }
Example #6
0
        /// <summary>
        /// Tests whether redirect result has specific location provided by builder.
        /// </summary>
        /// <param name="uriTestBuilder">Builder for expected URI.</param>
        /// <returns>Base test builder.</returns>
        public IBaseTestBuilderWithCaughtException AtLocation(Action <IUriTestBuilder> uriTestBuilder)
        {
            var redirrectResult = this.GetRedirectResult <RedirectResult>(Location);

            LocationValidator.ValidateLocation(
                redirrectResult,
                uriTestBuilder,
                this.ThrowNewRedirectResultAssertionException);

            return(this);
        }
        /// <summary>
        /// Tests whether the <see cref="AcceptedResult"/>
        /// has specific location provided by builder.
        /// </summary>
        /// <param name="acceptedTestBuilder">
        /// Instance of <see cref="IAcceptedTestBuilder"/> type.
        /// </param>
        /// <param name="uriTestBuilder">Builder for expected URI.</param>
        /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
        public static IAndAcceptedTestBuilder AtLocation(
            this IAcceptedTestBuilder acceptedTestBuilder,
            Action <IUriTestBuilder> uriTestBuilder)
        {
            var actualBuilder = GetAcceptedTestBuilder <AcceptedResult>(acceptedTestBuilder, Location);

            LocationValidator.ValidateLocation(
                actualBuilder.ActionResult,
                uriTestBuilder,
                actualBuilder.ThrowNewFailedValidationException);

            return(actualBuilder);
        }
Example #8
0
        /// <summary>
        /// Tests whether the <see cref="Microsoft.AspNetCore.Mvc.ActionResult"/>
        /// has specific location provided by builder.
        /// </summary>
        /// <param name="baseTestBuilderWithRedirectResult">
        /// Instance of <see cref="IBaseTestBuilderWithRedirectResult{TRedirectResultTestBuilder}"/> type.
        /// </param>
        /// <param name="uriTestBuilder">Builder for expected URI.</param>
        /// <returns>The same redirect <see cref="Microsoft.AspNetCore.Mvc.ActionResult"/> test builder.</returns>
        public static TRedirectResultTestBuilder ToUrl <TRedirectResultTestBuilder>(
            this IBaseTestBuilderWithRedirectResult <TRedirectResultTestBuilder> baseTestBuilderWithRedirectResult,
            Action <IUriTestBuilder> uriTestBuilder)
            where TRedirectResultTestBuilder : IBaseTestBuilderWithActionResult
        {
            var actualBuilder = GetActualBuilder(baseTestBuilderWithRedirectResult);

            LocationValidator.ValidateLocation(
                actualBuilder.TestContext.MethodResult,
                uriTestBuilder,
                actualBuilder.ThrowNewFailedValidationException);

            return(actualBuilder.ResultTestBuilder);
        }
Example #9
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());
        }
Example #10
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());
        }