public async Task ReplaceDocumentAsync_ShouldNotReplaceOrInsertDocument_CollectionMissingOriginalDocument()
        {
            // Arrange
            var inserted = new BsonDocument
            {
                ["_id"]   = "exist",
                ["Value"] = Fixture.Create <string>()
            };

            await _destCollection.InsertOneAsync(inserted);

            // Act
            var replacement = new BsonDocument
            {
                ["_id"]   = "not_exist",
                ["Value"] = Fixture.Create <string>()
            };
            await _sut.ReplaceDocumentAsync(new ReplaceOneModel <BsonDocument>(replacement.GetFilterBy("_id"), replacement),
                                            CancellationToken.None);

            // Assert
            var afterReplace = _destCollection.FindSync(FilterDefinition <BsonDocument> .Empty).ToList();

            afterReplace.Should().HaveCount(1).And.AllBeEquivalentTo(inserted);
        }
        public async Task RunRetryWorker_ShouldThrowCancellationException_ChannelIsOpenAndOperationIsCancelled()
        {
            // Arrange
            var retry = new BsonDocument
            {
                ["_id"]   = _fixture.Create <string>(),
                ["Value"] = _fixture.Create <string>()
            };

            var retryChannel = Channel.CreateUnbounded <ReplaceOneModel <BsonDocument> >();
            var cts          = new CancellationTokenSource();
            await retryChannel.Writer.WriteAsync(new ReplaceOneModel <BsonDocument>(retry.GetFilterBy("_id"), retry),
                                                 CancellationToken.None);

            var worker = _sut.RunRetryWorker(retryChannel, new Mock <ILogger>().Object,
                                             cts.Token);

            // Act
            cts.Cancel();

            // Assert
            Func <Task> act = async() => await worker;
            await act.Should().ThrowAsync <OperationCanceledException>();
        }