public IdentitySeeder( SchoolMachineContext context, RoleManager <IdentityRole <Guid> > roleManager, UserManager <ApplicationUser> userManager) { this.context = context ?? throw new ArgumentNullException(nameof(context)); this.roleManager = roleManager ?? throw new ArgumentNullException(nameof(roleManager)); this.userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); }
public static void BaseTestClassSetup(TestContext context) { IConfiguration Configuration = new ConfigurationBuilder().Build(); try { string[] args = new string[0]; var webHostBuilder = WebHost .CreateDefaultBuilder(args) .ConfigureAppConfiguration( (context, config) => KeyVaultConnectionManager.ConfigureSchoolMachineConfiguration(config) ) .UseStartup <Startup>(); var webHost = webHostBuilder.Build(); var roleManager = webHost.Services.GetRequiredService <RoleManager <IdentityRole <Guid> > >(); var userManager = webHost.Services.GetRequiredService <UserManager <ApplicationUser> >(); var builder = new DbContextOptionsBuilder <SchoolMachineContext>(); builder.UseInMemoryDatabase(databaseName: "SchoolMachine"); var dbContextOptions = builder.Options; SchoolMachineContext = new SchoolMachineContext(dbContextOptions, Configuration); DataSeeder.Seed(SchoolMachineContext); var identitySeeder = new IdentitySeeder(SchoolMachineContext, roleManager, userManager); var identityTask = identitySeeder.Seed(); identityTask.Wait(); // Test Assertions Assert.IsTrue(SchoolMachineContext.Districts.Count() >= DataSeeder.DistrictSeeder.Objects.Count() , string.Format("Database has {0} SchoolDistricts and Seeder has {1}", SchoolMachineContext.Districts.Count(), DataSeeder.DistrictSeeder.Objects.Count())); Assert.IsTrue(SchoolMachineContext.Schools.Count() >= DataSeeder.SchoolSeeder.Objects.Count() , string.Format("Database has {0} Schools and Seeder has {1}", SchoolMachineContext.Schools.Count(), DataSeeder.SchoolSeeder.Objects.Count())); Assert.IsTrue(SchoolMachineContext.Students.Count() >= DataSeeder.StudentSeeder.Objects.Count() , string.Format("Database has {0} Students and Seeder has {1}", SchoolMachineContext.Students.Count(), DataSeeder.StudentSeeder.Objects.Count())); Assert.IsTrue(SchoolMachineContext.DistrictSchools.Count() >= DataSeeder.DistrictSchools.Count() , string.Format("Database has {0} SchoolDistrictSchools and Seeder has {1}", SchoolMachineContext.DistrictSchools.Count(), DataSeeder.DistrictSchools.Count())); Assert.IsTrue(SchoolMachineContext.SchoolStudents.Count() >= DataSeeder.SchoolStudents.Count() , string.Format("Database has {0} SchoolStudents and Seeder has {1}", SchoolMachineContext.SchoolStudents.Count(), DataSeeder.SchoolStudents.Count())); } catch (Exception ex) { Assert.Fail(string.Format("Unexpected exception occurred during test class intialization: {0}", ex)); } }
public static void Seed(SchoolMachineContext context) { foreach (var country in DataSeeder.CountrySeeder.Objects) { context.Countries.Add(country); } foreach (var state in DataSeeder.StateSeeder.Objects) { context.States.Add(state); } foreach (var location in DataSeeder.Locations) { context.Locations.Add(location); } foreach (var district in DataSeeder.DistrictSeeder.Objects) { context.Districts.Add(district); } foreach (var school in DataSeeder.SchoolSeeder.Objects) { context.Schools.Add(school); } foreach (var student in DataSeeder.StudentSeeder.Objects) { context.Students.Add(student); } foreach (var districtSchool in DataSeeder.DistrictSchools) { context.DistrictSchools.Add(districtSchool); } foreach (var schoolStudent in DataSeeder.SchoolStudents) { context.SchoolStudents.Add(schoolStudent); } context.SaveChanges(); }
public RepositoryBase(SchoolMachineContext repositoryContext) { this.RepositoryContext = repositoryContext; }
public RepositoryWrapper(SchoolMachineContext repositoryContext) { _repoContext = repositoryContext; }
public StateRepository(SchoolMachineContext dbContext) : base(dbContext) { }
public SchoolStudentRepository(SchoolMachineContext repositoryContext) : base(repositoryContext) { }
public SchoolMachineDbContextCleaner(SchoolMachineContext schoolMachineContext) { this.schoolMachineContext = schoolMachineContext; }
public DistrictRepository(SchoolMachineContext dbContext) : base(dbContext) { }
public CountryRepository(SchoolMachineContext dbContext) : base(dbContext) { }
public StudentDistrictRegistrationRepository(SchoolMachineContext dbContext) : base(dbContext) { }
public static void BaseTestClassCleanup() { SchoolMachineContext = null; }
public DistrictSchoolRepository(SchoolMachineContext repositoryContext) : base(repositoryContext) { }