public void Constructor_should_work()
        {
            var processedRequests = new WriteRequest[0];
            var upserts = new BulkWriteOperationUpsert[0];
            var result = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors = new BulkWriteOperationError[0];
            var writeConcernError = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            subject.Result.Should().BeSameAs(result);
            subject.UnprocessedRequests.Should().BeSameAs(unprocessedRequests);
            subject.WriteConcernError.Should().BeSameAs(writeConcernError);
            subject.WriteErrors.Should().BeSameAs(writeErrors);
        }
        public void Constructor_should_work()
        {
            var processedRequests   = new WriteRequest[0];
            var upserts             = new BulkWriteOperationUpsert[0];
            var result              = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors         = new BulkWriteOperationError[0];
            var writeConcernError   = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject             = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            subject.Result.Should().BeSameAs(result);
            subject.UnprocessedRequests.Should().BeSameAs(unprocessedRequests);
            subject.WriteConcernError.Should().BeSameAs(writeConcernError);
            subject.WriteErrors.Should().BeSameAs(writeErrors);
        }
        private static IReadOnlyList <BulkWriteOperationError> CreateWriteErrors(BsonDocument writeCommandResponse)
        {
            var writeErrors = new List <BulkWriteOperationError>();

            if (writeCommandResponse.Contains("writeErrors"))
            {
                foreach (BsonDocument value in writeCommandResponse["writeErrors"].AsBsonArray)
                {
                    var index      = value["index"].ToInt32();
                    var code       = value["code"].ToInt32();
                    var message    = value["errmsg"].AsString;
                    var details    = (BsonDocument)value.GetValue("errInfo", null);
                    var writeError = new BulkWriteOperationError(index, code, message, details);
                    writeErrors.Add(writeError);
                }
            }

            return(writeErrors);
        }
        public void Serialization_should_drop_custom_fields()
        {
            var processedRequests = new WriteRequest[0];
            var upserts = new BulkWriteOperationUpsert[0];
            var result = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors = new BulkWriteOperationError[0];
            var writeConcernError = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            var formatter = new BinaryFormatter();
            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, subject);
                stream.Position = 0;
                var rehydrated = (BulkWriteOperationException)formatter.Deserialize(stream);

                rehydrated.Result.Should().BeNull();
                rehydrated.UnprocessedRequests.Should().BeNull();
                rehydrated.WriteConcernError.Should().BeNull();
                rehydrated.WriteErrors.Should().BeNull();
            }
        }
        public void Serialization_should_drop_custom_fields()
        {
            var processedRequests   = new WriteRequest[0];
            var upserts             = new BulkWriteOperationUpsert[0];
            var result              = new BulkWriteOperationResult.Acknowledged(1, 2, 3, 4, 5, processedRequests, upserts);
            var writeErrors         = new BulkWriteOperationError[0];
            var writeConcernError   = new BulkWriteConcernError(1, "message", new BsonDocument("x", 1));
            var unprocessedRequests = new WriteRequest[0];
            var subject             = new BulkWriteOperationException(result, writeErrors, writeConcernError, unprocessedRequests);

            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, subject);
                stream.Position = 0;
                var rehydrated = (BulkWriteOperationException)formatter.Deserialize(stream);

                rehydrated.Result.Should().BeNull();
                rehydrated.UnprocessedRequests.Should().BeNull();
                rehydrated.WriteConcernError.Should().BeNull();
                rehydrated.WriteErrors.Should().BeNull();
            }
        }
        private static IReadOnlyList<BulkWriteOperationError> CreateWriteErrors(BsonDocument writeCommandResponse)
        {
            var writeErrors = new List<BulkWriteOperationError>();

            if (writeCommandResponse.Contains("writeErrors"))
            {
                foreach (BsonDocument value in writeCommandResponse["writeErrors"].AsBsonArray)
                {
                    var index = value["index"].ToInt32();
                    var code = value["code"].ToInt32();
                    var message = value["errmsg"].AsString;
                    var details = (BsonDocument)value.GetValue("errInfo", null);
                    var writeError = new BulkWriteOperationError(index, code, message, details);
                    writeErrors.Add(writeError);
                }
            }

            return writeErrors;
        }
 public void Should_return_correct_error_category(int code, ServerErrorCategory expectedCategory)
 {
     var subject = new BulkWriteOperationError(0, code, "something", new BsonDocument());
     subject.Category.Should().Be(expectedCategory);
 }
Пример #8
0
 // internal static methods
 internal static BulkWriteError FromCore(Core.Operations.BulkWriteOperationError error)
 {
     return(new BulkWriteError(error.Index, error.Category, error.Code, error.Message, error.Details));
 }
Пример #9
0
        public void Should_return_correct_error_category(int code, ServerErrorCategory expectedCategory)
        {
            var subject = new BulkWriteOperationError(0, code, "something", new BsonDocument());

            subject.Category.Should().Be(expectedCategory);
        }