Пример #1
0
        /// <summary>
        /// Creates a <see cref="IWebHostBuilder"/> used to set up <see cref="TestServer"/>.
        /// </summary>
        /// <remarks>
        /// The default implementation of this method looks for a <c>public static IWebHostBuilder CreateWebHostBuilder(string[] args)</c>
        /// method defined on the entry point of the assembly of <typeparamref name="TEntryPoint" /> and invokes it passing an empty string
        /// array as arguments.
        /// </remarks>
        /// <returns>A <see cref="IWebHostBuilder"/> instance.</returns>
        protected virtual IWebHostBuilder CreateWebHostBuilder()
        {
            var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint <TEntryPoint>(Array.Empty <string>());

            if (builder == null)
            {
                throw new InvalidOperationException(Resources.FormatMissingBuilderMethod(
                                                        nameof(IHostBuilder),
                                                        nameof(IWebHostBuilder),
                                                        typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName,
                                                        typeof(WebApplicationFactory <TEntryPoint>).Name,
                                                        nameof(CreateHostBuilder),
                                                        nameof(CreateWebHostBuilder)));
            }
            else
            {
                return(builder.UseEnvironment(Environments.Development));
            }
        }
Пример #2
0
        public TestServer CreateServer(
            Action <IWebHostBuilder> configureBuilder,
            [CallerMemberName] string isolationKey = "")
        {
            var builder = WebHostBuilderFactory
                          .CreateFromTypesAssemblyEntryPoint <Startup>(new string[] { })
                          .UseSolutionRelativeContentRoot(Path.Combine("test", "WebSites", "Identity.DefaultUI.WebSite"))
                          .ConfigureServices(sc => sc.SetupTestDatabase(isolationKey)
                                             .AddMvc()
                                             // Mark the cookie as essential for right now, as Identity uses it on
                                             // several places to pass important data in post-redirect-get flows.
                                             .AddCookieTempDataProvider(o => o.Cookie.IsEssential = true));

            configureBuilder(builder);

            var server = new TestServer(builder);

            _disposableServers.Add(server);
            return(server);
        }
Пример #3
0
 IServiceProvider BuildServiceProvider <TStartup>() where TStartup : class
 => WebHostBuilderFactory
 .CreateFromTypesAssemblyEntryPoint <TStartup>(new string[0])
 .ConfigureServices(_config)
 .Build()
 .Services;
Пример #4
0
 /// <summary>
 /// Creates a <see cref="IWebHostBuilder"/> used to setup <see cref="TestServer"/>.
 /// <remarks>
 /// The default implementation of this method looks for a <c>public static IWebHostBuilder CreateDefaultBuilder(string[] args)</c>
 /// method defined on the entry point of the assembly of <typeparamref name="TStartup" /> and invokes it passing an empty string
 /// array as arguments. In case this method can't be found,
 /// </remarks>
 /// </summary>
 /// <returns>A <see cref="IWebHostBuilder"/> instance.</returns>
 protected virtual IWebHostBuilder CreateWebHostBuilder() =>
 WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint <TStartup>(Array.Empty <string>()) ?? new WebHostBuilder();