public async Task Setup() { Action <IServiceCollection> actions = (sc) => { sc.ReplaceTransient <IDbContextFactory <PersonalCommonLegacyContext>, InMemoryPersonalCommonLegacyContextFactory>(); sc.ReplaceTransient <IDbContextFactory <PersonalLegacyContext>, InMemoryPersonalLegacyContextFactory>(); var usercontext = new StaticUserContext(new UserContext { UserId = _userId }); sc.Remove <ICurrentUserContext>(); sc.AddScoped <ICurrentUserContext>(i => usercontext); }; _testServer = new TestServerBuilder() .WithPostConfigureCollection(actions) .Build <Startup>(); _client = _testServer.CreateClientWithJwtToken(_customerId, _userId); var fakeCustomerIdService = A.Fake <ICustomerIdService>(); A.CallTo(() => fakeCustomerIdService.GetCustomerIdNotNull()).Returns(_customerId); var personalLegacyFactory = new InMemoryPersonalLegacyContextFactory(fakeCustomerIdService); _personalLegacyDb = await personalLegacyFactory.CreateDbContext(); var personalCommonLegacyFactory = _testServer.Host.Services.GetService <IDbContextFactory <PersonalCommonLegacyContext> >(); _personalCommonLegacyDb = await personalCommonLegacyFactory.CreateDbContext(); }
private static List <Unit> GenerateAndAddCompanies(int numberOfCompanies, PersonalLegacyContext context) { var companies = UnitFactory.GetCompanyFactory(_regionIdHardcoded) .Generate(numberOfCompanies); context.Units.AddRange(companies); context.SaveChanges(); var unitContentBooks = companies.SelectMany(c => new List <UnitContentBook> { new UnitContentBook { UnitId = c.Id, ContentBookId = 1 }, new UnitContentBook { UnitId = c.Id, ContentBookId = 2 }, new UnitContentBook { UnitId = c.Id, ContentBookId = 8 }, }); context.UnitContentBooks.AddRange(unitContentBooks); context.SaveChanges(); return(companies); }
private static List <Employee> GenerateAndAddEmployees(List <int> potentialUnitIds, int numberOfEmployees, PersonalLegacyContext context) { List <int> userIds = null; using (var commonContext = _commonDbFactory.CreateDbContext().Result) { var currentMaxId = commonContext.Users.Max(u => u.UserId.Value); userIds = Enumerable.Range(currentMaxId + 1000, numberOfEmployees).ToList(); var dbId = commonContext.Customers.First(c => c.SticosCustomerId == _customerId).Id; foreach (var userId in userIds) { var users = DbUserFactory .GetFactory(dbId, potentialUnitIds, userId, 8675309 + userId) .Generate(); commonContext.Users.AddRange(users); } commonContext.SaveChanges(); } var employees = EmployeeFactory .GetFactory(potentialUnitIds) .Generate(numberOfEmployees); for (int i = 0; i < employees.Count; i++) { employees[i].UserId = userIds.ElementAt(i); } context.Employees.AddRange(employees); context.SaveChanges(); var employments = employees.Select(e => new Employment { EmployeeId = e.Id, Percentage = 100, StartDate = e.EmployeeStartDate }); context.Employments.AddRange(employments); context.SaveChanges(); return(employees); }
private static void GenerateAndAddAbsences(List <int> employeeIds, int averageNumberOfAbsencesPerEmployeePerYear, int year, PersonalLegacyContext context) { var absences = AbsenceFactory .GetFactory(employeeIds, year) .Generate(employeeIds.Count * averageNumberOfAbsencesPerEmployeePerYear); context.Absences.AddRange(absences); context.SaveChanges(); //while (date.Year <=year) //{ // var absences = AbsenceFactory // .GetFactory(employeeIds, date, date.AddDays(3),seedId++) // .Generate(2); // absences.ForEach(a => a.FromAndToHasTime = a.From > a.From.Date && a.To >a.To.Date); // context.Absences.AddRange(absences); // context.SaveChanges(); // date = date.AddDays(4); //} }
private static List <Unit> GenerateAndAddDepartments(List <int> potentialParentIds, int numberOfDepartments, PersonalLegacyContext context) { var departments = UnitFactory.GetDepartmentFactory(potentialParentIds) .Generate(numberOfDepartments); context.Units.AddRange(departments); context.SaveChanges(); return(departments); }