示例#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());
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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());
            }
示例#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);
            }
示例#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);
            }
示例#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);
            }
示例#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());
            }
示例#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);
                }
            }