public static IIdentityServerBuilder AddIntegrationTestConfiguration(this IIdentityServerBuilder builder)
        {
            builder.AddInMemoryClients(ClientSeedData.GetClients(SeedingType.IntegrationTest));
            builder.AddInMemoryApiResources(ApiResourceSeedData.GetApiResources(SeedingType.IntegrationTest));
            builder.AddInMemoryUsers(IdentityUserSeedData.GetIdentityUsers(SeedingType.IntegrationTest));
            builder.AddInMemoryRoles(RoleSeedData.GetIdentityRoles(SeedingType.IntegrationTest));
            builder.AddInMemoryUserRoles(IdentityUserRoleSeedData.GetIdentityUserRoles(SeedingType.IntegrationTest));
            builder.AddInMemoryIdentityResources(IdentityResourceSeedData.GetIdentityResources(SeedingType.IntegrationTest));

            builder.AddInMemoryPersistedGrants();

            return(builder);
        }
        /// <summary>
        /// Adds the roles.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="seedingType">Type of the seeding.</param>
        private static void AddRoles(AuthenticationDbContext context,
                                     SeedingType seedingType)
        {
            List <IdentityRole> roles = RoleSeedData.GetIdentityRoles(seedingType);

            foreach (IdentityRole role in roles)
            {
                Boolean foundRole = context.Roles.Any(a => a.Name == role.Name);

                if (!foundRole)
                {
                    context.Roles.Add(role);
                }
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    SeedData.Initialize(services);
                    RoleSeedData.Initialize(services).Wait();
                }
                catch (Exception ex)
                {
                    services.GetRequiredService <ILogger <Program> >().LogError(ex, "An error occurred while seeding the database.");
                    throw;
                }
            }
            BuildWebHost(args).Run();
        }