Beispiel #1
0
        public void UpdateNullCommentReturnsBadRequest()
        {
            // Arrange
            var commentsRepo = new Mock <ICommentRepository>();
            var services     = new Mock <IPaginationUtilities>();
            var controller   = new CommentApiController(commentsRepo.Object, services.Object);

            // Act
            var putResponse = controller.Put(1, null);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), putResponse);
        }
Beispiel #2
0
        public void UpdateValidCommentNullRepoResultReturns404()
        {
            // Arrange
            var comment      = TestEntities.Comments[0];
            var commentsRepo = new Mock <ICommentRepository>();
            var services     = new Mock <IPaginationUtilities>();
            var controller   = new CommentApiController(commentsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            //Act
            var putResponse = controller.Put(comment.Id, comment);

            //Assert
            Assert.IsType(typeof(JsonResult), putResponse);
            Assert.Equal(404, controller.Response.StatusCode);
        }
Beispiel #3
0
        public void UpdateValidCommentWrongIdBadRequest()
        {
            // Arrange
            var comment      = TestEntities.Comments[0];
            var commentsRepo = new Mock <ICommentRepository>();

            commentsRepo.Setup(repo => repo.Edit(comment)).Returns(comment);
            var services   = new Mock <IPaginationUtilities>();
            var controller = new CommentApiController(commentsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };
            // Act
            var putResponse = controller.Put(404, comment);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), putResponse);
        }
Beispiel #4
0
        public void UpdateInvalidCommentReturnsBadRequest()
        {
            // Arrange

            var comment      = TestEntities.Comments[2];
            var commentsRepo = new Mock <ICommentRepository>();

            commentsRepo.Setup(repo => repo.Edit(comment)).Returns(comment);
            var services   = new Mock <IPaginationUtilities>();
            var controller = new CommentApiController(commentsRepo.Object, services.Object)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            controller.ModelState.AddModelError("", "Error");

            // Act
            var postResponse = controller.Put(comment.Id, comment);

            // Assert
            Assert.IsType(typeof(BadRequestObjectResult), postResponse);
        }