コード例 #1
0
        public async Task TestEmployeeCreateAlreadyExists()
        {
            var employeeToCreate = new EmployeeToCreate {
                FirstName = "Rakshi", MiddleName = "N", LastName = "S", DateOfBirth = DateTime.Now, City = "Bangalore", State = "Karnataka", Country = "India", ZipCode = "560103"
            };

            _repository.Setup(repo => repo.GetEmployeeByNameAsync(It.IsAny <Employee>())).ReturnsAsync(GetTestEmployees().First());
            var employeeController = new EmployeesController(_repository.Object, _mapper);

            var result = await employeeController.CreateEmployee(employeeToCreate);

            Assert.IsInstanceOfType(result.Result, typeof(BadRequestObjectResult));
        }
コード例 #2
0
        public async Task TestEmployeeCreate()
        {
            var employeeToCreate = new EmployeeToCreate {
                FirstName = "Sakshi", MiddleName = "N", LastName = "S", DateOfBirth = DateTime.Now, City = "Bangalore", State = "Karnataka", Country = "India", ZipCode = "560103"
            };
            var CreatedEmployee = new Employee {
                Id = 3, FirstName = "Sakshi", MiddleName = "N", LastName = "S", DateOfBirth = DateTime.Now, City = "Bangalore", State = "Karnataka", Country = "India", ZipCode = "560103"
            };
            Employee emp = null;

            _repository.Setup(repo => repo.GetEmployeeByNameAsync(It.IsAny <Employee>())).ReturnsAsync(emp);
            _repository.Setup(repo => repo.CreateEmployee(It.IsAny <Employee>())).ReturnsAsync(CreatedEmployee);
            var employeeController = new EmployeesController(_repository.Object, _mapper);

            var result = await employeeController.CreateEmployee(employeeToCreate);

            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
            Assert.AreEqual("3", ((result.Result as OkObjectResult).Value as Employee).Id.ToString());
        }