Пример #1
0
        public void constructor_should_should_map_writeConcernResult(object exceptionInfo, Type expectedExceptionType)
        {
            var response = new BsonDocument
            {
                {
                    "writeConcernError",
                    Enum.TryParse <ServerErrorCode>(exceptionInfo.ToString(), out var errorCode)
                        ? new BsonDocument("code", (int)errorCode)
                        : new BsonDocument("errmsg", exceptionInfo.ToString())
                }
            };
            var writeConcernResult    = new WriteConcernResult(response);
            var writeConcernException = new MongoWriteConcernException(_connectionId, "dummy", writeConcernResult);

            var result = writeConcernException.MappedWriteConcernResultException;

            if (expectedExceptionType != null)
            {
                result.GetType().Should().Be(expectedExceptionType);
            }
            else
            {
                result.Should().BeNull();
            }
        }
        public void constructor_should_initialize_subject()
        {
            var subject = new MongoWriteConcernException(_connectionId, _message, _writeConcernResult);

            subject.Command.Should().BeNull();
            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeNull();
            subject.Message.Should().BeSameAs(_message);
            subject.Result.Should().Be(_writeConcernResult.Response);
            subject.WriteConcernResult.Should().Be(_writeConcernResult);
        }
Пример #3
0
        public void constructor_should_initialize_subject()
        {
            var subject = new MongoWriteConcernException(_connectionId, _message, _writeConcernResult);

            subject.Command.Should().BeNull();
            subject.ConnectionId.Should().BeSameAs(_connectionId);
            subject.InnerException.Should().BeNull();
            subject.Message.Should().BeSameAs(_message);
            subject.Result.Should().Be(_writeConcernResult.Response);
            subject.WriteConcernResult.Should().Be(_writeConcernResult);
        }
Пример #4
0
 private static void AddErrorLabelsFromWriteConcernResult(MongoWriteConcernException exception, WriteConcernResult writeConcernResult)
 {
     // note: make a best effort to extract the error labels from the writeConcernResult, but never throw an exception
     if (writeConcernResult != null && writeConcernResult.Response != null)
     {
         if (writeConcernResult.Response.TryGetValue("writeConcernError", out var writeConcernError) &&
             writeConcernError.IsBsonDocument)
         {
             AddErrorLabelsFromCommandResult(exception, writeConcernError.AsBsonDocument);
         }
     }
 }
Пример #5
0
        public void Serialization_should_work()
        {
            var subject = new MongoWriteConcernException(_connectionId, _message, _writeConcernResult);

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

                rehydrated.Command.Should().BeNull();
                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.InnerException.Should().BeNull();
                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.Result.Should().Be(subject.Result);
                rehydrated.WriteConcernResult.Should().BeUsing(subject.WriteConcernResult, EqualityComparerRegistry.Default);
            }
        }
        public void Serialization_should_work()
        {
            var subject = new MongoWriteConcernException(_connectionId, _message, _writeConcernResult);

            var formatter = new BinaryFormatter();

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

                rehydrated.Command.Should().BeNull();
                rehydrated.ConnectionId.Should().Be(subject.ConnectionId);
                rehydrated.InnerException.Should().BeNull();
                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.Result.Should().Be(subject.Result);
                rehydrated.WriteConcernResult.Should().BeUsing(subject.WriteConcernResult, EqualityComparerRegistry.Default);
            }
        }