示例#1
0
        public void TestDelCommentReturnUnauthorized()
        {
            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims));
            mockCommentService.Setup(x => x.Delete(It.IsAny <string>())).Returns(true);
            var _commenController = new CommentController(mockCommentService.Object, mockAuthorService.Object);

            _commenController.ControllerContext.HttpContext = contextMock.Object;
            var comment = _commenController.DelComment("asfa5ffa4fafaf", "afa5fafaf4aga4g");
            var type    = comment.GetType();

            Assert.AreEqual(type.Name, "UnauthorizedResult");
        }
示例#2
0
        public void TestDelCommentSuccess()
        {
            var contextMock = new Mock <HttpContext>();

            var claims = new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "abc"),
                new Claim(ClaimTypes.Role, "member"),
                new Claim("user_id", "afa5fafaf4aga4g")
            });

            contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims));
            mockCommentService.Setup(x => x.Delete(It.IsAny <string>())).Returns(true);
            var _commenController = new CommentController(mockCommentService.Object, mockAuthorService.Object);

            _commenController.ControllerContext.HttpContext = contextMock.Object;
            var comment = _commenController.DelComment("asfa5ffa4fafaf", "afa5fafaf4aga4g");
            var type    = comment.GetType();

            Assert.AreEqual(type.Name, "OkResult");
        }