Delete() private method

private Delete ( int id ) : System.Web.Mvc.ActionResult
id int
return System.Web.Mvc.ActionResult
示例#1
0
        public void Delete_Method_Should_Return_Httpnotfoubdresult()
        {
            // Arrange
            FunctionalTestHelper.CreateAccountAndBlog(_dbContext);
            FunctionalTestHelper.CreateOnePost(_dbContext);

            // Act
            _controller = new PostController();
            var result = _controller.Delete(1000) as HttpNotFoundResult;

            // Assert
            result.ShouldNotBeNull();
            result.ShouldBeOfType(typeof(HttpNotFoundResult));
        }
示例#2
0
        public void Delete_Method_Should_Delete_Post()
        {
            // Arrange
            FunctionalTestHelper.CreateAccountAndBlog(_dbContext);
            FunctionalTestHelper.CreateOnePost(_dbContext);

            _controller = new PostController();
            _controller.SetFakeControllerContext();

            // Act
            var result = _controller.Delete(1) as RedirectToRouteResult;

            // Assert
            result.RouteValues["controller"].ShouldEqual("Home");
            result.RouteValues["action"].ShouldEqual("Index");

            _dbContext.Posts.Count().ShouldEqual(0);
        }
示例#3
0
        public void Delete_Method_Should_Delete_Post_Via_Ajax()
        {
            // Arrange
            FunctionalTestHelper.CreateAccountAndBlog(_dbContext);
            FunctionalTestHelper.CreateOnePost(_dbContext);

            _controller = new PostController();
            _controller.SetFakeControllerContext(isAjaxRequest:true);

            // Act
            var result = _controller.Delete(1) as JsonResult;

            // Assert
            var serializer = new JavaScriptSerializer();
            var output = serializer.Serialize(result.Data);
            Assert.AreEqual(@"{""success"":true}", output);

            _dbContext.Posts.Count().ShouldEqual(0);
        }