public void DeletePost_CanDelete_ValidHoliday() { // Arrange - create the controller HolidayController target = new HolidayController(mock.Object); // Act - call the action method var result = (ViewResult)target.DeleteConfirmed(1); // Assert - check the result mock.Verify(m => m.DeleteHoliday(1), Times.Once); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.IsInstanceOf(typeof(List <Holiday>), result.ViewData.Model); }
public void DeletePost_CanDelete_ValidHoliday() { // Arrange - create the controller HolidayController target = new HolidayController(mock.Object); // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(1); // Assert - check the result mock.Verify(m => m.DeleteHoliday(1), Times.Once); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("ABMView", result.RouteValues["action"]); Assert.IsNotNull(result.RouteValues["tab"]); Assert.IsFalse(result.Permanent); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); }
public void DeletePost_CannotDelete_ValidHoliday() { // Arrange - create the controller HolidayController target = new HolidayController(mock.Object); mock.Setup(x => x.DeleteHoliday(It.IsAny <int>())) .Callback(() => { throw new System.Data.Entity.Infrastructure.DbUpdateException(); }); // Act - call the action method RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(2); // Assert - check the result mock.Verify(m => m.DeleteHoliday(2), Times.Once); Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); Assert.AreEqual("Home", result.RouteValues["controller"]); Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]); }