/// <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)));
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var hostBuilder = WebHostBuilderFactory.Build <Startup>(args);
            var host        = hostBuilder.Build();

            host.Run();
        }
Ejemplo n.º 3
0
        public void OneTimeSetup()
        {
            var builder = WebHostBuilderFactory
                          .CreateFromTypesAssemblyEntryPoint <Startup>(Array.Empty <string>());

            appServer  = new TestServer(builder);
            httpClient = appServer.CreateClient();
        }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 5
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 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"));
            }
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 IServiceProvider BuildServiceProvider <TStartup>() where TStartup : class
 => WebHostBuilderFactory
 .CreateFromTypesAssemblyEntryPoint <TStartup>(new string[0])
 .ConfigureServices(_config)
 .Build()
 .Services;
Ejemplo n.º 9
0
 protected override IWebHostBuilder CreateWebHostBuilder()
 {
     return(WebHostBuilderFactory.CreateFromAssemblyEntryPoint(
                typeof(Cms.Web.Startup).Assembly, Array.Empty <string>()));
 }
Ejemplo n.º 10
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();