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 ThrowArgumentNullException_WhenPassedContentIsNull(string content) { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var imageFactoryMock = new Mock <IGalleryImageFactory>(); var commentFactoryMock = new Mock <IGalleryCommentFactory>(); var likeFactoryMock = new Mock <IGalleryLikeFactory>(); var id = "some name"; var guid = Guid.NewGuid(); var service = new GalleryImageService(contextMock.Object, imageFactoryMock.Object, likeFactoryMock.Object, commentFactoryMock.Object); // Act & Assert Assert.Throws <ArgumentNullException>(() => service.AddComment(id, content, guid)); }
public void ThrowInvalidOperationException_WhenNoSuchUser() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var imageFactoryMock = new Mock <IGalleryImageFactory>(); var commentFactoryMock = new Mock <IGalleryCommentFactory>(); var likeFactoryMock = new Mock <IGalleryLikeFactory>(); var id = "some name"; var content = "some content"; var guid = Guid.NewGuid(); contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns((User)null); var service = new GalleryImageService(contextMock.Object, imageFactoryMock.Object, likeFactoryMock.Object, commentFactoryMock.Object); // Act & Assert Assert.Throws <InvalidOperationException>(() => service.AddComment(id, content, guid)); }