Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var identity = ConfigureIdentity.Make(Configuration);

            identity.AddServices(services);
            services.AddMvc();
        }
Exemple #2
0
        public WebHostTestServer()
        {
            var tokenConfig = new TokenValidationParameters {
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ValidateLifetime         = false,
                ValidateIssuerSigningKey = true,
                ValidateActor            = false,
                ValidateTokenReplay      = false,
                ValidIssuer      = JWTConfig.Audience,
                ValidAudience    = JWTConfig.Audience,
                IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JWTConfig.Key))
            };
            var builder = new WebHostBuilder()
                          .ConfigureServices(services => {
                ConfigureIdentity.Make()
                .SetDbContextConfig(dbOptions => {
                    dbOptions.UseInMemoryDatabase("TESTING_DATABASE_MEMORY");
                })
                .SetIdentityOptions(identityOptions => {
                    identityOptions.SignIn.RequireConfirmedEmail       = false;
                    identityOptions.SignIn.RequireConfirmedPhoneNumber = false;
                })
                .SetJwtBearerOptions(jwtBearerOptions => {
                    jwtBearerOptions.RequireHttpsMetadata      = false;
                    jwtBearerOptions.IncludeErrorDetails       = true;
                    jwtBearerOptions.TokenValidationParameters = tokenConfig;
                })
                .AddServices(services);

                services.AddMvc(options => {
                    // options.Filters.Add<IdentityAuthorizeAttribute>();
                });
            })
                          .Configure(app => {
                app.UseAuthentication();
                app.UseMvc(routes => {
                    routes.MapRoute("default", "{controller=FakeIdentityAuthorizeTestsController}/{action=Index}/{id?}");
                });
            });
            var testServer = new TestServer(builder);

            testServer.BaseAddress = new Uri("http://localhost");
            _testServer            = testServer;
        }
Exemple #3
0
        public WebHostFixtureWithConfig()
        {
            var ds = Path.DirectorySeparatorChar;

            _webHost = WebHost.CreateDefaultBuilder()
                       .ConfigureServices(services => {
                var config = new ConfigurationBuilder()
                             .SetBasePath(Directory.GetCurrentDirectory() + $"..{ds}..{ds}..{ds}..{ds}")
                             .AddJsonFile("appsettings.json")
                             .Build();

                ConfigureIdentity.Make(config)
                .SetDbContextConfig(options => {
                    options.UseInMemoryDatabase(Guid.NewGuid().ToString());
                })
                .AddServices(services);
                var provider = services.BuildServiceProvider();
                _roleManager = provider.GetService <RoleManager <ApplicationRole> >();
                _userManager = provider.GetService <UserManager <ApplicationUser> >();
            })
                       .UseStartup <FakeStartup>()
                       .Build();
        }