Ejemplo n.º 1
0
        public void _Call_UnitOfWork_Commit(int id)
        {
            //Arrange
            var post = new Post();

            var mockedPostRepository = new Mock <IRepository <Post> >();

            mockedPostRepository.Setup(r => r.GetById(It.IsAny <int>())).Returns(post);

            var mockedUserService      = new Mock <IUserService>();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedPostFactory      = new Mock <IPostFactory>();
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var postService = new PostsService(
                mockedPostRepository.Object,
                mockedUserService.Object,
                mockedUnitOfWork.Object,
                mockedPostFactory.Object,
                mockedCategoryService.Object,
                mockedDateTimeProvider.Object);

            var comment = new Comment();

            //Act
            postService.AddComment(id, comment);

            //Assert
            mockedUnitOfWork.Verify(u => u.Commit(), Times.Once);
        }
Ejemplo n.º 2
0
        public void _Call_PostRepository_GetById(int id)
        {
            //Arrange
            var mockedPostRepository   = new Mock <IRepository <Post> >();
            var mockedUserService      = new Mock <IUserService>();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedPostFactory      = new Mock <IPostFactory>();
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var postService = new PostsService(
                mockedPostRepository.Object,
                mockedUserService.Object,
                mockedUnitOfWork.Object,
                mockedPostFactory.Object,
                mockedCategoryService.Object,
                mockedDateTimeProvider.Object);

            var comment = new Comment();

            //Act
            postService.AddComment(id, comment);

            //Assert
            mockedPostRepository.Verify(r => r.GetById(id), Times.Once);
        }
Ejemplo n.º 3
0
        public JsonResult AddComment(string data, HttpPostedFileBase file)
        {
            PostCommentEntity comment = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <PostCommentEntity>(data);

            var dt = _postService.AddComment(comment, file);

            return(Json(dt, JsonRequestBehavior.AllowGet));
        }