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); }
/// <exception cref="NullReferenceException">Thrown when the enviroment variable was not found. This results in an empty or null string variable which is not allowed.</exception> private static void SeedIdentityUserRoles(ModelBuilder builder) { if (_userAccounts == null || _userAccounts.Length == 0) { throw new NullReferenceException($"{nameof(_userAccounts)} was empty or null"); } if (_identityRoles == null || _identityRoles.Length < Enum.GetNames(typeof(Roles)).Length) { throw new NullReferenceException($"{nameof(_userAccounts)} was empty, not containing all roles or null"); } builder.Entity <IdentityUserRole <string> >().HasData(IdentityUserRoleSeedData.Build(_userAccounts, _identityRoles)); }
/// <summary> /// Adds the users to roles. /// </summary> /// <param name="context">The context.</param> /// <param name="seedingType">Type of the seeding.</param> private static void AddUsersToRoles(AuthenticationDbContext context, SeedingType seedingType) { List <IdentityUserRole <String> > identityUserRoles = IdentityUserRoleSeedData.GetIdentityUserRoles(seedingType); foreach (IdentityUserRole <String> identityUserRole in identityUserRoles) { Boolean foundUserRole = context.UserRoles.Any(a => a.RoleId == identityUserRole.RoleId && a.UserId == identityUserRole.UserId); if (!foundUserRole) { context.UserRoles.Add(identityUserRole); } } }