public void ThrowArgumentNullException_WhenPassedIdIsNull(string id) { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act & Assert Assert.Throws <ArgumentNullException>(() => service.DeleteComment(id)); }
public void ThrowInvalidOperationException_WhenNoSuchCommentIsFound() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); contextMock.Setup(x => x.Comments.Find(It.IsAny <Guid>())).Returns((ArticleComment)null); var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act & Assert Assert.Throws <InvalidOperationException>(() => service.DeleteComment(Guid.NewGuid().ToString())); }
public void CallRemoveMethod_WhenPassedValidParams() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); var comment = new ArticleComment(); contextMock.Setup(x => x.Comments.Find(It.IsAny <Guid>())).Returns(comment); var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act service.DeleteComment(Guid.NewGuid().ToString()); // Assert contextMock.Verify(x => x.Comments.Remove(comment), Times.Once); }