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));
                }
            }
        }
Exemple #3
0
 public void TearDown()
 {
     ServiceCollectionFactory.Destroy(_services);
 }
Exemple #4
0
 public async Task Setup()
 {
     _services = await ServiceCollectionFactory.CreateAsync();
 }
 public static void Destroy(ServiceCollectionFactory services)
 {
     services.DatabaseContext.Database.EnsureDeleted();
     services.DatabaseContext.Dispose();
 }