/// <inheritdoc />
        public IAndViewTestBuilder WithViewEngineOfType <TViewEngine>()
            where TViewEngine : IViewEngine
        {
            var actualViewEngineType   = this.viewResult?.ViewEngine?.GetType();
            var expectedViewEngineType = typeof(TViewEngine);

            if (actualViewEngineType == null ||
                Reflection.AreDifferentTypes(expectedViewEngineType, actualViewEngineType))
            {
                throw ViewViewComponentResultAssertionException.ForViewEngineType(
                          this.TestContext.ExceptionMessagePrefix,
                          expectedViewEngineType.ToFriendlyTypeName(),
                          actualViewEngineType.ToFriendlyTypeName());
            }

            return(this);
        }
Example #2
0
        /// <summary>
        /// Tests whether <see cref="Microsoft.AspNetCore.Mvc.ViewComponents.ViewViewComponentResult"/>
        /// has the same <see cref="IViewEngine"/> type as the provided one.
        /// </summary>
        /// <param name="viewTestBuilder">
        /// Instance of <see cref="IViewTestBuilder"/> type.
        /// </param>
        /// <param name="viewEngineType"></param>
        /// <returns>The same <see cref="IAndViewTestBuilder"/>.</returns>
        public static IAndViewTestBuilder WithViewEngineOfType(
            this IViewTestBuilder viewTestBuilder,
            Type viewEngineType)
        {
            var actualBuilder = GetActualBuilder(viewTestBuilder);

            var actualViewEngineType = actualBuilder.ViewResult?.ViewEngine?.GetType();

            if (actualViewEngineType == null ||
                Reflection.AreDifferentTypes(viewEngineType, actualViewEngineType))
            {
                var(expectedViewEngineTypeName, actualViewEngineTypeName) =
                    (viewEngineType, actualViewEngineType).GetTypeComparisonNames();

                throw ViewViewComponentResultAssertionException.ForViewEngineType(
                          actualBuilder.TestContext.ExceptionMessagePrefix,
                          expectedViewEngineTypeName,
                          actualViewEngineTypeName);
            }

            return(actualBuilder);
        }