public ProjectsController(IProjectsService projectsService, IEmployeesService employeesService, IEmployeesProjectsPositionsService employeesProjectsPositionsService, IProjectPositionsService projectPositionsService)
 {
     this.projectsService  = projectsService;
     this.employeesService = employeesService;
     this.employeesProjectsPositionsService = employeesProjectsPositionsService;
     this.projectPositionsService           = projectPositionsService;
 }
        public async Task AddParticipantsAsync_WithValidData_ShouldAddProjectParticipantsAndReturnTrue()
        {
            string errorMessagePrefix = "EmployeesProjectsPositions AddParticipantsAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            List <EmployeesProjectsPositions> newEntities = new List <EmployeesProjectsPositions>
            {
                new EmployeesProjectsPositions {
                    EmployeeId = Employee_Id_4, ProjectId = Project_Id_1, ProjectPositionId = ProjectPosition_Id_2
                },
                new EmployeesProjectsPositions {
                    EmployeeId = Employee_Id_5, ProjectId = Project_Id_1, ProjectPositionId = ProjectPosition_Id_3
                },
            };

            List <ProjectEditParticipantDto> entitiesToAdd = newEntities.To <ProjectEditParticipantDto>().ToList();

            var expectedCount = context.EmployeesProjectsRoles.Count() + entitiesToAdd.Count;

            bool result = await this.employeesProjectsPositionsService.AddParticipantsAsync(entitiesToAdd);

            var actualCount = context.EmployeesProjectsRoles.Count();

            Assert.True(result, errorMessagePrefix);
            Assert.True(expectedCount == actualCount, errorMessagePrefix);
        }
Exemplo n.º 3
0
 public ProjectsService(OmmDbContext context, IReportsService reportsService, IStatusesService statusesService,
                        IEmployeesService employeesService, IProjectPositionsService projectPositionsService,
                        IEmployeesProjectsPositionsService employeesProjectsPositionsService, IAssignmentsService assignmentsService)
 {
     this.context                           = context;
     this.reportsService                    = reportsService;
     this.statusesService                   = statusesService;
     this.employeesService                  = employeesService;
     this.projectPositionsService           = projectPositionsService;
     this.employeesProjectsPositionsService = employeesProjectsPositionsService;
     this.assignmentsService                = assignmentsService;
 }
        public async Task RemoveParticipantsAsync_WithEmptyData_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            string invalidId = "Invalid id";

            List <ProjectEditParticipantDto> entitiesToRemove = GetEmployeeProjectsPositionsDummyData().Where(epp => epp.ProjectId == invalidId).To <ProjectEditParticipantDto>().ToList();

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.RemoveParticipantsAsync(entitiesToRemove));

            Assert.Equal(ErrorMessages.ProjectParticipantsToRemoveNullReference, ex.Message);
        }
        public async Task RemoveParticipantAsync_WithInvalidProjectId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto entityToRemove = (await context.EmployeesProjectsRoles.FirstAsync()).To <ProjectParticipantChangeDto>();

            entityToRemove.ProjectId = "Invalid id";

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.RemoveParticipantAsync(entityToRemove));

            Assert.Equal(ErrorMessages.ProjectParticipantNullReference, ex.Message);
        }
        public async Task ChangeEmployeeProjectPositionAsync_WithInvalidProjectPositionId_ShouldThrowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto expectedResult = GetEmployeeProjectsPositionsDummyData().First().To <ProjectParticipantChangeDto>();
            int invalidProjectPositionId = 22;

            expectedResult.ProjectPositionId = invalidProjectPositionId;

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.employeesProjectsPositionsService.ChangeEmployeeProjectPositionAsync(expectedResult));

            Assert.Equal(string.Format(ErrorMessages.ProjectPositionNullReference, invalidProjectPositionId), ex.Message);
        }
        public async Task RemoveParticipantsAsync_WithValidData_ShouldRemoveProjectParticipantsAndReturnTrue()
        {
            string errorMessagePrefix = "EmployeesProjectsPositions RemoveParticipantsAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            List <ProjectEditParticipantDto> entitiesToRemove = GetEmployeeProjectsPositionsDummyData().Where(epp => epp.ProjectId == Project_Id_1).To <ProjectEditParticipantDto>().ToList();
            var expectedCount = context.EmployeesProjectsRoles.Count() - entitiesToRemove.Count;

            bool result = await this.employeesProjectsPositionsService.RemoveParticipantsAsync(entitiesToRemove);

            var actualCount = context.EmployeesProjectsRoles.Count();

            Assert.True(result, errorMessagePrefix);
            Assert.True(expectedCount == actualCount, errorMessagePrefix);
        }
        public async Task RemoveParticipantAsync_WithValidData_ShouldRemoveProjectParticipantAndReturnTrue()
        {
            string errorMessagePrefix = "EmployeesProjectsPositions RemoveParticipantAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto entityToRemove = (await context.EmployeesProjectsRoles.FirstAsync()).To <ProjectParticipantChangeDto>();
            var expectedCount = context.EmployeesProjectsRoles.Count() - 1;

            bool result = await this.employeesProjectsPositionsService.RemoveParticipantAsync(entityToRemove);

            var actualCount = context.EmployeesProjectsRoles.Count();

            Assert.True(result, errorMessagePrefix);
            Assert.True(expectedCount == actualCount, errorMessagePrefix);
        }
        public async Task ChangeEmployeeProjectPositionAsync_WithValidData_ShouldChangeProjectPositionAndReturnTrue()
        {
            string errorMessagePrefix = "EmployeesProjectsPositions ChangeEmployeeProjectPositionAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.employeesProjectsPositionsService = new EmployeesProjectsPositionsService(context);

            ProjectParticipantChangeDto expectedResult = GetEmployeeProjectsPositionsDummyData().First().To <ProjectParticipantChangeDto>();

            expectedResult.ProjectPositionId = ProjectPosition_Id_2;

            bool returnResult = await this.employeesProjectsPositionsService.ChangeEmployeeProjectPositionAsync(expectedResult);

            ProjectParticipantChangeDto actualResult = (await context.EmployeesProjectsRoles.FirstAsync()).To <ProjectParticipantChangeDto>();

            Assert.True(expectedResult.EmployeeId == actualResult.EmployeeId, errorMessagePrefix + " " + "EmployeeId is not returned properly.");
            Assert.True(expectedResult.ProjectId == actualResult.ProjectId, errorMessagePrefix + " " + "ProjectId is not returned properly.");
            Assert.True(expectedResult.ProjectPositionId == actualResult.ProjectPositionId, errorMessagePrefix + " " + "ProjectPositionId is not changed properly.");

            Assert.True(returnResult, errorMessagePrefix);
        }