/// <summary>
        /// Tests whether the <see cref="AcceptedResult"/>
        /// location passes the given assertions.
        /// </summary>
        /// <param name="acceptedTestBuilder">
        /// Instance of <see cref="IAcceptedTestBuilder"/> type.
        /// </param>
        /// <param name="assertions">Action containing all assertions for the location.</param>
        /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
        public static IAndAcceptedTestBuilder AtLocationPassing(
            this IAcceptedTestBuilder acceptedTestBuilder,
            Action <string> assertions)
        {
            var actualBuilder = GetAcceptedTestBuilder <AcceptedResult>(acceptedTestBuilder, Location);

            assertions(actualBuilder.ActionResult.Location);

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

            var uri = LocationValidator.ValidateAndGetWellFormedUriString(
                location,
                actualBuilder.ThrowNewFailedValidationException);

            return(actualBuilder.AtLocation(uri));
        }
        /// <summary>
        /// Tests whether the <see cref="AcceptedResult"/>
        /// has specific location provided by <see cref="Uri"/>.
        /// </summary>
        /// <param name="acceptedTestBuilder">
        /// Instance of <see cref="IAcceptedTestBuilder"/> type.
        /// </param>
        /// <param name="location">Expected location as <see cref="Uri"/>.</param>
        /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
        public static IAndAcceptedTestBuilder AtLocation(
            this IAcceptedTestBuilder acceptedTestBuilder,
            Uri location)
        {
            var actualBuilder = GetAcceptedTestBuilder <AcceptedResult>(acceptedTestBuilder, Location);

            LocationValidator.ValidateUri(
                actualBuilder.ActionResult,
                location.OriginalString,
                actualBuilder.ThrowNewFailedValidationException);

            return(actualBuilder);
        }
        /// <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);
        }
        /// <summary>
        /// Tests whether the <see cref="AcceptedAtActionResult"/>
        /// has specific controller name.
        /// </summary>
        /// <param name="acceptedTestBuilder">
        /// Instance of <see cref="IAcceptedTestBuilder"/> type.
        /// </param>
        /// <param name="controllerName">Expected controller name.</param>
        /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
        public static IAndAcceptedTestBuilder AtController(
            this IAcceptedTestBuilder acceptedTestBuilder,
            string controllerName)
        {
            var actualBuilder = GetAcceptedTestBuilder <AcceptedAtActionResult>(
                acceptedTestBuilder,
                "controller name");

            RouteActionResultValidator.ValidateControllerName(
                actualBuilder.ActionResult,
                controllerName,
                actualBuilder.ThrowNewFailedValidationException);

            return(actualBuilder);
        }
        /// <summary>
        /// Tests whether the <see cref="AcceptedResult"/>
        /// location passes the given predicate.
        /// </summary>
        /// <param name="acceptedTestBuilder">
        /// Instance of <see cref="IAcceptedTestBuilder"/> type.
        /// </param>
        /// <param name="predicate">Predicate testing the location.</param>
        /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
        public static IAndAcceptedTestBuilder AtLocationPassing(
            this IAcceptedTestBuilder acceptedTestBuilder,
            Func <string, bool> predicate)
        {
            var actualBuilder = GetAcceptedTestBuilder <AcceptedResult>(acceptedTestBuilder, Location);

            var location = actualBuilder.ActionResult.Location;

            if (!predicate(location))
            {
                actualBuilder.ThrowNewFailedValidationException(
                    $"location ('{location}')",
                    "to pass the given predicate",
                    "it failed");
            }

            return(actualBuilder);
        }
Example #7
0
        private static IAndAcceptedTestBuilder ProcessRouteLambdaExpression(
            IAcceptedTestBuilder acceptedTestBuilder,
            LambdaExpression actionCall)
        {
            var actualBuilder = GetActualBuilder(acceptedTestBuilder);

            actualBuilder.IncludeCountCheck = false;

            var controllerTestContext = actualBuilder.TestContext as ControllerTestContext;
            var actionResult          = actualBuilder.TestContext.MethodResult as IActionResult;

            ExpressionLinkValidator.Validate(
                controllerTestContext,
                LinkGenerationTestContext.FromAcceptedResult(actionResult),
                actionCall,
                actualBuilder.ThrowNewFailedValidationException);

            return((IAndAcceptedTestBuilder)acceptedTestBuilder);
        }
        private static AcceptedTestBuilder <TAcceptedResult> GetAcceptedTestBuilder <TAcceptedResult>(
            IAcceptedTestBuilder acceptedTestBuilder,
            string containment)
            where TAcceptedResult : ObjectResult
        {
            var actualAcceptedTestBuilder = acceptedTestBuilder as AcceptedTestBuilder <TAcceptedResult>;

            if (actualAcceptedTestBuilder == null)
            {
                var acceptedTestBuilderBase = (BaseTestBuilderWithComponent)acceptedTestBuilder;

                throw new AcceptedResultAssertionException(string.Format(
                                                               "{0} accepted result to contain {1}, but such could not be found.",
                                                               acceptedTestBuilderBase.TestContext.ExceptionMessagePrefix,
                                                               containment));
            }

            return(actualAcceptedTestBuilder);
        }
