public async Task AddEmployeeHours_Fails_WhenAddedAlreadyWithTheSameTimePeriodEndEmployeeId() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }); await dbContext.SaveChangesAsync(); var eh = new EmployeeHours { EmployeeHoursId = 101, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }; var dao = new PostgresDataAccessObjectService(dbContext); bool exThrown = false; try { exThrown = true; dao.AddEmployeeHours(eh); } catch (Exception e) { Assert.Equal(typeof(ArgumentException), e.GetType()); Assert.Equal("EmployeeHours with EmployeeId: 4 and TimePeriod 02.01.2019_08.01.2019 already exists", e.Message); } var coll = dao.GetEmployeeHoursForAnEmployee(4); Assert.Single(coll); Assert.True(exThrown); }
public async Task AddEmployeeHours_WhenNotEmptyTable_KeepId_ConflictingKeyValues() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 100, Value = 100, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }); await dbContext.SaveChangesAsync(); var emp = new EmployeeHours { EmployeeHoursId = 100, Value = 100, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }; var dao = new PostgresDataAccessObjectService(dbContext); bool exThrown = false; try { exThrown = true; dao.AddEmployeeHours(emp, true); } catch (Exception ex) { Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Equal("EmployeeHours with EmployeeHoursId: 100 already exists", ex.Message); } Assert.True(exThrown); }
public async Task AddEmployeeHours_WhenNotEmptyTable() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }); await dbContext.SaveChangesAsync(); var eh = new EmployeeHours(); eh.EmployeeId = 4; eh.Value = 90; eh.TimePeriod = "02.03.2019_08.03.2019"; var dao = new PostgresDataAccessObjectService(dbContext); dao.AddEmployeeHours(eh); var coll = dao.GetEmployeeHoursForAnEmployee(4); Assert.Equal(2, coll.Count); Assert.Equal(100f, coll[0].Value); Assert.Equal(90f, coll[1].Value); Assert.Equal(100, coll[0].EmployeeHoursId); Assert.Equal(101, coll[1].EmployeeHoursId); }
public async Task AddEmployeeHours_WhenNotEmptyTable_Many() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 }); await dbContext.Employees.AddAsync(new Employee { Name = "Ola 2", Email = "*****@*****.**", EmployeeId = 5 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 101, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 4 }); await dbContext.EmployeeHoursCollection.AddAsync( new EmployeeHours { EmployeeHoursId = 102, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 5 }); await dbContext.SaveChangesAsync(); var dao = new PostgresDataAccessObjectService(dbContext); // the EmployeeHoursId is generated anyways dao.AddEmployeeHours( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "01.01.2019_02.01.2019", EmployeeId = 4 }); dao.AddEmployeeHours( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "09.01.2019_13.01.2019", EmployeeId = 4 }); dao.AddEmployeeHours( new EmployeeHours { EmployeeHoursId = 100, Value = 100f, TimePeriod = "01.01.2019_02.01.2019", EmployeeId = 5 }); var coll = dao.GetEmployeeHoursForAnEmployee(4); Assert.Equal(4, coll.Count); }
public async Task AddEmployeeHours_WhenEmployeeIdNotSet() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 9 }); await dbContext.SaveChangesAsync(); var eh = new EmployeeHours(); eh.Value = 90; eh.TimePeriod = "02.03.2019_08.03.2019"; var dao = new PostgresDataAccessObjectService(dbContext); bool exThrown = false; try { exThrown = true; dao.AddEmployeeHours(eh); } catch (Exception e) { Assert.Equal(typeof(ArgumentException), e.GetType()); Assert.Equal("EmployeeId was not set", e.Message); } Assert.True(exThrown); }
public async Task AddEmployeeHours_WhenEmptyTable() { await dbContext.Employees.AddAsync(new Employee { Name = "Ola AAA", Email = "*****@*****.**", EmployeeId = 4 }); await dbContext.SaveChangesAsync(); var eh = new EmployeeHours(); eh.EmployeeId = 4; eh.Value = 90; eh.TimePeriod = "02.03.2019_08.03.2019"; var dao = new PostgresDataAccessObjectService(dbContext); dao.AddEmployeeHours(eh); var coll = dao.GetEmployeeHoursForAnEmployee(4); Assert.Single(coll); Assert.Equal(90f, coll[0].Value); // apparently we must start from 1 Assert.Equal(1, coll[0].EmployeeHoursId); }
public async Task Synchronize_Works_StartWithNotEmplyDb_HQNotEmpty() { var cs = CommonHelpers.MockConfServ(false); var hqApiClient = new Moq.Mock <IHQAPIClient>(); // setup HQ state var hqEmp1 = new HQEmployee { Name = "Jan K", Email = "*****@*****.**", IsManager = false, ID = 1 }; var hqEmp2 = new HQEmployee { Name = "Ela K", Email = "*****@*****.**", IsManager = true, ID = 2 }; var hqEmps = new List <HQEmployee>(); hqEmps.Add(hqEmp1); hqEmps.Add(hqEmp2); hqApiClient.Setup(m => m.ListEmployees(cs.GetBranchOfficeId())).Returns( Task.FromResult(hqEmps) ); var hqSalary1 = new HQSalary { ID = 1, EmployeeID = 1, Value = 1000, TimePeriod = "hqsalary1" }; var hqSalary2 = new HQSalary { ID = 2, EmployeeID = 1, Value = 1000, TimePeriod = "hqsalary2" }; var hqSalaries = new List <HQSalary>(); hqSalaries.Add(hqSalary1); hqSalaries.Add(hqSalary2); hqApiClient.Setup(m => m.ListSalariesForEmployee(1)).Returns( Task.FromResult(hqSalaries) ); var dao = new PostgresDataAccessObjectService(dbContext); // setup BO state var boEmp1 = new Employee { Name = "BO Employee1", Email = "*****@*****.**", EmployeeId = 4 }; // will be deleted var boEmp2 = new Employee { Name = "Ela K", Email = "*****@*****.**", EmployeeId = 5, IsManager = true }; dao.AddEmployee(boEmp1, true); dao.AddEmployee(boEmp2, true); var eh1 = new EmployeeHours { EmployeeHoursId = 102, Value = 100f, TimePeriod = "01.01.2019_01.01.2019", EmployeeId = 4 }; // will be deleted var eh2 = new EmployeeHours { EmployeeHoursId = 103, Value = 100f, TimePeriod = "02.01.2019_02.01.2019", EmployeeId = 4 }; // will be deleted var eh3 = new EmployeeHours { EmployeeHoursId = 104, Value = 100f, TimePeriod = "03.01.2019_03.01.2019", EmployeeId = 4 }; // will be deleted var eh4 = new EmployeeHours { EmployeeHoursId = 105, Value = 100f, TimePeriod = "02.01.2019_08.01.2019", EmployeeId = 5 }; dao.AddEmployeeHours(eh1, true); dao.AddEmployeeHours(eh2, true); dao.AddEmployeeHours(eh3, true); dao.AddEmployeeHours(eh4, true); var salary1 = new Salary { SalaryId = 1, EmployeeId = 4, TimePeriod = "bosalary1", Value = 111 }; // will be deleted var salary2 = new Salary { SalaryId = 2, EmployeeId = 4, TimePeriod = "bosalary2", Value = 222 }; // will be deleted var salary3 = new Salary { SalaryId = 3, EmployeeId = 5, TimePeriod = "bosalary3", Value = 333 }; dao.AddSalary(salary1, true); dao.AddSalary(salary2, true); dao.AddSalary(salary3, true); var ss = new SynchronizatorService(hqApiClient.Object, cs, dao); await ss.Synchronize(); hqApiClient.Verify(m => m.ListEmployees(0), Moq.Times.Once); // 1 for each hq employee hqApiClient.Verify(m => m.ListSalariesForEmployee(Moq.It.IsAny <int>()), Moq.Times.Exactly(2)); ss.Dispose(); var emps = dao.GetAllEmployees(); var eh = dao.GetAllEmployeeHours(); var salaries = dao.GetAllSalaries(); Assert.Equal(2, emps.Count); Assert.Equal("*****@*****.**", emps[1].Email); Assert.Equal("*****@*****.**", emps[0].Email); Assert.Single(eh); Assert.Equal(105, eh[0].EmployeeHoursId); Assert.Equal(3, salaries.Count); }