public static async Task <ServiceCollectionFactory> CreateAsync() { var services = new ServiceCollectionFactory(); await CreateRolesAsync(services); var dummyUser1 = new ApplicationUser() { Id = "1", UserName = "******" }; var dummyUser2 = new ApplicationUser() { Id = "2", UserName = "******" }; var dummyAdmin = new ApplicationUser() { Id = "3", UserName = "******", Email = "*****@*****.**" }; await services.UserManager.CreateAsync(dummyUser1, "qwer"); await services.UserManager.CreateAsync(dummyUser2, "asdf"); await services.UserManager.CreateAsync(dummyAdmin, "admin"); await services.UserManager.AddToRoleAsync(dummyUser1, "Patient"); await services.UserManager.AddToRoleAsync(dummyUser2, "Doctor"); await services.UserManager.AddToRoleAsync(dummyAdmin, "Administrator"); await services.DatabaseContext.SaveChangesAsync(); return(services); }
private static async Task CreateRolesAsync(ServiceCollectionFactory services) { string[] roleNames = { "Administrator", "Doctor", "Patient" }; IdentityResult roleResult; foreach (var roleName in roleNames) { var roleExist = await services.RoleManager.RoleExistsAsync(roleName); if (!roleExist) { roleResult = await services.RoleManager.CreateAsync(new IdentityRole(roleName)); } } }
public void TearDown() { ServiceCollectionFactory.Destroy(_services); }
public async Task Setup() { _services = await ServiceCollectionFactory.CreateAsync(); }
public static void Destroy(ServiceCollectionFactory services) { services.DatabaseContext.Database.EnsureDeleted(); services.DatabaseContext.Dispose(); }