Esempio n. 1
0
        public async Task DeleteConfirmed_Post_RedirectToIndex()
        {
            Mock <EmployeeService> mock       = new Mock <EmployeeService>();
            EmployeeController     controller = GetNewEmployeeController(mock.Object, null, null);

            RedirectToRouteResult result = (await controller.DeleteConfirmed(1)) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void DeletePost_IdSelectedDepartmentNull_RedirectToPUView()
        {
            // Arrange
            //List<Employee> empList = mock.Object.Employees.ToList();
            EmployeeController controller         = new EmployeeController(mock.Object);
            string             selectedDepartment = null;

            // Act
            var result = controller.DeleteConfirmed(3, selectedDepartment);


            // Assert
            mock.Verify(m => m.DeleteEmployee(3), Times.Once);
            Assert.AreEqual(((ViewResult)result).GetType(), typeof(ViewResult));
            Assert.AreEqual(((ViewResult)result).ViewName, "OneRowPU");
        }
        public void DeletePost_CannotDelete_DataBaseDeleteError()
        {
            // Arrange - create the controller
            EmployeeController controller = new EmployeeController(mock.Object);

            mock.Setup(x => x.DeleteEmployee(It.IsAny <int>()))
            .Callback(() => { throw new System.Data.Entity.Infrastructure.DbUpdateException(); });


            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)controller.DeleteConfirmed(2);

            // Assert - check the result
            mock.Verify(m => m.DeleteEmployee(2), Times.Once);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]);
        }
Esempio n. 4
0
        public void DeleteConfirmedTest()
        {
            ActionResult result = employeeController.DeleteConfirmed(1);

            Assert.IsNotNull(result);
        }