public void DeleteComment_CommentViewModel_RedirectToActionResult()
        {
            _commentService.Setup(service => service.Delete(It.IsAny <Guid>()));

            var res = _sut.Delete(null, new CommentViewModel()) as RedirectToRouteResult;

            Assert.Equal("Comment", res.RouteValues["controller"]);
            Assert.Equal("GetAllCommentToGame", res.RouteValues["action"]);
        }
Beispiel #2
0
        public void Delete_ReturnsIActionResultWhenCommentIdAndGameKey()
        {
            // Arrange
            string gameKey = "c21";

            // Act
            var result = _commentController.Delete(_comment.Id, gameKey) as IActionResult;

            // Assert
            Assert.NotNull(result);
        }
Beispiel #3
0
        public void Delete_Comment()
        {
            //Act
            Comments lastComment        = m_ScrumToolDBContext.Comments.Last();
            int      initalCommentCount = m_ScrumToolDBContext.Comments.Count();

            //Arrange
            m_CommentController.Delete(lastComment.ID);
            //Assert
            m_ScrumToolDBContext.Comments.Should().HaveCount(initalCommentCount - 1, "Number of inital Comment - 1")
            .And.NotContain(lastComment);
        }
Beispiel #4
0
        public async void Delete_Errors()
        {
            CommentControllerMockFacade mock = new CommentControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            CommentController controller = new CommentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
        public void ShouldDeleteCommentWithForbidResultError()
        {
            RequestResult <UserComment> expectedResult = new RequestResult <UserComment>()
            {
                ResourcePayload = new UserComment()
                {
                    Id = Guid.NewGuid(),
                },
                ResultStatus = Common.Constants.ResultType.Error,
            };

            Mock <IHttpContextAccessor> httpContextAccessorMock = CreateValidHttpContext(Token, UserId, Hdid);
            Mock <ICommentService>      commentServiceMock      = new Mock <ICommentService>();

            commentServiceMock.Setup(s => s.Delete(expectedResult.ResourcePayload)).Returns(expectedResult);

            CommentController service = new CommentController(commentServiceMock.Object, httpContextAccessorMock.Object);
            var actualResult          = service.Delete(Hdid, expectedResult.ResourcePayload);

            Assert.IsType <ForbidResult>(actualResult);
        }
        public void ShouldDeleteComment()
        {
            RequestResult <UserComment> expectedResult = new RequestResult <UserComment>()
            {
                ResourcePayload = new UserComment()
                {
                    Id            = Guid.NewGuid(),
                    UserProfileId = Hdid,
                },
                ResultStatus = Common.Constants.ResultType.Success,
            };

            Mock <IHttpContextAccessor> httpContextAccessorMock = CreateValidHttpContext(Token, UserId, Hdid);
            Mock <ICommentService>      commentServiceMock      = new Mock <ICommentService>();

            commentServiceMock.Setup(s => s.Delete(expectedResult.ResourcePayload)).Returns(expectedResult);

            CommentController service = new CommentController(commentServiceMock.Object, httpContextAccessorMock.Object);
            var actualResult          = service.Delete(Hdid, expectedResult.ResourcePayload);
            RequestResult <UserComment> actualRequestResult = (RequestResult <UserComment>)((JsonResult)actualResult).Value;

            Assert.Equal(Common.Constants.ResultType.Success, actualRequestResult.ResultStatus);
            Assert.True(((JsonResult)actualResult).Value.IsDeepEqual(expectedResult));
        }
 public ActionResult CommentDelete(Comment comment)
 {
     comments.Delete(comment);
     return(RedirectToAction("Editor", "Login", null));
 }