public void ShouldExtractAndCorrectlyFormatDeepErrorHierarchies() { // Arrange var leafError1 = new Error("(Leaf) Internal app error 1", "Exception"); var leafError2 = new Error("(Leaf) Internal app error 2", "Exception"); var leafError4 = new Error("(Leaf) Internal app error 4", "Exception"); var branchError1 = new Error("(Branch) app error 1", "Exception", leafError1); var branchError2 = new Error("(Branch) app error 2", "Exception", leafError2); var rootError = new Error("(Root) app error", "Exception", new List <Error> { branchError1, branchError2, leafError4 }); var expectedMessage = string.Join( Environment.NewLine, "(Root) app error", " (Branch) app error 1", " (Leaf) Internal app error 1", " (Branch) app error 2", " (Leaf) Internal app error 2", " (Leaf) Internal app error 4"); var options = GetOptions(); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(rootError); // Assert Assert.Equal(expectedMessage, result); }
public void ShouldExtractAndCorrectlyFormatAggregateErrorMessages() { // Arrange var internalError1 = new Error("Internal app error 1", "Exception"); var internalError2 = new Error("Internal app error 2", "Exception"); var exception = new Error("Our App Error", "Exception", new List <Error> { internalError1, internalError2 }); var expectedMessage = string.Join( Environment.NewLine, "Our App Error", " Internal app error 1", " Internal app error 2"); var options = GetOptions(); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(exception); // Assert Assert.Equal(expectedMessage, result); }
public void ShouldExtractAndCorrectlyFormatMultilineErrorMessages() { // Arrange var internalError1 = new Error(string.Join( Environment.NewLine, "Internal Error", "Internal Error Details"), "Exception"); var exception = new Error(string.Join( Environment.NewLine, "Our App Error", "Our App Error Details"), "Exception", internalError1); var expectedMessage = string.Join( Environment.NewLine, "Our App Error", "Our App Error Details", " Internal Error", " Internal Error Details"); var options = GetOptions(); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(exception); // Assert Assert.Equal(expectedMessage, result); }
public void ShouldReturnOriginalErrorMessage() { // Arrange var error = new Error("Our App Error", "Exception"); var options = GetOptions(); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(error); // Assert Assert.Equal("Our App Error", result); }
public void ShouldReturnOriginalAndNestedErrorMessageWithCorrectIndentation() { // Arrange var options = GetOptions(); var internalError = new Error("Internal app error", "Exception"); var error = new Error("Our App Error", "Exception", internalError); var expectedMessage = string.Join( Environment.NewLine, "Our App Error", " Internal app error"); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(error); // Assert Assert.Equal(expectedMessage, result); }
public void ShouldExtractAndFormatErrorMessagesUsingConfiguredIndentationSymbol() { // Arrange var internalError1 = new Error("Internal app error 1", "Exception"); var exception = new Error("Our App Error", "Exception", new List <Error> { internalError1 }); var expectedMessage = string.Join( Environment.NewLine, "Our App Error", "///Internal app error 1"); var options = GetOptions("///"); var sut = new HierarchicalErrorMessageFormatter(options); // Act var result = sut.FormatErrorMessages(exception); // Assert Assert.Equal(expectedMessage, result); }