Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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));
        }
Exemplo n.º 5
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.º 6
0
        public void Serialization_should_work()
        {
            var subject = new MongoException(_message, _innerException);
            subject.AddErrorLabel("one");

            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
                rehydrated.ErrorLabels.Should().Equal(subject.ErrorLabels);
            }
        }