Esempio n. 1
0
        public void GivenAnInvalidModel_WhenITryAndUpdateABlog_ThenIHaveToReEditTheBlogData()
        {
            var controller = new BlogController(_blogDomain.Object, null);

            controller.ModelState.AddModelError("Name", "Name error");

            var result = controller.Update(new CreateBlogViewModel()) as ViewResult;

            Assert.That(result, Is.Not.Null);
        }
Esempio n. 2
0
        public void UpdateTest_ReturnsNull_WhenIdAndPostAreNull()
        {
            //act:
            var result = _blogController.Update(null, null);

            Assert.IsAssignableFrom <NotFoundObjectResult>(result);
        }
Esempio n. 3
0
        public void GivenAValidModel_WhenITryAndUpdateABlog_ThenIGetTheCorrectView()
        {
            string nickname   = "nickname";
            var    controller = new BlogController(_blogDomain.Object, null);


            var result =
                controller.Update(new CreateBlogViewModel {
                Nickname = nickname, Description = "desc", Title = "title"
            })
                as RedirectToRouteResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.RouteValues["controller"], Is.EqualTo("Dashboard").IgnoreCase);
            Assert.That(result.RouteValues["action"], Is.EqualTo("index").IgnoreCase);
        }
        // Should fail since no post with id 1234 exists
        public void Test5_UpdateFail()
        {
            // Arrange
            var controller = new BlogController(_context);

            // Act
            IActionResult actionResult = controller.Update(new CreateAndUpdateBody
            {
                id    = 1234,
                title = "my title",
                slug  = "my slug",
                text  = "im changed"
            });

            var statusCodeResult = Assert.IsType <StatusCodeResult>(actionResult);
            int?statusCode       = statusCodeResult.StatusCode as int?;

            // Assert
            Assert.Equal(404, statusCode);
        }
        // Should change post.text to "im changed", regarding post with id 1
        public void Test4_UpdateSuccess()
        {
            // Arrange
            var controller = new BlogController(_context);

            // Act
            IActionResult actionResult = controller.Update(new CreateAndUpdateBody
            {
                id    = 1,
                title = "my title",
                slug  = "my slug",
                text  = "im changed"
            });

            var  okObjectResult = Assert.IsType <OkObjectResult>(actionResult);
            Post updatedPost    = okObjectResult.Value as Post;

            // Assert
            Assert.Equal("im changed", updatedPost.Text);
            Assert.Equal("my-slug", updatedPost.Slug);
        }