Example #1
0
        /// <summary>
        /// Tests whether the component sets entries in the <see cref="Microsoft.AspNetCore.Http.ISession"/>.
        /// </summary>
        /// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
        /// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
        /// <param name="withNumberOfEntries">Expected number of <see cref="Microsoft.AspNetCore.Http.ISession"/> entries.
        /// If default null is provided, the test builder checks only if any entries are found.</param>
        /// <returns>The same component should have test builder.</returns>
        public static TBuilder Session <TBuilder>(
            this IBaseTestBuilderWithComponentShouldHaveTestBuilder <TBuilder> builder,
            int?withNumberOfEntries = null)
            where TBuilder : IBaseTestBuilder
        {
            var actualBuilder = (BaseTestBuilderWithComponentBuilder <TBuilder>)builder;

            DataProviderValidator.ValidateDataProviderNumberOfEntries(
                actualBuilder.TestContext,
                SessionTestBuilder.SessionName,
                withNumberOfEntries,
                actualBuilder.TestContext.Session.Keys.Count());

            return(actualBuilder.Builder);
        }
        /// <summary>
        /// Tests whether the component sets specific <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entries.
        /// </summary>
        /// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
        /// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
        /// <param name="withNumberOfEntries">Expected number of <see cref="Microsoft.Extensions.Caching.Distributed.IDistributedCache"/> entries.</param>
        /// <returns>The same component should have test builder.</returns>
        public static TBuilder DistributedCache <TBuilder>(
            this IBaseTestBuilderWithComponentShouldHaveTestBuilder <TBuilder> builder,
            int?withNumberOfEntries = null)
            where TBuilder : IBaseTestBuilder
        {
            var actualBuilder = (BaseTestBuilderWithComponentBuilder <TBuilder>)builder;

            DataProviderValidator.ValidateDataProviderNumberOfEntries(
                actualBuilder.TestContext,
                DistributedCacheTestBuilder.DistributedCacheName,
                withNumberOfEntries,
                actualBuilder.TestContext.GetDistributedCacheMock().Count);

            return(actualBuilder.Builder);
        }
Example #3
0
        /// <summary>
        /// Tests whether the component sets entries in the dynamic view bag.
        /// </summary>
        /// <typeparam name="TBuilder">Class representing ASP.NET Core MVC test builder.</typeparam>
        /// <param name="builder">Instance of <see cref="IBaseTestBuilderWithComponentShouldHaveTestBuilder{TBuilder}"/> type.</param>
        /// <param name="withNumberOfEntries">Expected number of dynamic view bag entries.
        /// If default null is provided, the test builder checks only if any entries are found.</param>
        /// <returns>The same component should have test builder.</returns>
        public static TBuilder ViewBag <TBuilder>(
            this IBaseTestBuilderWithComponentShouldHaveTestBuilder <TBuilder> builder,
            int?withNumberOfEntries = null)
            where TBuilder : IBaseTestBuilder
        {
            var actualBuilder = (BaseTestBuilderWithComponentBuilder <TBuilder>)builder;

            DataProviderValidator.ValidateDataProviderNumberOfEntries(
                actualBuilder.TestContext,
                ViewBagTestBuilder.ViewBagName,
                withNumberOfEntries,
                actualBuilder.TestContext.GetViewData().Count);

            return(actualBuilder.Builder);
        }