Пример #1
0
        /// <summary>
        /// Use the Startup type T to configure the ASP.Net Core application
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void UseStartup <T>() where T : class
        {
            if (Environment.ContentRootPath.IsEmpty())
            {
                Environment.ContentRootPath         = DirectoryFinder.FindParallelFolder(typeof(T).GetTypeInfo().Assembly.GetName().Name) ?? Directory.GetCurrentDirectory();
                Environment.ContentRootFileProvider = new PhysicalFileProvider(Environment.ContentRootPath);
            }

            Configure(x => x.UseStartup <T>());
        }
Пример #2
0
        /// <summary>
        /// Create a SystemUnderTest using the designated "Startup" type
        /// to configure the ASP.Net Core system
        /// </summary>
        /// <param name="rootPath"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SystemUnderTest ForStartup <T>(string rootPath = null) where T : class
        {
            var environment = new HostingEnvironment
            {
                ContentRootPath = rootPath ?? DirectoryFinder.FindParallelFolder(typeof(T).GetTypeInfo().Assembly.GetName().Name) ?? AppContext.BaseDirectory
            };

            environment.WebRootPath = environment.ContentRootPath;


            var system = new SystemUnderTest(environment);

            system.UseStartup <T>();

            return(system);
        }
Пример #3
0
        /// <summary>
        ///     Create a SystemUnderTest using the designated "Startup" type
        ///     to configure the ASP.Net Core system
        /// </summary>
        /// <param name="configure">Optional configuration of the IWebHostBuilder to be applied *after* the call to UseStartup()</param>
        /// <param name="rootPath"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SystemUnderTest ForStartup <T>(Func <IWebHostBuilder, IWebHostBuilder> configure = null,
                                                     string rootPath = null) where T : class
        {
            var builder = WebHost.CreateDefaultBuilder();

            builder.UseStartup <T>();
            if (configure != null)
            {
                builder = configure(builder);
            }

            builder.UseContentRoot(rootPath ?? DirectoryFinder.FindParallelFolder(typeof(T).Assembly.GetName().Name) ??
                                   AppContext.BaseDirectory);

            var system = new SystemUnderTest(builder, typeof(T).Assembly);

            return(system);
        }