Beispiel #1
0
        public void constructor_should_initialize_subject()
        {
            var subject = new MongoBulkWriteException<BsonDocument>(_connectionId, _bulkWriteResult, _writeErrors, _writeConcernError, _unprocessedRequests);

            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.Message.Should().Contain("bulk write operation");
            subject.Result.Should().BeSameAs(_bulkWriteResult);
            subject.UnprocessedRequests.Should().Equal(_unprocessedRequests);
            subject.WriteConcernError.Should().BeSameAs(_writeConcernError);
            subject.WriteErrors.Should().Equal(_writeErrors);
        }
        public void FromBulkWriteException_should_return_expected_result()
        {
            var processedRequests = new[] { new InsertOneModel<BsonDocument>(new BsonDocument("_id", 1)) };
            var upserts = new List<BulkWriteUpsert>();
            var bulkWriteResult = new BulkWriteResult<BsonDocument>.Acknowledged(1, 1, 0, 0, 0, processedRequests, upserts);
            var writeErrors = new[] { new BulkWriteError(1, ServerErrorCategory.Uncategorized, 2, "message", new BsonDocument("details", 1)) };
            var writeConcernError = new WriteConcernError(1, "message", new BsonDocument("details", 1));
            var unprocessedRequests = new List<WriteModel<BsonDocument>>();
            var bulkWriteException = new MongoBulkWriteException<BsonDocument>(_connectionId, bulkWriteResult, writeErrors, writeConcernError, unprocessedRequests);

            var result = MongoWriteException.FromBulkWriteException(bulkWriteException);

            result.ConnectionId.Should().Be(_connectionId);
            result.InnerException.Should().BeSameAs(bulkWriteException);
            result.Message.Should().Be("A write operation resulted in an error." + Environment.NewLine + "  message" + Environment.NewLine + "  message");
            result.WriteConcernError.Should().Be(writeConcernError);
            result.WriteError.Should().Be(writeErrors[0]);
        }
Beispiel #3
0
        public void Serialization_should_work()
        {
            var subject = new MongoBulkWriteException<BsonDocument>(_connectionId, _bulkWriteResult, _writeErrors, _writeConcernError, _unprocessedRequests);

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

                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.Result.Should().BeUsing(subject.Result, EqualityComparerRegistry.Default);
                rehydrated.UnprocessedRequests.Should().EqualUsing(subject.UnprocessedRequests, EqualityComparerRegistry.Default);
                rehydrated.WriteConcernError.Should().BeUsing(subject.WriteConcernError, EqualityComparerRegistry.Default);
                rehydrated.WriteErrors.Should().EqualUsing(subject.WriteErrors, EqualityComparerRegistry.Default);
            }
        }