public async Task Synchronize_Works_StartWithEmplyDb_HQNotEmpty()
        {
            var cs          = CommonHelpers.MockConfServ(false);
            var hqApiClient = new Moq.Mock <IHQAPIClient>();

            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);

            var hqSalary1 = new HQSalary {
                ID = 1, EmployeeID = 1, Value = 1000, TimePeriod = "01.02.2019-06.02.2019"
            };
            var hqSalary2 = new HQSalary {
                ID = 2, EmployeeID = 1, Value = 1000, TimePeriod = "07.02.2019-09.02.2019"
            };
            var hqSalaries = new List <HQSalary>();

            hqSalaries.Add(hqSalary1);
            hqSalaries.Add(hqSalary2);

            hqApiClient.Setup(m => m.ListEmployees(cs.GetBranchOfficeId())).Returns(
                Task.FromResult(hqEmps)
                );
            hqApiClient.Setup(m => m.ListSalariesForEmployee(1)).Returns(
                Task.FromResult(hqSalaries)
                );

            var dao = new PostgresDataAccessObjectService(dbContext);
            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[0].Email);
            Assert.Equal("*****@*****.**", emps[1].Email);
            Assert.Empty(eh);
            Assert.Equal(2, salaries.Count);
        }
Esempio n. 2
0
        public void Employee_FromHQEmployee()
        {
            var other = new HQEmployee {
                Name           = "Ola Dwa", Email = "*****@*****.**", ID = 0,
                BranchOfficeID = 123, DateOfBirth = "1996-01-25", IsManager = true, Pay = 30
            };
            var obj = new Employee(other);

            Assert.Equal(-1, obj.EmployeeId);
            Assert.Equal("Ola Dwa", obj.Name);
            Assert.Equal("*****@*****.**", obj.Email);
            Assert.True(obj.IsManager);
            Assert.Equal(new DateTime(1996, 1, 25), obj.DateOfBirth);
        }
        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);
        }