Inheritance: System.Exception
Exemplo n.º 1
0
 public void MongoExceptionConstructorTest()
 {
     string msg = string.Empty; // TODO: Initialize to an appropriate value
     Exception t = null; // TODO: Initialize to an appropriate value
     MongoException target = new MongoException(msg, t);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
 public void Constructor_should_work()
 {
     var innerException = new Exception("inner");
     var exception = new MongoException("message", innerException);
     exception.Message.Should().Be("message");
     exception.InnerException.Message.Should().Be("inner");
 }
Exemplo n.º 3
0
        public void constructor_with_innerException_should_initialize_subject()
        {
            var subject = new MongoException(_message, _innerException);

            subject.Message.Should().BeSameAs(_message);
            subject.InnerException.Should().BeSameAs(_innerException);
        }
Exemplo n.º 4
0
        public void constructor_with_innerException_should_initialize_subject()
        {
            var subject = new MongoException(_message, _innerException);

            subject.Message.Should().BeSameAs(_message);
            subject.InnerException.Should().BeSameAs(_innerException);
        }
Exemplo n.º 5
0
        public void Constructor_should_work()
        {
            var innerException = new Exception("inner");
            var exception      = new MongoException("message", innerException);

            exception.Message.Should().Be("message");
            exception.InnerException.Message.Should().Be("inner");
        }
Exemplo n.º 6
0
        public void constructor_should_initialize_subject()
        {
            var subject = new MongoException(_message);

            subject.Message.Should().BeSameAs(_message);
            subject.InnerException.Should().BeNull();
            subject.ErrorLabels.Should().HaveCount(0);
        }
Exemplo n.º 7
0
        public void AddErrorLabels_should_not_add_duplicates()
        {
            var subject = new MongoException(_message);

            subject.AddErrorLabel("one");
            subject.AddErrorLabel("one");

            subject.ErrorLabels.Should().HaveCount(1);
        }
Exemplo n.º 8
0
        public void ErrorLabels_should_return_expected_result(string[] errorLabels)
        {
            var subject = new MongoException(_message);
            foreach (var errorLabel in errorLabels)
            {
                subject.AddErrorLabel(errorLabel);
            }

            var result = subject.ErrorLabels;

            result.Should().Equal(errorLabels);
        }
Exemplo n.º 9
0
        public void RemoveErrorLabels_should_have_expected_result(string[] errorLabels, string removeErrorLabel)
        {
            var subject = new MongoException(_message);
            foreach (var errorLabel in errorLabels)
            {
                subject.AddErrorLabel(errorLabel);
            }

            subject.RemoveErrorLabel(removeErrorLabel);

            subject.ErrorLabels.Should().Equal(errorLabels.Where(x => x != removeErrorLabel));
        }
 public void Serialization_should_work()
 {
     var innerException = new Exception("inner");
     var exception = new MongoException("message", innerException);
     var formatter = new BinaryFormatter();
     using (var stream = new MemoryStream())
     {
         formatter.Serialize(stream, exception);
         stream.Position = 0;
         var rehydrated = (MongoException)formatter.Deserialize(stream);
         rehydrated.Message.Should().Be("message");
         rehydrated.InnerException.Message.Should().Be("inner");
     }
 }
Exemplo n.º 11
0
        public void Serialization_should_work()
        {
            var innerException = new Exception("inner");
            var exception      = new MongoException("message", innerException);
            var formatter      = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, exception);
                stream.Position = 0;
                var rehydrated = (MongoException)formatter.Deserialize(stream);
                rehydrated.Message.Should().Be("message");
                rehydrated.InnerException.Message.Should().Be("inner");
            }
        }
Exemplo n.º 12
0
        public void Serialization_should_work()
        {
            var subject = new MongoException(_message, _innerException);

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

                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
            }
        }
Exemplo n.º 13
0
        public void AddErrorLabels_should_have_expected_result(
            [Values(0, 1, 2, 3)] int existingCount)
        {
            var subject = new MongoException(_message);
            for (var i = 0; i < existingCount; i++)
            {
                var errorLabel = $"label{i}";
                subject.AddErrorLabel(errorLabel);
            }
            var existingErrorLabels = new List<string>(subject.ErrorLabels);
            var newErrorLabel = "x";

            subject.AddErrorLabel(newErrorLabel);

            subject.ErrorLabels.Should().Equal(existingErrorLabels.Concat(new[] { newErrorLabel }));
        }
Exemplo n.º 14
0
        public void HasErrorLabel_should_have_expected_result(
            [Values(0, 1, 2, 3)] int existingCount)
        {
            var subject = new MongoException(_message);
            for (var i = 0; i < existingCount; i++)
            {
                var errorLabel = $"label{i}";
                subject.AddErrorLabel(errorLabel);
            }

            foreach (var errorLabel in subject.ErrorLabels)
            {
                subject.HasErrorLabel(errorLabel).Should().BeTrue();
            }
            subject.HasErrorLabel("x").Should().BeFalse();
        }
Exemplo n.º 15
0
        public void Serialization_should_work()
        {
            var subject = new MongoException(_message, _innerException);

            var formatter = new BinaryFormatter();

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

                rehydrated.Message.Should().Be(subject.Message);
                rehydrated.InnerException.Message.Should().Be(subject.InnerException.Message); // Exception does not override Equals
            }
        }
        //
        // WriteToEventLog
        //   A helper function that writes exception detail to the event log. Exceptions
        // are written to the event log as a security measure to avoid private database
        // details from being returned to the browser. If a method does not return a status
        // or boolean indicating the action succeeded or failed, a generic exception is also
        // thrown by the caller.
        //
        private void WriteToEventLog(MongoException e, string action)
        {
            EventLog log = new EventLog();
            log.Source = eventSource;
            log.Log = eventLog;

            string message = exceptionMessage + "\n\n";
            message += "Action: " + action + "\n\n";
            message += "Exception: " + e.ToString();

            log.WriteEntry(message);
        }