/// <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 CreateDefaultBuilder(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() => WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint <TEntryPoint>(Array.Empty <string>()) ?? throw new InvalidOperationException(Resources.FormatMissingCreateWebHostBuilderMethod( nameof(IWebHostBuilder), typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName, typeof(WebApplicationFactory <TEntryPoint>).Name, nameof(CreateWebHostBuilder)));
public static void Main(string[] args) { var hostBuilder = WebHostBuilderFactory.Build <Startup>(args); var host = hostBuilder.Build(); host.Run(); }
public void OneTimeSetup() { var builder = WebHostBuilderFactory .CreateFromTypesAssemblyEntryPoint <Startup>(Array.Empty <string>()); appServer = new TestServer(builder); httpClient = appServer.CreateClient(); }
protected virtual IWebHostBuilder CreateWebHostBuilder() { var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint <TEntryPoint>(Array.Empty <string>()); if (builder == null) { throw new InvalidOperationException("Some error"); } else { return(builder.UseEnvironment("Development")); } }
/// <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 CreateDefaultBuilder(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.FormatMissingCreateWebHostBuilderMethod( nameof(IWebHostBuilder), typeof(TEntryPoint).Assembly.EntryPoint.DeclaringType.FullName, typeof(WebApplicationFactory <TEntryPoint>).Name, nameof(CreateWebHostBuilder))); } else { return(builder.UseEnvironment("Development")); } }
static TestClientBase CreateClient() { var b = WebHostBuilderFactory.Create(null, null, services => { services.AddSingleton <StupidService>(); }, app => { app.UseMiddleware <StupidMiddleware>(); }, c => c.UseTestServer()) .Build(); b.Start(); return(new TestServerClient(b, true)); }
public static 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); return(server); }
IServiceProvider BuildServiceProvider <TStartup>() where TStartup : class => WebHostBuilderFactory .CreateFromTypesAssemblyEntryPoint <TStartup>(new string[0]) .ConfigureServices(_config) .Build() .Services;
protected override IWebHostBuilder CreateWebHostBuilder() { return(WebHostBuilderFactory.CreateFromAssemblyEntryPoint( typeof(Cms.Web.Startup).Assembly, Array.Empty <string>())); }
/// <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();