public async Task GivenAnErrorGettingTheCollection_WhenGetAllIsCalled_ExceptionIsThrown()
        {
            // arrange
            var target = new TestDocumentRepository(context, logger);

            Mock.Get(context)
            .Setup(x => x.GetCollection <TestDocument>(typeof(TestDocument).Name))
            .Throws(new Exception("Test error message"))
            .Verifiable();

            // act
            var actual = await Assert.ThrowsAsync <Exception>(async() =>
                                                              await target.GetAllAsync().ConfigureAwait(false))
                         .ConfigureAwait(false);

            // assert
            Assert.Equal("Test error message", actual.Message);
            Mock.Verify(Mock.Get(context));
        }
        public async Task GivenADocumentRepository_WhenGetAllAsyncIsCalled_CollectionIsTakenFromContext()
        {
            // arrange
            var          target             = new TestDocumentRepository(context, logger);
            var          testCollection     = Mock.Of <IMongoCollection <TestDocument> >();
            var          findCollection     = Mock.Of <IAsyncCursor <TestDocument> >();
            const string expectedJsonFilter = "{ }";
            int          index    = 0;
            var          expected = new[] { new TestDocument(), new TestDocument() };

            Mock.Get(context)
            .Setup(x => x.GetCollection <TestDocument>(typeof(TestDocument).Name))
            .Returns(testCollection)
            .Verifiable();

            Mock.Get(findCollection)
            .Setup(x => x.MoveNext(It.IsAny <CancellationToken>()))
            .Callback((CancellationToken ct) =>
            {
                index++;
            })
            .Returns(() => index < expected.Length);

            Mock.Get(findCollection)
            .Setup(x => x.Current)
            .Returns(expected);

            Mock.Get(testCollection)
            .Setup(x => x.FindAsync(
                       It.Is <FilterDefinition <TestDocument> >(filter => filter.RenderToJson().Equals(expectedJsonFilter)),
                       It.IsAny <FindOptions <TestDocument, TestDocument> >(),
                       default))
            .Returns(Task.FromResult(findCollection))
            .Verifiable();

            // act
            var actual = await target.GetAllAsync().ConfigureAwait(false);

            // assert
            Assert.Equal(expected, actual);
            Mock.Verify(Mock.Get(context));
            Mock.Verify(Mock.Get(testCollection));
        }