예제 #1
0
        public async Task DeletComments_ShouldDeleteDestinationCommentsCorrectly()
        {
            List <Comment> deletedComments     = new List <Comment>();
            var            commentsRepoBuilder = new CommentsRepositoryBuilder();

            commentsRepoBuilder.CommentsRepoMock.Setup(r => r.Delete(It.IsAny <Comment>()))
            .Callback <Comment>(c => deletedComments.Add(c));

            var commentsRepo = commentsRepoBuilder
                               .WithAll()
                               .Build();

            var sut = new DestinationService(null, null, null, commentsRepo, null, null, null, Mapper);

            await sut.DeleteComments("2");

            Assert.Equal(3, deletedComments.Count);
            deletedComments.ForEach(c => Assert.Equal("2", c.DestinationId));
            commentsRepoBuilder.CommentsRepoMock.Verify(c => c.Delete(It.IsAny <Comment>()), Times.Exactly(3));
            commentsRepoBuilder.CommentsRepoMock.Verify(c => c.SaveChangesAsync(), Times.Once);
        }