Пример #1
0
        public void ChangeHistoryEndDateIfItsNotValidTest()
        {
            ParticipationHistoryService participationHistoryService = new ParticipationHistoryService(uow, new Map <ParticipationHistory, ParticipationHistoryDTO>());
            EmployeeService             employeeService             = new EmployeeService(uow, new Map <Employee, EmployeeDTO>());
            ProjectService     projectService     = new ProjectService(uow, new Map <Project, ProjectDTO>());
            ProjectWorkService projectWorkService = new ProjectWorkService(uow, new Map <ProjectWork, ProjectWorkDTO>());
            EmployeeDTO        employee           = new EmployeeDTO
            {
                EmployeeName       = "Екатерина",
                EmployeeSurname    = "Антонович",
                EmployeePatronymic = "Алексеевна",
                RoleId             = 3,
                Email = "*****@*****.**",
            };
            var employeeOnWork = employeeService.CreateEmployee(employee);
            var em             = employeeService.GetEmployeeById(employeeOnWork.Id);

            ProjectDTO project = new ProjectDTO
            {
                ProjectName        = "проект 1",
                ProjectDescription = "проект номер один",
                ProjectStartDate   = new DateTimeOffset(2021, 10, 6, 10, 15, 35, new TimeSpan(3, 0, 0)),
                ProjectEndDate     = new DateTimeOffset(2021, 11, 21, 10, 15, 35, new TimeSpan(3, 0, 0))
            };
            var proj = projectService.CreateProject(project);
            var pr   = projectService.GetProjectById(proj.Id);

            ProjectWorkDTO projectWork = new ProjectWorkDTO
            {
                EmployeeId    = em.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 3
            };
            var pWork = projectWorkService.CreateProjectWork(projectWork);
            var prw   = projectWorkService.GetProjectWorkById(pWork.Id);

            ParticipationHistoryDTO participationHistory = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 10, 16, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 21, 11, 15, 35, new TimeSpan(3, 0, 0))
            };

            var errors  = phvalidator.Validate(participationHistory);
            var history = participationHistoryService.CreateHistory(participationHistory);
            var actual  = participationHistoryService.GetHistoryById(history.Id);

            Assert.ThrowsException <InvalidDateException>(() => participationHistoryService.ChangeHistoryEndDate(actual.Id, new DateTimeOffset(2021, 9, 05, 10, 15, 35, new TimeSpan(3, 0, 0))));

            participationHistoryService.DeleteHistoryById(actual.Id);
            projectWorkService.DeleteProjectWorkById(prw.Id);
            employeeService.DeleteEmployeeById(em.Id);
            projectService.DeleteProjectById(pr.Id);
        }
Пример #2
0
        public void GetLastEmployeesHistoryTest()
        {
            ParticipationHistoryService participationHistoryService = new ParticipationHistoryService(uow, new Map <ParticipationHistory, ParticipationHistoryDTO>());
            EmployeeService             employeeService             = new EmployeeService(uow, new Map <Employee, EmployeeDTO>());
            ProjectService     projectService     = new ProjectService(uow, new Map <Project, ProjectDTO>());
            ProjectWorkService projectWorkService = new ProjectWorkService(uow, new Map <ProjectWork, ProjectWorkDTO>());
            EmployeeDTO        employee           = new EmployeeDTO
            {
                EmployeeName       = "Екатерина",
                EmployeeSurname    = "Антонович",
                EmployeePatronymic = "Алексеевна",
                RoleId             = 3,
                Email = "*****@*****.**",
            };
            var employeeOnWork = employeeService.CreateEmployee(employee);
            var em             = employeeService.GetEmployeeById(employeeOnWork.Id);

            ProjectDTO project = new ProjectDTO
            {
                ProjectName        = "проект 1",
                ProjectDescription = "проект номер один",
                ProjectStartDate   = new DateTimeOffset(2021, 10, 6, 10, 15, 35, new TimeSpan(3, 0, 0)),
                ProjectEndDate     = new DateTimeOffset(2021, 11, 21, 10, 15, 35, new TimeSpan(3, 0, 0))
            };
            var proj = projectService.CreateProject(project);
            var pr   = projectService.GetProjectById(proj.Id);

            ProjectWorkDTO projectWork = new ProjectWorkDTO
            {
                EmployeeId    = em.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 3
            };
            var pWork = projectWorkService.CreateProjectWork(projectWork);
            var prw   = projectWorkService.GetProjectWorkById(pWork.Id);

            ParticipationHistoryDTO participationHistory1 = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 10, 16, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 04, 11, 15, 35, new TimeSpan(3, 0, 0))
            };
            var errors   = phvalidator.Validate(participationHistory1);
            var history1 = participationHistoryService.CreateHistory(participationHistory1);
            var actual1  = participationHistoryService.GetHistoryById(history1.Id);

            ParticipationHistoryDTO participationHistory2 = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 11, 05, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 21, 11, 15, 35, new TimeSpan(3, 0, 0))
            };
            var errors2  = phvalidator.Validate(participationHistory2);
            var history2 = participationHistoryService.CreateHistory(participationHistory2);
            var actual2  = participationHistoryService.GetHistoryById(history2.Id);

            var actual = participationHistoryService.GetLastEmployeesHistory(prw.Id);
            ParticipationHistoryDTO expected = new ParticipationHistoryDTO
            {
                Id            = actual2.Id,
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 11, 05, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 21, 11, 15, 35, new TimeSpan(3, 0, 0))
            };

            Assert.IsTrue(errors.Count == 0 && errors2.Count == 0 && actual.Id == expected.Id && actual.ProjectWorkId == expected.ProjectWorkId &&
                          actual.StartDate == expected.StartDate && actual.EndDate == expected.EndDate);

            participationHistoryService.DeleteHistoryById(actual1.Id);
            participationHistoryService.DeleteHistoryById(actual2.Id);
            projectWorkService.DeleteProjectWorkById(prw.Id);
            employeeService.DeleteEmployeeById(em.Id);
            projectService.DeleteProjectById(pr.Id);
        }
