Exemplo n.º 1
0
        public void CanChangeTraceLevel()
        {
            var loggerResult = new LoggerEventArgs();
            var testClass = new MockLoggingClass();
            var logger = testClass.GetLogger();

            testClass.LoggerEvent += (sender, args) =>
            {
                loggerResult = args;
            };

            const string expectedMessage = "- Hello World";

            // Default priority for LogVerbose is low - we'll change to high
            testClass.LogMessage(logger.LogVerbose,
                "Hello {0}", "World", Priority.High);
            Assert.AreEqual(Category.Debug, loggerResult.Category);
            Assert.AreEqual(Priority.High, loggerResult.Priority);
            Assert.AreEqual(expectedMessage, loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);

            // Set trace level to verbose
            var appSettings = testClass.GetAppSettings();
            appSettings.TraceLevel = (int)GwnTraceLevel.Verbose;

            testClass.LogMessage(logger.LogVerbose, expectedMessage);
            Assert.IsTrue(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogInfo, expectedMessage);
            Assert.IsTrue(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogWarning, expectedMessage);
            Assert.IsTrue(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogError, expectedMessage);
            Assert.IsTrue(loggerResult.IsLoggingPermitted);

            // Set trace level to Info (level 3)
            appSettings.TraceLevel = (int)GwnTraceLevel.Info;

            // Verbose should be false (level 4)
            testClass.LogMessage(logger.LogVerbose, expectedMessage);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);

            // Info should be true (level 3)
            testClass.LogMessage(logger.LogInfo, expectedMessage);
            Assert.IsTrue(loggerResult.IsLoggingPermitted);
        }
Exemplo n.º 2
0
        public void CanChangeDefaultPriority()
        {
            var loggerResult = new LoggerEventArgs();
            var testClass = new MockLoggingClass();
            var logger = testClass.GetLogger();

            testClass.LoggerEvent += (sender, args) =>
            {
                loggerResult = args;
            };

            // Default priority for LogVerbose is low - we'll change to high
            testClass.LogMessage(logger.LogVerbose,
                "Hello {0}", "World", Priority.High);
            Assert.AreEqual(Category.Debug, loggerResult.Category);
            Assert.AreEqual(Priority.High, loggerResult.Priority);
            Assert.AreEqual("- Hello World", loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);
        }
Exemplo n.º 3
0
 public void CanGetLogger()
 {
     var logger = new MockLoggingClass().GetLogger();
     Assert.IsNotNull(logger);
 }
Exemplo n.º 4
0
        public void CanUpdateLoggingWithClassNamePrefix()
        {
            var loggerResult = new LoggerEventArgs();
            var testClass = new MockLoggingClass();
            var logger = testClass.GetLogger();

            testClass.LoggerEvent += (sender, args) =>
            {
                loggerResult = args;
            };
            const string expectedMessage =
                "- GwnLoggerFixture.MethodName: Hello World 100";
            //   ^^^^^^^^^^^^^^^^
            // Default priority for LogVerbose is low - we'll change to high
            // by placing Priority.High in the parameter list.  We'll also send
            // "this" which will cause the class name to prefix the logging result
            testClass.LogMessage(logger.LogVerbose,
                "MethodName: Hello {0} {1}", "World",
                100, Priority.High, this);

            Assert.AreEqual(Category.Debug, loggerResult.Category);
            Assert.AreEqual(Priority.High, loggerResult.Priority);
            Assert.AreEqual(expectedMessage, loggerResult.Message);
        }
Exemplo n.º 5
0
        public void CanOverridePriority()
        {
            var loggerResult = new LoggerEventArgs();
            var testClass = new MockLoggingClass();
            var logger = testClass.GetLogger();

            testClass.LoggerEvent += (sender, args) =>
            {
                loggerResult = args;
            };

            testClass.LogMessage(logger.LogError, "Hello {0}","World");
            Assert.AreEqual(Category.Exception, loggerResult.Category);
            Assert.AreEqual(Priority.High, loggerResult.Priority);
            Assert.AreEqual("X Hello World", loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogWarning, "TraceLevel = {0}", 2);
            Assert.AreEqual(Category.Warn, loggerResult.Category);
            Assert.AreEqual(Priority.Medium, loggerResult.Priority);
            Assert.AreEqual("! TraceLevel = 2", loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogInfo, "{0} Information", "Good");
            Assert.AreEqual(Category.Info, loggerResult.Category);
            Assert.AreEqual(Priority.Low, loggerResult.Priority);
            Assert.AreEqual("+ Good Information", loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);

            testClass.LogMessage(logger.LogVerbose, "To much {0}", "Information");
            Assert.AreEqual(Category.Debug, loggerResult.Category);
            Assert.AreEqual(Priority.Low, loggerResult.Priority);
            Assert.AreEqual("- To much Information", loggerResult.Message);
            Assert.IsFalse(loggerResult.IsLoggingPermitted);
        }