public async Task InsertManyAsync_should_execute_the_BulkMixedOperation() { var documents = new[] { BsonDocument.Parse("{_id:1,a:1}"), BsonDocument.Parse("{_id:2,a:2}") }; var expectedRequests = new[] { new InsertRequest(documents[0]) { CorrelationId = 0 }, new InsertRequest(documents[1]) { CorrelationId = 1 } }; var operationResult = new BulkWriteOperationResult.Unacknowledged(2, expectedRequests); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.InsertManyAsync( documents, null, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifyWrites(expectedRequests, true, call); }
public void Should_convert_from_core_unacknowledged_result_when_original_models_does_not_exist() { var core = new BulkWriteOperationResult.Unacknowledged( requestCount: 1, processedRequests: new[] { new InsertRequest(new BsonDocumentWrapper(new BsonDocument("b", 1))) }); var mapped = BulkWriteResult <BsonDocument> .FromCore(core); mapped.ProcessedRequests[0].Should().BeOfType <InsertOneModel <BsonDocument> >(); ((InsertOneModel <BsonDocument>)mapped.ProcessedRequests[0]).Document.Should().Be("{b:1}"); mapped.IsAcknowledged.Should().BeFalse(); mapped.RequestCount.Should().Be(core.RequestCount); }
public void Should_convert_from_core_unacknowledged_result_when_original_models_exists() { var core = new BulkWriteOperationResult.Unacknowledged( requestCount: 1, processedRequests: new[] { new InsertRequest(new BsonDocument("b", 1)) }); var models = new[] { new InsertOneModel <BsonDocument>(new BsonDocument("a", 1)) }; var mapped = BulkWriteResult <BsonDocument> .FromCore(core, models); mapped.ProcessedRequests[0].Should().BeSameAs(models[0]); mapped.IsAcknowledged.Should().BeFalse(); mapped.RequestCount.Should().Be(core.RequestCount); }
public async Task InsertOneAsync_should_execute_the_BulkMixedOperation() { var document = BsonDocument.Parse("{_id:1,a:1}"); var expectedRequest = new InsertRequest(document) { CorrelationId = 0 }; var operationResult = new BulkWriteOperationResult.Unacknowledged(1, new[] { expectedRequest }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.InsertOneAsync( document, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifySingleWrite(expectedRequest, call); }
public async Task DeleteOneAsync_should_execute_the_BulkMixedOperation() { var filter = new BsonDocument("a", 1); var expectedRequest = new DeleteRequest(filter) { CorrelationId = 0, Limit = 1 }; var operationResult = new BulkWriteOperationResult.Unacknowledged(9, new[] { expectedRequest }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.DeleteOneAsync( filter, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifySingleWrite(expectedRequest, call); }
public async Task DeleteManyAsync_should_execute_the_BulkMixedOperation() { var criteria = new BsonDocument("a", 1); var expectedRequest = new DeleteRequest(criteria) { CorrelationId = 0, Limit = 0 }; var operationResult = new BulkWriteOperationResult.Unacknowledged(9, new[] { expectedRequest }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.DeleteManyAsync( new DeleteManyModel <BsonDocument>(criteria), Timeout.InfiniteTimeSpan, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifySingleWrite(expectedRequest, call); }
public async Task UpdateOneAsync_should_execute_the_BulkMixedOperation(bool upsert) { var criteria = BsonDocument.Parse("{a:1}"); var update = BsonDocument.Parse("{$set:{a:1}}"); var expectedRequest = new UpdateRequest(UpdateType.Update, criteria, update) { CorrelationId = 0, IsUpsert = upsert, IsMulti = false }; var operationResult = new BulkWriteOperationResult.Unacknowledged(9, new[] { expectedRequest }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.UpdateOneAsync( new UpdateOneModel <BsonDocument>(criteria, update) { IsUpsert = upsert }, Timeout.InfiniteTimeSpan, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifySingleWrite(expectedRequest, call); }
public async Task UpdateManyAsync_should_execute_the_BulkMixedOperation(bool upsert) { var filter = BsonDocument.Parse("{a:1}"); var update = BsonDocument.Parse("{$set:{a:1}}"); var expectedRequest = new UpdateRequest(UpdateType.Update, filter, update) { CorrelationId = 0, IsUpsert = upsert, IsMulti = true }; var operationResult = new BulkWriteOperationResult.Unacknowledged(9, new[] { expectedRequest }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); await _subject.UpdateManyAsync( filter, update, new UpdateOptions { IsUpsert = upsert }, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); VerifySingleWrite(expectedRequest, call); }
public async Task BulkWriteAsync_should_execute_the_BulkMixedWriteOperation(bool isOrdered) { var requests = new WriteModel <BsonDocument>[] { new InsertOneModel <BsonDocument>(new BsonDocument("_id", 1).Add("a", 1)), new DeleteManyModel <BsonDocument>(new BsonDocument("b", 1)), new DeleteOneModel <BsonDocument>(new BsonDocument("c", 1)), new ReplaceOneModel <BsonDocument>(new BsonDocument("d", 1), new BsonDocument("e", 1)), new ReplaceOneModel <BsonDocument>(new BsonDocument("f", 1), new BsonDocument("g", 1)) { IsUpsert = true }, new UpdateManyModel <BsonDocument>(new BsonDocument("h", 1), new BsonDocument("$set", new BsonDocument("i", 1))), new UpdateManyModel <BsonDocument>(new BsonDocument("j", 1), new BsonDocument("$set", new BsonDocument("k", 1))) { IsUpsert = true }, new UpdateOneModel <BsonDocument>(new BsonDocument("l", 1), new BsonDocument("$set", new BsonDocument("m", 1))), new UpdateOneModel <BsonDocument>(new BsonDocument("n", 1), new BsonDocument("$set", new BsonDocument("o", 1))) { IsUpsert = true }, }; var bulkOptions = new BulkWriteOptions { IsOrdered = isOrdered }; var operationResult = new BulkWriteOperationResult.Unacknowledged(9, new[] { new InsertRequest(new BsonDocument("b", 1)) }); _operationExecutor.EnqueueResult <BulkWriteOperationResult>(operationResult); var result = await _subject.BulkWriteAsync(requests, bulkOptions, CancellationToken.None); var call = _operationExecutor.GetWriteCall <BulkWriteOperationResult>(); call.Operation.Should().BeOfType <BulkMixedWriteOperation>(); var operation = (BulkMixedWriteOperation)call.Operation; // I know, this is a lot of stuff in one test :( operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.IsOrdered.Should().Be(isOrdered); operation.Requests.Count().Should().Be(9); var convertedRequests = operation.Requests.ToList(); // InsertOneModel convertedRequests[0].Should().BeOfType <InsertRequest>(); convertedRequests[0].CorrelationId.Should().Be(0); var convertedRequest0 = (InsertRequest)convertedRequests[0]; convertedRequest0.Document.Should().Be("{_id:1, a:1}"); // RemoveManyModel convertedRequests[1].Should().BeOfType <DeleteRequest>(); convertedRequests[1].CorrelationId.Should().Be(1); var convertedRequest1 = (DeleteRequest)convertedRequests[1]; convertedRequest1.Filter.Should().Be("{b:1}"); convertedRequest1.Limit.Should().Be(0); // RemoveOneModel convertedRequests[2].Should().BeOfType <DeleteRequest>(); convertedRequests[2].CorrelationId.Should().Be(2); var convertedRequest2 = (DeleteRequest)convertedRequests[2]; convertedRequest2.Filter.Should().Be("{c:1}"); convertedRequest2.Limit.Should().Be(1); // ReplaceOneModel convertedRequests[3].Should().BeOfType <UpdateRequest>(); convertedRequests[3].CorrelationId.Should().Be(3); var convertedRequest3 = (UpdateRequest)convertedRequests[3]; convertedRequest3.Filter.Should().Be("{d:1}"); convertedRequest3.Update.Should().Be("{e:1}"); convertedRequest3.UpdateType.Should().Be(UpdateType.Replacement); convertedRequest3.IsMulti.Should().BeFalse(); convertedRequest3.IsUpsert.Should().BeFalse(); // ReplaceOneModel with upsert convertedRequests[4].Should().BeOfType <UpdateRequest>(); convertedRequests[4].CorrelationId.Should().Be(4); var convertedRequest4 = (UpdateRequest)convertedRequests[4]; convertedRequest4.Filter.Should().Be("{f:1}"); convertedRequest4.Update.Should().Be("{g:1}"); convertedRequest4.UpdateType.Should().Be(UpdateType.Replacement); convertedRequest4.IsMulti.Should().BeFalse(); convertedRequest4.IsUpsert.Should().BeTrue(); // UpdateManyModel convertedRequests[5].Should().BeOfType <UpdateRequest>(); convertedRequests[5].CorrelationId.Should().Be(5); var convertedRequest5 = (UpdateRequest)convertedRequests[5]; convertedRequest5.Filter.Should().Be("{h:1}"); convertedRequest5.Update.Should().Be("{$set:{i:1}}"); convertedRequest5.UpdateType.Should().Be(UpdateType.Update); convertedRequest5.IsMulti.Should().BeTrue(); convertedRequest5.IsUpsert.Should().BeFalse(); // UpdateManyModel with upsert convertedRequests[6].Should().BeOfType <UpdateRequest>(); convertedRequests[6].CorrelationId.Should().Be(6); var convertedRequest6 = (UpdateRequest)convertedRequests[6]; convertedRequest6.Filter.Should().Be("{j:1}"); convertedRequest6.Update.Should().Be("{$set:{k:1}}"); convertedRequest6.UpdateType.Should().Be(UpdateType.Update); convertedRequest6.IsMulti.Should().BeTrue(); convertedRequest6.IsUpsert.Should().BeTrue(); // UpdateOneModel convertedRequests[7].Should().BeOfType <UpdateRequest>(); convertedRequests[7].CorrelationId.Should().Be(7); var convertedRequest7 = (UpdateRequest)convertedRequests[7]; convertedRequest7.Filter.Should().Be("{l:1}"); convertedRequest7.Update.Should().Be("{$set:{m:1}}"); convertedRequest7.UpdateType.Should().Be(UpdateType.Update); convertedRequest7.IsMulti.Should().BeFalse(); convertedRequest7.IsUpsert.Should().BeFalse(); // UpdateOneModel with upsert convertedRequests[8].Should().BeOfType <UpdateRequest>(); convertedRequests[8].CorrelationId.Should().Be(8); var convertedRequest8 = (UpdateRequest)convertedRequests[8]; convertedRequest8.Filter.Should().Be("{n:1}"); convertedRequest8.Update.Should().Be("{$set:{o:1}}"); convertedRequest8.UpdateType.Should().Be(UpdateType.Update); convertedRequest8.IsMulti.Should().BeFalse(); convertedRequest8.IsUpsert.Should().BeTrue(); // Result result.Should().NotBeNull(); result.IsAcknowledged.Should().BeFalse(); result.RequestCount.Should().Be(9); result.ProcessedRequests.Should().BeEquivalentTo(requests); for (int i = 0; i < requests.Length; i++) { result.ProcessedRequests[i].Should().BeSameAs(requests[i]); } }