Ejemplo n.º 1
0
            public async Task Should_Get_All_Employees()
            {
                //Arrange
                _employeeDataAccessMock.Setup(x => x.GetEmployees()).ReturnsAsync(EmployeesDataMock.AsQueryable());

                //Act
                var employees = await _serviceUnderTest.GetEmployees();

                //Assert
                Assert.True(employees.Any());
            }
Ejemplo n.º 2
0
            public async Task Should_Return_New_EmployeeId(int expectedEmployeeId)
            {
                //Arrange
                var employeeCreate = EmployeesDataMock.FirstOrDefault();

                employeeCreate.Id = expectedEmployeeId;
                //Act
                int actualEmployeeId = await _dataAccessUnderTest.CreateEmployee(employeeCreate);

                //Assert
                Assert.Equal(expectedEmployeeId, actualEmployeeId);
            }
Ejemplo n.º 3
0
            public async Task Should_Return_BadRequest_Result(int employeeId)
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployeeById(employeeId))
                .ReturnsAsync(EmployeesDataMock.FirstOrDefault(x => x.Id == employeeId));

                //Act
                var actionResult = await _controllerUnderTest.GetEmployeeById(employeeId);

                //Assert
                Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
                Assert.IsNotNull(((BadRequestObjectResult)actionResult).Value);
            }
Ejemplo n.º 4
0
            public async Task Should_Get_Employee_By_Id(int employeeId)
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployeeById(employeeId))
                .ReturnsAsync(EmployeesDataMock.FirstOrDefault(x => x.Id == employeeId));

                //Act
                var actionResult = await _controllerUnderTest.GetEmployeeById(employeeId);

                //Assert
                Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult));
                Assert.AreEqual(employeeId, ((Employees)((OkObjectResult)actionResult).Value).Id);
            }
Ejemplo n.º 5
0
            public async Task Should_Get_All_Employees()
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployees()).ReturnsAsync(EmployeesDataMock.AsQueryable());

                //Act
                var result = await _controllerUnderTest.GetEmployees();

                //Assert
                Assert.IsInstanceOfType(result, typeof(OkObjectResult));
                Assert.IsNotNull(((OkObjectResult)result).Value);
                Assert.IsTrue(((IEnumerable <Employees>)((OkObjectResult)result).Value).Any());
            }
Ejemplo n.º 6
0
            public async Task Should_Return_Delete_Status(int employeeId, bool?expectedResult)
            {
                //Arrange
                _employeeDataAccessMock.Setup(x => x.GetEmployees()).ReturnsAsync(EmployeesDataMock.AsQueryable());
                _employeeDataAccessMock.Setup(x => x.DeleteEmployee(employeeId))
                .ReturnsAsync(Convert.ToBoolean(expectedResult));

                //Act
                bool?actualResult = await _serviceUnderTest.DeleteEmployee(employeeId);

                //Assert
                Assert.Equal(expectedResult, actualResult);
            }
Ejemplo n.º 7
0
            public async Task Should_Return_BadRequest_Result(int employeeId)
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployeeById(employeeId))
                .ReturnsAsync(EmployeesDataMock.FirstOrDefault(x => x.Id == employeeId));

                //Act
                var actionResult = await _controllerUnderTest.GetEmployeeById(employeeId);

                //Assert
                var result = Assert.IsType <BadRequestObjectResult>(actionResult);

                Assert.NotNull(result.Value);
            }
Ejemplo n.º 8
0
            public async Task Should_Get_Employee_By_Id(int employeeId)
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployeeById(employeeId))
                .ReturnsAsync(EmployeesDataMock.FirstOrDefault(x => x.Id == employeeId));

                //Act
                var actionResult = await _controllerUnderTest.GetEmployeeById(employeeId);

                //Assert
                var result = Assert.IsType <OkObjectResult>(actionResult);

                Assert.Equal(employeeId, ((Employees)result.Value).Id);
            }
Ejemplo n.º 9
0
            public async Task Should_Get_All_Employees()
            {
                //Arrange
                _employeeServiceMock.Setup(x => x.GetEmployees()).ReturnsAsync(EmployeesDataMock.AsQueryable());

                //Act
                var result = await _controllerUnderTest.GetEmployees();

                //Assert
                var okObjectResult = Assert.IsType <OkObjectResult>(result);

                Assert.NotNull(okObjectResult.Value);
                Assert.True(((IEnumerable <Employees>)okObjectResult.Value).Any());
            }
Ejemplo n.º 10
0
            public async Task Should_Return_Employee_Data(int employeeId, int?expectedResult)
            {
                //Assert
                _employeeDataAccessMock.Setup(x => x.GetEmployees()).ReturnsAsync(EmployeesDataMock.AsQueryable());

                //Act
                var actualResult = await _serviceUnderTest.GetEmployeeById(employeeId);

                //Assert
                if (expectedResult == null)
                {
                    Assert.Null(actualResult);
                }
                else
                {
                    Assert.Equal(employeeId, actualResult.Id);
                }
            }