public void CanInsertComment() { 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 = new FlyComment { Author = new FlyOwner { Id = 1 }, Fly = new Fly { Id = 1 }, Comment = "Comment 3" }; commentService.Insert(comment); commentRepository.Verify(v => v.Insert(It.IsAny<FlyComment>()), Times.Once()); }
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!"); } }