public void ExceptionsInDataPropertyShouldBeFormatted() { var exception = new Exception("MyMessage"); Exception innerException = null; try { ThrowInnerException(); } catch (Exception ex) { innerException = ex; } exception.Data.Add("OtherException", innerException); var testableLogger = new TestableLogger(); testableLogger.LogToOperations(exception, 0, EventLogEntryType.Error, null); Assert.IsTrue(testableLogger.Message.Contains("OtherException")); Assert.IsTrue(testableLogger.Message.Contains("InvalidOperationException")); Assert.IsTrue(testableLogger.Message.Contains("ThrowInnerException()")); Assert.IsTrue(testableLogger.Message.Contains("MyDataKey")); Assert.IsTrue(testableLogger.Message.Contains("MyDataValue")); }
public void ExceptionMessagesAreFormatted() { var testableLogger = new TestableLogger(); try { ThrowException(); } catch (Exception ex) { testableLogger.LogToOperations(ex, 99, EventLogEntryType.Error, "Blurp"); } // Make sure all the exception messages are displayed Assert.IsTrue(testableLogger.Message.Contains("Message1")); Assert.IsTrue(testableLogger.Message.Contains("Message2")); Assert.IsTrue(testableLogger.Message.Contains("Message3")); // make sure the stacktraces are displayed Assert.IsTrue(testableLogger.Message.Contains("ThrowInnerException()")); Assert.IsTrue(testableLogger.Message.Contains("ThrowException()")); // make sure the exception types are displayed Assert.IsTrue(testableLogger.Message.Contains("ArgumentException")); Assert.IsTrue(testableLogger.Message.Contains("AccessViolationException")); Assert.IsTrue(testableLogger.Message.Contains("InvalidOperationException")); Assert.IsTrue(testableLogger.Message.Contains("MyDataKey")); Assert.IsTrue(testableLogger.Message.Contains("MyDataValue")); }
public void CanWriteErrorMessageWithSingleCategoryAndEventID() { var testableLogger = new TestableLogger(); testableLogger.LogToOperations("Message", 99, "Category"); Assert.AreEqual("Message", testableLogger.Message); Assert.AreEqual("Category", testableLogger.Category); Assert.AreEqual(99, testableLogger.EventID); Assert.AreEqual(EventLogEntryType.Error, testableLogger.EventLogSeverity); }
public void CanWriteErrorMessage() { var testableLogger = new TestableLogger(); testableLogger.LogToOperations("Message"); Assert.AreEqual("Message", testableLogger.Message); Assert.AreEqual(null, testableLogger.Category); Assert.AreEqual(0, testableLogger.EventID); Assert.AreEqual(EventLogEntryType.Error, testableLogger.EventLogSeverity); }