public void AddCommentToRespectiveImage_WhenParamsAreValid() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var imageFactoryMock = new Mock <IGalleryImageFactory>(); var commentFactoryMock = new Mock <IGalleryCommentFactory>(); var likeFactoryMock = new Mock <IGalleryLikeFactory>(); var comment = new GalleryComment(); var image = new GalleryImage(); var user = new User(); contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns(user); commentFactoryMock.Setup(x => x.CreateGalleryComment(It.IsAny <Guid>(), It.IsAny <User>(), It.IsAny <string>(), It.IsAny <Guid>())) .Returns(comment); contextMock.Setup(x => x.GalleryImages.Find(It.IsAny <Guid>())).Returns(image); var id = "some name"; var content = "some content"; var guid = Guid.NewGuid(); var service = new GalleryImageService(contextMock.Object, imageFactoryMock.Object, likeFactoryMock.Object, commentFactoryMock.Object); // Act service.AddComment(id, content, guid); // Assert Assert.AreSame(comment, image.Comments.First()); }
public void MakeACallToSaveChanges_WhenParamsAreValid() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var imageFactoryMock = new Mock <IGalleryImageFactory>(); var commentFactoryMock = new Mock <IGalleryCommentFactory>(); var likeFactoryMock = new Mock <IGalleryLikeFactory>(); var comment = new GalleryComment(); var image = new GalleryImage(); var user = new User(); contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns(user); commentFactoryMock.Setup(x => x.CreateGalleryComment(It.IsAny <Guid>(), It.IsAny <User>(), It.IsAny <string>(), It.IsAny <Guid>())) .Returns(comment); contextMock.Setup(x => x.GalleryImages.Find(It.IsAny <Guid>())).Returns(image); var id = "some name"; var content = "some content"; var guid = Guid.NewGuid(); var service = new GalleryImageService(contextMock.Object, imageFactoryMock.Object, likeFactoryMock.Object, commentFactoryMock.Object); // Act service.AddComment(id, content, guid); // Assert contextMock.Verify(x => x.SaveChanges(), Times.Once); }
public void CallSaveChanges_WhenInputParamsAreValid() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var imageFactoryMock = new Mock <IGalleryImageFactory>(); var commentFactoryMock = new Mock <IGalleryCommentFactory>(); var likeFactoryMock = new Mock <IGalleryLikeFactory>(); var id = Guid.NewGuid().ToString(); var comment = new GalleryComment(); contextMock.Setup(x => x.GalleryComments.Find(It.IsAny <Guid>())).Returns(comment); contextMock.Setup(x => x.GalleryComments.Remove(comment)); var service = new GalleryImageService(contextMock.Object, imageFactoryMock.Object, likeFactoryMock.Object, commentFactoryMock.Object); // Act service.DeleteComment(id); // Assert contextMock.Verify(x => x.SaveChanges(), Times.Once); }