示例#1
0
        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"));
        }
示例#2
0
        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"));
        }
示例#3
0
        public void CanWriteDiagnosticMessageWithEventID()
        {
            var testableLogger = new TestableLogger();

            testableLogger.TraceToDeveloper("Message", 99);

            Assert.AreEqual("Message", testableLogger.Message);
            Assert.AreEqual(null, testableLogger.Category);
            Assert.AreEqual(99, testableLogger.EventID);
            Assert.AreEqual(TraceSeverity.Medium, testableLogger.TraceSeverity);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        public void CanWriteDiagnosticMessageWithSingleCategory()
        {
            var testableLogger = new TestableLogger();

            testableLogger.TraceToDeveloper("Message", "Category");

            Assert.AreEqual("Message", testableLogger.Message);
            Assert.AreEqual("Category", testableLogger.Category);
            Assert.AreEqual(0, testableLogger.EventID);
            Assert.AreEqual(TraceSeverity.Medium, testableLogger.TraceSeverity);
        }