Raised when a command returns a failure message.
Inheritance: MongoException
Exemple #1
0
        public void Code_get_returns_expected_result()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            var result = subject.Code;

            result.Should().Be(123);
        }
        public void ErrorMessage_get_returns_expected_result()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            var result = subject.ErrorMessage;

            result.Should().Be("error message");
        }
        public void constructor_should_add_error_labels(string jsonResult, string[] expectedErrorLabels)
        {
            var result = jsonResult == null ? null : BsonDocument.Parse(jsonResult);

            var subject = new MongoCommandException(_connectionId, _message, _command, result);

            subject.ErrorLabels.Should().Equal(expectedErrorLabels);
        }
        public void Code_get_returns_expected_result()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            var result = subject.Code;

            result.Should().Be(123);
        }
Exemple #5
0
        public void ErrorMessage_get_returns_expected_result()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            var result = subject.ErrorMessage;

            result.Should().Be("error message");
        }
 public void Constructor_with_2_arguments_should_work()
 {
     var command = new BsonDocument("command", 1);
     var exception = new MongoCommandException("message", command);
     exception.Message.Should().Be("message");
     exception.InnerException.Should().BeNull();
     exception.Command.Equals(command).Should().BeTrue();
     exception.Result.Should().BeNull();
 }
        public void constructor_with_message_command_result_should_initialize_subject()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            subject.Command.Should().BeSameAs(_command);
            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeNull();
            subject.Message.Should().BeSameAs(_message);
            subject.Result.Should().BeSameAs(_commandResult);
        }
Exemple #8
0
        public void constructor_with_message_command_result_should_initialize_subject()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            subject.Command.Should().BeSameAs(_command);
            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeNull();
            subject.Message.Should().BeSameAs(_message);
            subject.Result.Should().BeSameAs(_commandResult);
        }
        public void Constructor_with_2_arguments_should_work()
        {
            var command   = new BsonDocument("command", 1);
            var exception = new MongoCommandException("message", command);

            exception.Message.Should().Be("message");
            exception.InnerException.Should().BeNull();
            exception.Command.Equals(command).Should().BeTrue();
            exception.Result.Should().BeNull();
        }
 public void Constructor_with_4_arguments_should_work()
 {
     var command = new BsonDocument("command", 1);
     var result = new BsonDocument("result", 2);
     var innerException = new Exception("inner");
     var exception = new MongoCommandException("message", command, result, innerException);
     exception.Message.Should().Be("message");
     exception.InnerException.Message.Should().Be("inner");
     exception.Command.Equals(command).Should().BeTrue();
     exception.Result.Equals(result).Should().BeTrue();
 }
        public void Constructor_with_4_arguments_should_work()
        {
            var command        = new BsonDocument("command", 1);
            var result         = new BsonDocument("result", 2);
            var innerException = new Exception("inner");
            var exception      = new MongoCommandException("message", command, result, innerException);

            exception.Message.Should().Be("message");
            exception.InnerException.Message.Should().Be("inner");
            exception.Command.Equals(command).Should().BeTrue();
            exception.Result.Equals(result).Should().BeTrue();
        }
        public void Serialization_should_work()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

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

                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.Message.Should().Be(_message);
                rehydrated.InnerException.Should().BeNull();
                rehydrated.Command.Should().Be(_command);
                rehydrated.Result.Should().Be(_commandResult);
            }
        }
 private static void AddErrorLabelsFromCommandResult(MongoCommandException 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);
                 }
             }
         }
     }
 }
        public void Serialization_should_work()
        {
            var command = new BsonDocument("command", 1);
            var result = new BsonDocument("result", 2);
            var innerException = new Exception("inner");
            var exception = new MongoCommandException("message", command, result, innerException);

            var formatter = new BinaryFormatter();
            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, exception);
                stream.Position = 0;
                var rehydrated = (MongoCommandException)formatter.Deserialize(stream);
                rehydrated.Message.Should().Be("message");
                rehydrated.InnerException.Message.Should().Be("inner");
                rehydrated.Command.Equals(command).Should().BeTrue();
                rehydrated.Result.Equals(result).Should().BeTrue();
            }
        }
Exemple #15
0
        public void Serialization_should_work()
        {
            var subject = new MongoCommandException(_connectionId, _message, _command, _commandResult);

            var formatter = new BinaryFormatter();

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

                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.Message.Should().Be(_message);
                rehydrated.InnerException.Should().BeNull();
                rehydrated.Command.Should().Be(_command);
                rehydrated.Result.Should().Be(_commandResult);
            }
        }
        public void Serialization_should_work()
        {
            var command        = new BsonDocument("command", 1);
            var result         = new BsonDocument("result", 2);
            var innerException = new Exception("inner");
            var exception      = new MongoCommandException("message", command, result, innerException);

            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, exception);
                stream.Position = 0;
                var rehydrated = (MongoCommandException)formatter.Deserialize(stream);
                rehydrated.Message.Should().Be("message");
                rehydrated.InnerException.Message.Should().Be("inner");
                rehydrated.Command.Equals(command).Should().BeTrue();
                rehydrated.Result.Equals(result).Should().BeTrue();
            }
        }
Exemple #17
0
 public MongoMapReduceException(MongoCommandException mce, MapReduce mr) : base(mce.Message, mce.Error, mce.Command)
 {
     mrr = new MapReduce.MapReduceResult(mce.Error);
 }
Exemple #18
0
 private static string MongoCommandExceptionHandle(MongoCommandException ex,
     List<TreeNode> trvMongoDb,
     TreeNode connectionNode,
     string mongoConnKey)
 {
     //listDatabase命令错误,本质是用户名称错误
     if (ex.Result["errmsg"] == "unauthorized")
     {
         if (!GuiConfig.IsUseDefaultLanguage)
         {
             connectionNode.Text += "[" + GuiConfig.GetText("ExceptionAuthenticationException") + "]";
             Utility.ExceptionDeal(ex, GuiConfig.GetText("ExceptionAuthenticationException"), GuiConfig.GetText("ExceptionAuthenticationExceptionNote"));
         }
         else
         {
             connectionNode.Text += "[MongoCommandExceptionHandle]";
             Utility.ExceptionDeal(ex, "MongoCommandExceptionHandle:", "Please check UserName and Password");
         }
     }
     else
     {
         if (!GuiConfig.IsUseDefaultLanguage)
         {
             connectionNode.Text += "[" + GuiConfig.GetText("ExceptionNotConnected") + "]";
             Utility.ExceptionDeal(ex, GuiConfig.GetText("ExceptionNotConnected"), "Unknown Exception");
         }
         else
         {
             connectionNode.Text += "[Exception]";
             Utility.ExceptionDeal(ex, "Not Connected", "Unknown Exception");
         }
     }
     connectionNode.Tag = ConstMgr.ConnectionExceptionTag + ":" + mongoConnKey;
     trvMongoDb.Add(connectionNode);
     return mongoConnKey;
 }
 public MongoMapReduceException(MongoCommandException mce, MapReduce mr)
     : base(mce.Message,mce.Error, mce.Command)
 {
     mrr = new MapReduce.MapReduceResult(mce.Error);
 }