Exemplo n.º 1
0
        public void FromCore_should_convert_from_core_exception_with_a_write_concern_error_when_original_models_do_not_exist()
        {
            var exception = new MongoBulkWriteOperationException(
                _connectionId,
                result: new BulkWriteOperationResult.Acknowledged(
                    requestCount: 1,
                    matchedCount: 1,
                    deletedCount: 0,
                    insertedCount: 0,
                    modifiedCount: 0,
                    processedRequests: new[] { new InsertRequest(new BsonDocumentWrapper(new BsonDocument("b", 1)))
                                               {
                                                   CorrelationId = 1
                                               } },
                    upserts: new List <BulkWriteOperationUpsert>()),
                writeErrors: new[] { new BulkWriteOperationError(10, 1, "blah", new BsonDocument("a", 1)) },
                writeConcernError: new BulkWriteConcernError(11, "funny", new BsonDocument("c", 1)),
                unprocessedRequests: new[] { new InsertRequest(new BsonDocumentWrapper(new BsonDocument("a", 1)))
                                             {
                                                 CorrelationId = 0
                                             } });

            var mapped = MongoBulkWriteException <BsonDocument> .FromCore(exception);

            mapped.Result.ProcessedRequests.Count.Should().Be(1);
            mapped.Result.ProcessedRequests[0].Should().BeOfType <InsertOneModel <BsonDocument> >();
            ((InsertOneModel <BsonDocument>)mapped.Result.ProcessedRequests[0]).Document.Should().Be("{b:1}");
            mapped.WriteConcernError.Should().NotBeNull();
            mapped.WriteErrors.Count.Should().Be(1);
            mapped.WriteErrors[0].Should().NotBeNull();
            mapped.UnprocessedRequests.Count.Should().Be(1);
            mapped.UnprocessedRequests[0].Should().BeOfType <InsertOneModel <BsonDocument> >();
            ((InsertOneModel <BsonDocument>)mapped.UnprocessedRequests[0]).Document.Should().Be("{a:1}");
        }
        public void FromCore_should_convert_from_core_exception_with_a_write_concern_error_when_original_models_exists()
        {
            var exception = new MongoBulkWriteOperationException(
                __connectionId,
                result: new BulkWriteOperationResult.Acknowledged(
                    requestCount: 1,
                    matchedCount: 1,
                    deletedCount: 0,
                    insertedCount: 0,
                    modifiedCount: 0,
                    processedRequests: new[] { new InsertRequest(new BsonDocument("b", 1))
                                               {
                                                   CorrelationId = 1
                                               } },
                    upserts: new List <BulkWriteOperationUpsert>()),
                writeErrors: new[] { new BulkWriteOperationError(10, 1, "blah", new BsonDocument("a", 1)) },
                writeConcernError: new BulkWriteConcernError(11, "47", "funny", new BsonDocument("c", 1), new[] { "RetryableWriteError" }),
                unprocessedRequests: new[] { new InsertRequest(new BsonDocument("a", 1))
                                             {
                                                 CorrelationId = 0
                                             } });

            var models = new[]
            {
                new InsertOneModel <BsonDocument>(new BsonDocument("a", 1)),
                new InsertOneModel <BsonDocument>(new BsonDocument("b", 1))
            };
            var mapped = MongoBulkWriteException <BsonDocument> .FromCore(exception, models);

            mapped.ErrorLabels.Should().BeEquivalentTo(exception.ErrorLabels);
            mapped.Result.ProcessedRequests.Count.Should().Be(1);
            mapped.Result.ProcessedRequests[0].Should().BeSameAs(models[1]);
            mapped.WriteConcernError.Should().NotBeNull();
            mapped.WriteConcernError.ErrorLabels.Should().BeEquivalentTo(exception.WriteConcernError.ErrorLabels);
            mapped.WriteErrors.Count.Should().Be(1);
            mapped.WriteErrors[0].Should().NotBeNull();
            mapped.UnprocessedRequests.Count.Should().Be(1);
            mapped.UnprocessedRequests[0].Should().BeSameAs(models[0]);
        }