Пример #1
0
        public void DeletePost_CanDelete_ValidCountry()
        {
            // Arrange - create the controller
            CountryController target = new CountryController(mock.Object);

            // Act - call the action method
            var result = (ViewResult)target.DeleteConfirmed(1);

            // Assert - check the result
            mock.Verify(m => m.DeleteCountry(1), Times.Once);
            Assert.AreEqual("Index", result.ViewName);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }
Пример #2
0
        public void DeletePost_CanDelete_ValidCountry()
        {
            // Arrange - create the controller
            CountryController target = new CountryController(mock.Object);

            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)target.DeleteConfirmed(1);

            // Assert - check the result
            mock.Verify(m => m.DeleteCountry(1), Times.Once);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("ABMView", result.RouteValues["action"]);
            Assert.IsNull(result.RouteValues["tab"]);
            Assert.IsFalse(result.Permanent);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
        }
Пример #3
0
        public void DeletePost_CannotDelete_ValidCountry()
        {
            // Arrange - create the controller
            CountryController target = new CountryController(mock.Object);

            mock.Setup(x => x.DeleteCountry(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.DeleteCountry(2), Times.Once);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("DataBaseDeleteError", result.RouteValues["action"]);
        }