public async Task ExecuteAsync_with_one_insert() { var requests = new[] { new InsertRequest(BsonDocument.Parse("{_id: 1, x: 3}")) }; var subject = new BulkMixedWriteOperation(_collectionNamespace, requests, _messageEncoderSettings); var result = await ExecuteOperationAsync(subject); result.DeletedCount.Should().Be(0); result.InsertedCount.Should().Be(1); if (result.IsModifiedCountAvailable) { result.ModifiedCount.Should().Be(0); } result.MatchedCount.Should().Be(0); result.ProcessedRequests.Should().HaveCount(1); result.RequestCount.Should().Be(1); result.Upserts.Should().BeEmpty(); var list = await ReadAllFromCollectionAsync(); list.Should().HaveCount(1); }
public void Execute_with_mixed_upserts_and_ordered_is_true( [Values(false, true)] bool async) { var requests = new WriteRequest[] { new UpdateRequest(UpdateType.Update, BsonDocument.Parse("{x: 12}"), BsonDocument.Parse("{$set: {y: 1}}")) { IsUpsert = true }, new DeleteRequest(new BsonDocument("_id", 2)), new InsertRequest(new BsonDocument("_id", 7)), new UpdateRequest(UpdateType.Update, BsonDocument.Parse("{x: 4}"), BsonDocument.Parse("{$set: {y: 2}}")) { IsUpsert = true } }; var subject = new BulkMixedWriteOperation(_collectionNamespace, requests, _messageEncoderSettings) { IsOrdered = true }; var result = ExecuteOperation(subject, async); result.DeletedCount.Should().Be(1); result.InsertedCount.Should().Be(1); if (result.IsModifiedCountAvailable) { result.ModifiedCount.Should().Be(0); } result.MatchedCount.Should().Be(0); result.ProcessedRequests.Should().HaveCount(4); result.RequestCount.Should().Be(4); result.Upserts.Should().HaveCount(2); var list = ReadAllFromCollection(async); list.Should().HaveCount(8); }
public void Execute_unacknowledged_with_an_error_in_the_second_batch_and_ordered_is_true( [Values(false, true)] bool async) { var requests = new[] { new InsertRequest(new BsonDocument { { "_id", 1 } }), new InsertRequest(new BsonDocument { { "_id", 2 } }), new InsertRequest(new BsonDocument { { "_id", 3 } }), new InsertRequest(new BsonDocument { { "_id", 1 } }), // will fail new InsertRequest(new BsonDocument { { "_id", 5 } }), }; var subject = new BulkMixedWriteOperation(_collectionNamespace, requests, _messageEncoderSettings) { IsOrdered = true, MaxBatchCount = 2, WriteConcern = WriteConcern.Unacknowledged }; var result = ExecuteOperation(subject); result.ProcessedRequests.Should().HaveCount(4); result.RequestCount.Should().Be(5); var list = ReadAllFromCollection(async); list.Should().HaveCount(3); }
public async Task ExecuteAsync_with_one_update_against_a_matching_document() { var requests = new[] { new UpdateRequest(UpdateType.Update, BsonDocument.Parse("{x: 1}"), BsonDocument.Parse("{$set: {a: 1}}")) }; var subject = new BulkMixedWriteOperation(_collectionNamespace, requests, _messageEncoderSettings); var result = await ExecuteOperationAsync(subject); result.DeletedCount.Should().Be(0); result.InsertedCount.Should().Be(0); if (result.IsModifiedCountAvailable) { result.ModifiedCount.Should().Be(1); } result.MatchedCount.Should().Be(1); // I don't understand this... result.ProcessedRequests.Should().HaveCount(1); result.RequestCount.Should().Be(1); result.Upserts.Should().BeEmpty(); var list = await ReadAllFromCollectionAsync(); list.Should().HaveCount(6); }
public void Execute_with_one_delete_without_matching_a_document( [Values(false, true)] bool async) { var requests = new[] { new DeleteRequest(BsonDocument.Parse("{_id: 20}")) }; var subject = new BulkMixedWriteOperation(_collectionNamespace, requests, _messageEncoderSettings); var result = ExecuteOperation(subject, async); result.DeletedCount.Should().Be(0); result.InsertedCount.Should().Be(0); if (result.IsModifiedCountAvailable) { result.ModifiedCount.Should().Be(0); } result.MatchedCount.Should().Be(0); result.ProcessedRequests.Should().HaveCount(1); result.RequestCount.Should().Be(1); result.Upserts.Should().BeEmpty(); var list = ReadAllFromCollection(async); list.Should().HaveCount(6); }
public BatchHelper(BulkMixedWriteOperation operation, IChannelHandle channel) { _operation = operation; _channel = channel; }