Exemple #1
0
        public static HttpClient CreateAuthenticatedClient <TStartup>(this TestWebApplicationFactory <TStartup> factory) where TStartup : class
        {
            var client = factory.WithWebHostBuilder(builder =>
            {
                builder.ConfigureTestServices(services =>
                {
                    services.AddAuthentication("Test")
                    .AddScheme <AuthenticationSchemeOptions, TestAuthenticationHandler>(
                        "Test", options => { });

                    services.AddAuthorization(options =>
                    {
                        options.AddPolicy("Bearer", policy =>
                        {
                            policy.AddAuthenticationSchemes("Test");
                            policy.RequireAuthenticatedUser();
                        });
                    });
                });
            })
                         .CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false,
            });

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Test");

            return(client);
        }
Exemple #2
0
 public BrandApiTests(TestWebApplicationFactory <Startup> factory)
 {
     _factory = factory;
 }