Esempio n. 1
0
        public void CreateEmployeeForCompany_ValidInputCreatesEmployeeyAndReturnsAnOkResult_WithAnEmployee()
        {
            // Arrange
            var  existingCompany = SeedTestData.GetTestCompany();
            Guid companyId       = existingCompany.Id;
            var  testEmployee    = SeedTestData.GetTestEmployee();

            mockRepo.Setup(repo => repo.Company.GetCompany(companyId, false)).Returns(existingCompany).Verifiable();
            mockRepo.Setup(repo => repo.Employee.CreateEmployeeForCompany(companyId, It.IsAny <Employee>()))
            .Verifiable();
            var controller = new EmployeesController(mockRepo.Object, _mapper);
            EmployeeForCreationDto newEmployeeDto = new EmployeeForCreationDto()
            {
                Name     = testEmployee.Name,
                Age      = testEmployee.Age,
                Position = testEmployee.Position
            };
            // Act
            var result = controller.CreateEmployeeForCompany(companyId, newEmployeeDto);

            // Assert
            Assert.IsInstanceOf <OkObjectResult>(result);
            var okResult = result as OkObjectResult;

            Assert.That(okResult.Value, Is.TypeOf <Employee>());
            Employee resultEmp = okResult.Value as Employee;

            Assert.AreEqual(resultEmp.Name, newEmployeeDto.Name);
            Assert.AreEqual(resultEmp.Age, newEmployeeDto.Age);
            Assert.AreEqual(resultEmp.Position, newEmployeeDto.Position);
            mockRepo.Verify(repo => repo.Company.GetCompany(companyId, false), Times.Once);
            mockRepo.Verify();
        }
Esempio n. 2
0
        public void CreateEmployeeForCompany__InValidInputNull_ReturnsBadRequestObjectResult()
        {
            // Arrange
            var  existingCompany = SeedTestData.GetTestCompany();
            Guid companyId       = existingCompany.Id;
            var  controller      = new EmployeesController(mockRepo.Object, _mapper);
            EmployeeForCreationDto newEmployeeDto = null;
            // Act
            var result = controller.CreateEmployeeForCompany(companyId, newEmployeeDto);

            // Assert
            Assert.IsInstanceOf <BadRequestObjectResult>(result);

            mockRepo.Verify(repo => repo.Employee.CreateEmployeeForCompany(companyId, It.IsAny <Employee>()), Times.Never);
        }