示例#1
0
        public void CanDeleteComment()
        {
            var commentRepository = new Mock<IFlyCommentRepository>();

            commentRepository.Setup(s => s.GetAll())
                             .Returns(new List<FlyComment>
                                 {
                                     new FlyComment {Id = 1, Author = new FlyOwner {Id = 1}, Fly = new Fly {Id = 1}, Comment = "Comment" },
                                     new FlyComment {Id = 2, Author = new FlyOwner {Id = 2}, Fly = new Fly {Id = 1}, Comment = "Comment 2" }
                                 }.AsQueryable());

            var commentService = new FlyCommentService(commentRepository.Object);

            commentService.Delete(1);

            commentRepository.Verify(v => v.Delete(It.IsAny<int>()), Times.Once());
        }
示例#2
0
        public void CanGetById()
        {
            var commentRepository = new Mock<IFlyCommentRepository>();

            commentRepository.Setup(s => s.GetAll())
                             .Returns(new List<FlyComment>
                                 {
                                     new FlyComment {Id = 1, Author = new FlyOwner {Id = 1}, Fly = new Fly {Id = 1}, Comment = "Comment" },
                                     new FlyComment {Id = 2, Author = new FlyOwner {Id = 2}, Fly = new Fly {Id = 1}, Comment = "Comment 2" }
                                 }.AsQueryable());

            var commentService = new FlyCommentService(commentRepository.Object);

            var comment = commentService.GetById(1);

            Assert.AreEqual(comment.Id, 1);
            commentRepository.Verify(v => v.GetAll(), Times.Once());
        }
示例#3
0
        public void CanNotInsertWithotComment()
        {
            var commentRepository = new Mock<IFlyCommentRepository>();

            commentRepository.Setup(s => s.GetAll())
                             .Returns(new List<FlyComment>
                                 {
                                     new FlyComment {Id = 1, Author = new FlyOwner {Id = 1}, Fly = new Fly {Id = 1}, Comment = "Comment" },
                                     new FlyComment {Id = 2, Author = new FlyOwner {Id = 2}, Fly = new Fly {Id = 1}, Comment = "Comment 2" }
                                 }.AsQueryable());

            var commentService = new FlyCommentService(commentRepository.Object);

            try
            {
                var comment = new FlyComment { Author = new FlyOwner { Id = 1 }, Fly = new Fly { Id = 1 } };
                commentService.Insert(comment);
                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argx)
            {
                Assert.AreEqual("Comment is required!", argx.Message);
                commentRepository.Verify(v => v.Insert(It.IsAny<FlyComment>()), Times.Never());
            }
            catch (Exception)
            {
                Assert.Fail("Validation not implemented!");
            }
        }