コード例 #1
0
        public void DeletePost_CanDelete_ValidGreeting()
        {
            // Arrange - create the controller
            GreetingController target = new GreetingController(mock.Object);

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

            // Assert - check the result
            mock.Verify(m => m.DeleteGreeting(1), Times.Once);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("BDMView", result.RouteValues["action"]);
            Assert.IsNull(result.RouteValues["tab"]);
            Assert.IsFalse(result.Permanent);
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
        }
コード例 #2
0
        public void DeletePost_CannotDelete_ValidGreeting()
        {
            // Arrange - create the controller
            GreetingController target = new GreetingController(mock.Object);

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