public void constructor_with_innerException_should_initialize_subject()
        {
            var subject = new MongoServerException(_connectionId, _message, _innerException);

            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeSameAs(_innerException);
            subject.Message.Should().BeSameAs(_message);
        }
        public void constructor_with_innerException_should_initialize_subject()
        {
            var subject = new MongoServerException(_connectionId, _message, _innerException);

            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeSameAs(_innerException);
            subject.Message.Should().BeSameAs(_message);
        }
        public void Serialization_should_work()
        {
            var subject = new MongoServerException(_connectionId, _message, _innerException);

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

                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
            }
        }
        public void Serialization_should_work()
        {
            var subject = new MongoServerException(_connectionId, _message, _innerException);

            var formatter = new BinaryFormatter();

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

                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
            }
        }
示例#5
0
 /// <summary>
 /// Adds error labels from a command result document into the top-level label list.
 /// </summary>
 /// <param name="exception">The exception.</param>
 /// <param name="result">The result document.</param>
 protected static void AddErrorLabelsFromCommandResult(MongoServerException exception, BsonDocument result)
 {
     // note: make a best effort to extract the error labels from the result, but never throw an exception
     if (result != null)
     {
         BsonValue errorLabels;
         if (result.TryGetValue("errorLabels", out errorLabels) && errorLabels.IsBsonArray)
         {
             foreach (var errorLabel in errorLabels.AsBsonArray)
             {
                 if (errorLabel.IsString)
                 {
                     exception.AddErrorLabel(errorLabel.AsString);
                 }
             }
         }
     }
 }