Ejemplo n.º 1
0
        public void AddComment()
        {
            var controllerContext = new Mock <ControllerContext>();
            var principal         = new Mock <IPrincipal>();

            principal.Setup(p => p.IsInRole("Administrator")).Returns(true);
            principal.SetupGet(x => x.Identity.Name).Returns("rr");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            controller.ControllerContext = controllerContext.Object;

            CommentModel toAdd = new CommentModel
            {
                AuthorLogin = "******",
                CreateDate  = DateTime.Now,
                RecipeId    = 2,
                Text        = "new comment",
                Id          = 7
            };

            ViewResult result = controller.AddComment(toAdd) as ViewResult;

            var addedComment = db.FindComment(7);

            Assert.AreNotEqual(null, addedComment);
        }