public void AddErrorLabels_should_not_add_duplicates() { var subject = new MongoException(_message); subject.AddErrorLabel("one"); subject.AddErrorLabel("one"); subject.ErrorLabels.Should().HaveCount(1); }
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 })); }
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); }
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 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(); }
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); } }