Example #1
0
        public void ShouldTellProviderToOpenFileAfterItIsSet()
        {
            // Define variables and constants
            MockLoggingProvider provider = new MockLoggingProvider();

            // Set up context


            // Execute
            Logger.LoggingProvider = provider;

            // Assert outcome
            Assert.AreEqual(Logger.FileLocation, provider.LastLogFileLocation);
        }
Example #2
0
        public void TestLogMethods()
        {
            // Define variables and constants
            string[] messages = new string[] {
                "1", "2", "3", "4"
            };
            Exception[] exceptions = new Exception[] {
                new ApplicationException(),
                new ApplicationException(),
                new ApplicationException(),
                new ApplicationException()
            };
            MockLoggingProvider provider = new MockLoggingProvider();

            // Set up context
            Logger.LoggingProvider = provider;

            // Execute
            for (int i = 0; i < 4; ++i)
            {
                switch (i)
                {
                case 0:
                    Logger.Debug(messages[i], exceptions[i]);
                    Assert.AreEqual(LogMessageSeverity.Debug, provider.LasMessageSeverity);
                    break;

                case 1:
                    Logger.Log(messages[i], exceptions[i]);
                    Assert.AreEqual(LogMessageSeverity.Standard, provider.LasMessageSeverity);
                    break;

                case 2:
                    Logger.Warn(messages[i], exceptions[i]);
                    Assert.AreEqual(LogMessageSeverity.Warning, provider.LasMessageSeverity);
                    break;

                case 3:
                    Logger.Fatal(messages[i], exceptions[i]);
                    Assert.AreEqual(LogMessageSeverity.Fatal, provider.LasMessageSeverity);
                    break;
                }

                Assert.AreEqual(messages[i], provider.LastMessage);
                Assert.AreEqual(exceptions[i], provider.LastMessageException);
            }

            // Assert outcome
        }
Example #3
0
        public void ShouldUpdateFileLocationInProviderWhenSet()
        {
            // Define variables and constants
            const string        TEST_FILE_LOCATION = "test.log";
            MockLoggingProvider provider           = new MockLoggingProvider();

            // Set up context
            Logger.LoggingProvider = provider;

            // Execute
            Logger.FileLocation = TEST_FILE_LOCATION;

            // Assert outcome
            Assert.AreEqual(TEST_FILE_LOCATION, provider.LastLogFileLocation);
        }
Example #4
0
        public void ShouldRejectDisposedLoggingProviders()
        {
            // Define variables and constants
            ILoggingProvider disposedLoggingProvider = new MockLoggingProvider();

            disposedLoggingProvider.Dispose();

            // Set up context


            // Execute
            Logger.LoggingProvider = disposedLoggingProvider;

            // Assert outcome
        }
Example #5
0
        public void ShouldDisposeOldProviderWhenSettingANewOne()
        {
            // Define variables and constants
            ILoggingProvider oldProvider = new MockLoggingProvider();
            ILoggingProvider newProvider = new MockLoggingProvider();

            // Set up context
            Logger.LoggingProvider = oldProvider;

            // Execute
            Logger.LoggingProvider = newProvider;

            // Assert outcome
            Assert.IsTrue(oldProvider.IsDisposed);
            Assert.IsFalse(newProvider.IsDisposed);
        }