Example #9
0
 GetActualBuilder(IAcceptedTestBuilder acceptedTestBuilder)
 => (IBaseTestBuilderWithRouteValuesResultInternal <IAndAcceptedTestBuilder>)acceptedTestBuilder;
Example #10
0
 /// <summary>
 /// Tests whether <see cref="AcceptedAtActionResult"/> or <see cref="AcceptedAtRouteResult"/>
 /// returns accepted at specific asynchronous action.
 /// </summary>
 /// <typeparam name="TController">Type of expected controller.</typeparam>
 /// <param name="builder">Instance of <see cref="IAcceptedTestBuilder"/> type.</param>
 /// <param name="actionCall">Method call expression indicating the expected asynchronous accepted action.</param>
 /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
 public static IAndAcceptedTestBuilder At <TController>(
     this IAcceptedTestBuilder builder,
     Expression <Func <TController, Task> > actionCall)
     where TController : class
 => ProcessRouteLambdaExpression(builder, actionCall);
 /// <summary>
 /// Tests whether the <see cref="AcceptedAtActionResult"/> or <see cref="AcceptedAtRouteResult"/>
 /// has the same <see cref="IUrlHelper"/> type as the provided one.
 /// </summary>
 /// <param name="acceptedTestBuilder">
 /// Instance of <see cref="IAcceptedTestBuilder"/> type.
 /// </param>
 /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
 public static IAndAcceptedTestBuilder WithUrlHelperOfType <TUrlHelper>(
     this IAcceptedTestBuilder acceptedTestBuilder)
     where TUrlHelper : IUrlHelper
 => acceptedTestBuilder
 .WithUrlHelperOfType <IAndAcceptedTestBuilder, TUrlHelper>();
 /// <summary>
 /// Tests whether the <see cref="AcceptedAtActionResult"/> or <see cref="AcceptedAtRouteResult"/>
 /// contains specific route value of the given type with the provided key.
 /// </summary>
 /// <param name="acceptedTestBuilder">
 /// Instance of <see cref="IAcceptedTestBuilder"/> type.
 /// </param>
 /// <param name="key">Expected route key.</param>
 /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
 public static IAndAcceptedTestBuilder ContainingRouteValueOfType <TRouteValue>(
     this IAcceptedTestBuilder acceptedTestBuilder,
     string key)
 => acceptedTestBuilder
 .ContainingRouteValueOfType <IAndAcceptedTestBuilder, TRouteValue>(key);
 /// <summary>
 /// Tests whether the accepted result
 /// contains <see cref="IOutputFormatter"/> of the provided type.
 /// </summary>
 /// <param name="acceptedTestBuilder">
 /// Instance of <see cref="IAcceptedTestBuilder"/> type.
 /// </param>
 /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
 public static IAndAcceptedTestBuilder ContainingOutputFormatterOfType <TOutputFormatter>(
     this IAcceptedTestBuilder acceptedTestBuilder)
     where TOutputFormatter : IOutputFormatter
 => acceptedTestBuilder
 .ContainingOutputFormatterOfType <IAndAcceptedTestBuilder, TOutputFormatter>();
 /// <summary>
 /// Tests whether the <see cref="AcceptedAtRouteResult"/>
 /// has specific route name.
 /// </summary>
 /// <param name="acceptedTestBuilder">
 /// Instance of <see cref="IAcceptedTestBuilder"/> type.
 /// </param>
 /// <param name="routeName">Expected route name.</param>
 /// <returns>The same <see cref="IAndAcceptedTestBuilder"/>.</returns>
 public static IAndAcceptedTestBuilder AtRoute(
     this IAcceptedTestBuilder acceptedTestBuilder,
     string routeName)
 => acceptedTestBuilder
 .WithRouteName(routeName);