Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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()));
        }
Ejemplo n.º 3
0
        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);
        }