Пример #3
0
        public void GetAllEmployeesHistoriesOnProjectTest()
        {
            ParticipationHistoryService participationHistoryService = new ParticipationHistoryService(uow, new Map <ParticipationHistory, ParticipationHistoryDTO>());
            EmployeeService             employeeService             = new EmployeeService(uow, new Map <Employee, EmployeeDTO>());
            ProjectService     projectService     = new ProjectService(uow, new Map <Project, ProjectDTO>());
            ProjectWorkService projectWorkService = new ProjectWorkService(uow, new Map <ProjectWork, ProjectWorkDTO>());
            EmployeeDTO        employee           = new EmployeeDTO
            {
                EmployeeName       = "Екатерина",
                EmployeeSurname    = "Антонович",
                EmployeePatronymic = "Алексеевна",
                RoleId             = 3,
                Email = "*****@*****.**",
            };
            var employeeOnWork = employeeService.CreateEmployee(employee);
            var em             = employeeService.GetEmployeeById(employeeOnWork.Id);

            EmployeeDTO employee2 = new EmployeeDTO
            {
                EmployeeName       = "Иван",
                EmployeeSurname    = "Иванов",
                EmployeePatronymic = "Иванович",
                RoleId             = 2,
                Email = "*****@*****.**",
            };
            var employeeOnWork2 = employeeService.CreateEmployee(employee2);
            var em2             = employeeService.GetEmployeeById(employeeOnWork2.Id);

            ProjectDTO project = new ProjectDTO
            {
                ProjectName        = "проект 1",
                ProjectDescription = "проект номер один",
                ProjectStartDate   = new DateTimeOffset(2021, 10, 6, 10, 15, 35, new TimeSpan(3, 0, 0)),
                ProjectEndDate     = new DateTimeOffset(2021, 11, 21, 10, 15, 35, new TimeSpan(3, 0, 0))
            };
            var proj = projectService.CreateProject(project);
            var pr   = projectService.GetProjectById(proj.Id);

            ProjectWorkDTO projectWork = new ProjectWorkDTO
            {
                EmployeeId    = em.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 3
            };
            var pWork = projectWorkService.CreateProjectWork(projectWork);
            var prw   = projectWorkService.GetProjectWorkById(pWork.Id);

            ProjectWorkDTO projectWork2 = new ProjectWorkDTO
            {
                EmployeeId    = em2.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 2
            };
            var pWork2 = projectWorkService.CreateProjectWork(projectWork2);
            var prw2   = projectWorkService.GetProjectWorkById(pWork2.Id);

            ParticipationHistoryDTO participationHistory1 = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 10, 16, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 04, 11, 15, 35, new TimeSpan(3, 0, 0))
            };
            var errors   = phvalidator.Validate(participationHistory1);
            var history1 = participationHistoryService.CreateHistory(participationHistory1);
            var actual1  = participationHistoryService.GetHistoryById(history1.Id);

            ParticipationHistoryDTO participationHistory2 = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw.Id,
                StartDate     = new DateTimeOffset(2021, 11, 05, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 21, 11, 15, 35, new TimeSpan(3, 0, 0))
            };
            var errors2  = phvalidator.Validate(participationHistory2);
            var history2 = participationHistoryService.CreateHistory(participationHistory2);
            var actual2  = participationHistoryService.GetHistoryById(history2.Id);

            ParticipationHistoryDTO participationHistory3 = new ParticipationHistoryDTO
            {
                ProjectWorkId = prw2.Id,
                StartDate     = new DateTimeOffset(2021, 11, 05, 10, 15, 35, new TimeSpan(3, 0, 0)),
                EndDate       = new DateTimeOffset(2021, 11, 21, 11, 15, 35, new TimeSpan(3, 0, 0))
            };
            var errors3  = phvalidator.Validate(participationHistory3);
            var history3 = participationHistoryService.CreateHistory(participationHistory3);
            var actual3  = participationHistoryService.GetHistoryById(history3.Id);

            var actual = participationHistoryService.GetAllEmployeesHistoriesOnProject(prw.Id).ToList();

            Assert.AreEqual(actual.Count, 2);

            participationHistoryService.DeleteHistoryById(actual1.Id);
            participationHistoryService.DeleteHistoryById(actual2.Id);
            participationHistoryService.DeleteHistoryById(actual3.Id);
            projectWorkService.DeleteProjectWorkById(prw.Id);
            projectWorkService.DeleteProjectWorkById(prw2.Id);
            employeeService.DeleteEmployeeById(em.Id);
            employeeService.DeleteEmployeeById(em2.Id);
            projectService.DeleteProjectById(pr.Id);
        }