public async Task CreateWithAssistantsIds_WithValidData_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "AssignmentEmployeesService CreateWithAssistantsIds() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            List <string> employeesIdsToCreateAssignmentWith = new List <string> {
                Employee_Id_3, Employee_Id_4
            };

            var expectedCount = employeesIdsToCreateAssignmentWith.Count;

            List <AssignmentsEmployees> actualResult = this.assignmentsEmployeesService.CreateWithAssistantsIds(employeesIdsToCreateAssignmentWith).ToList();

            var actualCount = actualResult.Count;

            for (int i = 0; i < expectedCount; i++)
            {
                Assert.True(employeesIdsToCreateAssignmentWith[i] == actualResult[i].AssistantId, errorMessagePrefix + " " + "Assistant not created correctly!");
            }
            Assert.True(expectedCount == actualCount, errorMessagePrefix + " " + "Assistants were not added correctly!");
        }
        public async Task AddAssistantsAsync_WithExistendAssistantId_ShouldThowArgumentException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            List <string> employeesIdsToAddToAssignment = new List <string> {
                Employee_Id_3, Employee_Id_1
            };

            var ex = await Assert.ThrowsAsync <ArgumentException>(() => this.assignmentsEmployeesService.AddAssistantsAsync(employeesIdsToAddToAssignment, Assignment_Id_1));

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

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            string invalidAssistantId = "Invalid id";

            List <string> employeesIdsToRemoveFromAssignment = new List <string> {
                invalidAssistantId, Employee_Id_2
            };

            var ex = await Assert.ThrowsAsync <NullReferenceException>(() => this.assignmentsEmployeesService.RemoveAssistantsAsync(employeesIdsToRemoveFromAssignment, Assignment_Id_1));

            Assert.Equal(string.Format(ErrorMessages.EmployeeIdNullReference, invalidAssistantId), ex.Message);
        }
        public async Task CreateWithAssistantsIds_WithInvalidAssistantId_ShouldThowNullReferenceException()
        {
            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            string invalidId = "Invalid id";

            List <string> employeesIdsToCreateAssignmentWith = new List <string> {
                invalidId, Employee_Id_4
            };

            var ex = Assert.Throws <NullReferenceException>(() => this.assignmentsEmployeesService.CreateWithAssistantsIds(employeesIdsToCreateAssignmentWith));

            Assert.Equal(string.Format(ErrorMessages.EmployeeIdNullReference, invalidId), ex.Message);
        }
        public async Task RemoveAssistantsAsync_WithValidData_ShouldRemoveAssistantsFromAssignmentAndReturnTrue()
        {
            string errorMessagePrefix = "AssignmentEmployeesService RemoveAssistantsAsync() method does not work properly.";

            var context = OmmDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            this.assignmentsEmployeesService = new AssignmentsEmployeesService(context);

            List <string> employeesIdsToRemoveFromAssignment = new List <string> {
                Employee_Id_1, Employee_Id_2
            };

            var expectedCount = context.AssignmentsEmployees.Count() - employeesIdsToRemoveFromAssignment.Count;

            var result = await this.assignmentsEmployeesService.RemoveAssistantsAsync(employeesIdsToRemoveFromAssignment, Assignment_Id_1);

            var actualCount = context.AssignmentsEmployees.Count();

            Assert.True(result, errorMessagePrefix);
            Assert.True(expectedCount == actualCount, errorMessagePrefix + " " + "Assistants were not removed correctly!");
        }
 public AssignmentsService(OmmDbContext context, IStatusesService statusesService, IAssignmentsEmployeesService assignmentsEmployeesService)
 {
     this.context                     = context;
     this.statusesService             = statusesService;
     this.assignmentsEmployeesService = assignmentsEmployeesService;
 }