Exemple #1
0
        public void ChangeWorkLoadIfItsSchedule()
        {
            EmployeeService    employeeService    = new EmployeeService(uow, new Map <Employee, EmployeeDTO>());
            ProjectService     projectService     = new ProjectService(uow, new Map <Project, ProjectDTO>());
            ScheduleServise    scheduleServise    = new ScheduleServise(uow, new Map <Schedule, ScheduleDTO>(), new Map <ScheduleDay, ScheduleDayDTO>());
            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, 10, 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 pw     = projectWorkService.GetProjectWorkById(pWork.Id);
            var actual = projectWorkService.GetProjectWorkById(pw.Id);

            scheduleServise.CreateSchedule(new ScheduleDTO {
                ProjectWorkId = actual.Id, ScheduleDayId = 2
            });
            scheduleServise.CreateSchedule(new ScheduleDTO {
                ProjectWorkId = actual.Id, ScheduleDayId = 4
            });

            Assert.ThrowsException <PercentOrScheduleException>(() => employeeService.ChangeWorkLoad(em.Id, 1));

            projectWorkService.DeleteProjectWorkById(actual.Id);
            employeeService.DeleteEmployeeById(em.Id);
            projectService.DeleteProjectById(pr.Id);
        }
        public void CreateScheduleTest()
        {
            ScheduleServise    scheduleServise    = new ScheduleServise(uow, new Map <Schedule, ScheduleDTO>(), new Map <ScheduleDay, ScheduleDayDTO>());
            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, 10, 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);

            ScheduleDTO schedule = new ScheduleDTO
            {
                ProjectWorkId = prw.Id,
                ScheduleDayId = 1
            };

            var         sch      = scheduleServise.CreateSchedule(schedule);
            ScheduleDTO actual   = scheduleServise.GetScheduleById(sch.Id);
            ScheduleDTO expected = new ScheduleDTO
            {
                Id            = actual.Id,
                ProjectWorkId = prw.Id,
                ScheduleDayId = 1
            };

            Assert.IsTrue(actual.Id == expected.Id && actual.ProjectWorkId == expected.ProjectWorkId &&
                          actual.ScheduleDayId == expected.ScheduleDayId);

            scheduleServise.DeleteScheduleById(actual.Id);
            projectWorkService.DeleteProjectWorkById(prw.Id);
            employeeService.DeleteEmployeeById(em.Id);
            projectService.DeleteProjectById(pr.Id);
        }
        public void DeleteScheduleByProjectWorkIdTest()
        {
            ScheduleServise    scheduleServise    = new ScheduleServise(uow, new Map <Schedule, ScheduleDTO>(), new Map <ScheduleDay, ScheduleDayDTO>());
            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, 10, 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);

            ScheduleDTO schedule1 = new ScheduleDTO
            {
                ProjectWorkId = prw.Id,
                ScheduleDayId = 1
            };

            var         sch1    = scheduleServise.CreateSchedule(schedule1);
            ScheduleDTO actual1 = scheduleServise.GetScheduleById(sch1.Id);

            ScheduleDTO schedule2 = new ScheduleDTO
            {
                ProjectWorkId = prw.Id,
                ScheduleDayId = 3
            };

            var         sch2    = scheduleServise.CreateSchedule(schedule2);
            ScheduleDTO actual2 = scheduleServise.GetScheduleById(sch2.Id);

            scheduleServise.DeleteScheduleByProjectWorkId(prw.Id);

            Assert.ThrowsException <NotFoundException>(() => scheduleServise.GetScheduleOnProjectWork(prw.Id));

            projectWorkService.DeleteProjectWorkById(prw.Id);
            employeeService.DeleteEmployeeById(em.Id);
            projectService.DeleteProjectById(pr.Id);
        }
        public void GetNamesOnProjectTest()
        {
            ScheduleServise    scheduleServise    = new ScheduleServise(uow, new Map <Schedule, ScheduleDTO>(), new Map <ScheduleDay, ScheduleDayDTO>());
            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        employee1          = new EmployeeDTO
            {
                EmployeeName       = "Екатерина",
                EmployeeSurname    = "Антонович",
                EmployeePatronymic = "Алексеевна",
                RoleId             = 3,
                Email = "*****@*****.**",
            };
            var employeeOnWork1 = employeeService.CreateEmployee(employee1);
            var em1             = employeeService.GetEmployeeById(employeeOnWork1.Id);

            EmployeeDTO employee2 = new EmployeeDTO
            {
                EmployeeName       = "Иван",
                EmployeeSurname    = "Иванов",
                EmployeePatronymic = "Иванович",
                RoleId             = 3,
                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, 10, 21, 10, 15, 35, new TimeSpan(3, 0, 0))
            };
            var proj = projectService.CreateProject(project);
            var pr   = projectService.GetProjectById(proj.Id);

            ProjectWorkDTO projectWork1 = new ProjectWorkDTO
            {
                EmployeeId    = em1.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 3
            };
            var errors1 = pwvalidator.Validate(projectWork1);
            var pWork1  = projectWorkService.CreateProjectWork(projectWork1);
            var actual1 = projectWorkService.GetProjectWorkById(pWork1.Id);

            projectWorkService.AddWorkLoad(actual1.Id, 50);

            ProjectWorkDTO projectWork2 = new ProjectWorkDTO
            {
                EmployeeId    = em2.Id,
                ProjectId     = pr.Id,
                ProjectRoleId = 5
            };
            var errors2 = pwvalidator.Validate(projectWork2);
            var pWork2  = projectWorkService.CreateProjectWork(projectWork2);
            var actual2 = projectWorkService.GetProjectWorkById(pWork2.Id);

            scheduleServise.CreateSchedule(new ScheduleDTO {
                ProjectWorkId = actual2.Id, ScheduleDayId = 2
            });
            scheduleServise.CreateSchedule(new ScheduleDTO {
                ProjectWorkId = actual2.Id, ScheduleDayId = 4
            });

            var result = projectWorkService.GetNamesOnProject(pr.Id).ToList();

            Assert.IsTrue(result.First().name == "Антонович Екатерина Алексеевна" && result.Last().name == "Иванов Иван Иванович");

            projectWorkService.DeleteProjectWorkById(actual1.Id);
            projectWorkService.DeleteProjectWorkById(actual2.Id);
            employeeService.DeleteEmployeeById(em1.Id);
            employeeService.DeleteEmployeeById(em2.Id);
            projectService.DeleteProjectById(pr.Id);
        }