Beispiel #1
0
        public void Initialize_WithMissingLogNameConfiguration_ThrowsException()
        {
            // Arrange
            var validProviderName    = "Valid provider name";
            var provider             = new FakeWindowsEventLogLoggingProvider();
            var invalidConfiguration = CreateValidConfiguration();

            invalidConfiguration.Remove("logName");

            try
            {
                // Act
                provider.Initialize(validProviderName, invalidConfiguration);

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (ProviderException ex)
            {
                Assert.IsTrue(ex.Message.Contains("'logName'"),
                              "The exception message should contain the name of the attribute. Actual message: " + ex.Message);
                Assert.IsTrue(ex.Message.Contains(validProviderName),
                              "The exception message should contain the name of the provider. Actual message: " + ex.Message);
            }
        }
Beispiel #2
0
        public void BuildEventLogMessage_WithNullLogEntry_ThrowsException()
        {
            // Arrange
            var      provider     = new FakeWindowsEventLogLoggingProvider();
            LogEntry invalidEntry = null;

            // Act
            provider.BuildEventLogMessage(invalidEntry);
        }
Beispiel #3
0
        public void Initialize_WithNullConfiguration_ThrowsException()
        {
            // Arrange
            var provider = new FakeWindowsEventLogLoggingProvider();
            NameValueCollection invalidConfiguration = null;

            // Act
            provider.Initialize("Valid provider name", invalidConfiguration);
        }
Beispiel #4
0
        public void Initialize_WithValidConfiguration_Succeeds()
        {
            // Arrange
            var provider           = new FakeWindowsEventLogLoggingProvider();
            var validConfiguration = CreateValidConfiguration();

            // Act
            provider.Initialize("Valid provider name", validConfiguration);
        }
Beispiel #5
0
        public void Log_InitializedProvider_Succeeds()
        {
            // Arrange
            var provider = new FakeWindowsEventLogLoggingProvider();

            provider.Initialize("Valid name", CreateValidConfiguration());

            // Act
            provider.Log("Some message");
        }
Beispiel #6
0
        public void LogInternal_WithNullArgument_ThrowsException()
        {
            // Arrange
            var provider = new FakeWindowsEventLogLoggingProvider();

            LogEntry invalidEntry = null;

            // Act
            provider.Public_LogInternal(invalidEntry);
        }
Beispiel #7
0
        public void Log_WithLoggingEventTypeDebug_LogsEventWithoutEventLogEntryType()
        {
            // Arrange
            var loggedLoggingEventType = LoggingEventType.Debug;
            FakeWindowsEventLogLoggingProvider provider = BuildInitializedProvider();

            // Act
            provider.Log(loggedLoggingEventType, "Valid message");

            // Assert
            Assert.AreEqual(null, provider.LoggedType);
        }
Beispiel #8
0
        private static FakeWindowsEventLogLoggingProvider BuildInitializedProvider()
        {
            var provider = new FakeWindowsEventLogLoggingProvider();

            var configuration = new NameValueCollection();

            configuration.Add("source", "a valid source name");
            configuration.Add("logName", "a valid log name");

            provider.Initialize(null, configuration);

            return(provider);
        }
Beispiel #9
0
        public void Log_WithLoggingEventTypeInformation_LogsEventLogEntryTypeInformation()
        {
            // Arrange
            var loggedLoggingEventType = LoggingEventType.Information;
            var expectedWindowsLogType = EventLogEntryType.Information;
            FakeWindowsEventLogLoggingProvider provider = BuildInitializedProvider();

            // Act
            provider.Log(loggedLoggingEventType, "Valid message");

            // Assert
            Assert.AreEqual(expectedWindowsLogType, provider.LoggedType);
        }
Beispiel #10
0
        public void BuildEventLogMessage_WithSimpleLogEntry_BuildsExpectedLogMessage()
        {
            // Arrange
            var provider = new FakeWindowsEventLogLoggingProvider();
            var entry    = new LogEntry(LoggingEventType.Error, "Test message", "This is a source", null);
            var expectedEventLogMessage = "Test message\r\nSeverity: Error\r\nSource: This is a source\r\n";

            // Act
            var actualEventLogMessage = provider.BuildEventLogMessage(entry);

            // Assert
            Assert.AreEqual(expectedEventLogMessage, actualEventLogMessage);
        }
Beispiel #11
0
        public void Initialize_WithValidConfiguration_SetsLogNameProperty()
        {
            // Arrange
            var expectedLogName    = "The expected log name";
            var provider           = new FakeWindowsEventLogLoggingProvider();
            var validConfiguration = CreateValidConfiguration();

            validConfiguration["logName"] = expectedLogName;

            // Act
            provider.Initialize("Valid provider name", validConfiguration);

            // Assert
            Assert.AreEqual(expectedLogName, provider.LogName);
        }
Beispiel #12
0
        public void Initialize_WithUnrecognizedAttribute_ThrowException()
        {
            // Arrange
            var provider             = new FakeWindowsEventLogLoggingProvider();
            var invalidConfiguration = CreateValidConfiguration();

            invalidConfiguration.Add("bad attribute", "a bad value");

            try
            {
                // Act
                provider.Initialize("Valid provider name", invalidConfiguration);

                // Assert
                Assert.Fail("Initialize was expected to throw an Exception.");
            }
            catch (ProviderException ex)
            {
                Assert.IsTrue(ex.Message.Contains("bad attribute"), "The exception message should contain the name of the bad attribute.");
            }
        }
Beispiel #13
0
        public void BuildEventLogMessage_WithLogEntryWithThrownException_BuildsExpectedLogMessage()
        {
            // Arrange
            var       provider         = new FakeWindowsEventLogLoggingProvider();
            var       exceptionMessage = "Invalid operation";
            Exception thrownException  = GetThrownException(exceptionMessage);
            var       entry            =
                new LogEntry(LoggingEventType.Error, "Test message", "This is a source", thrownException);
            var expectedEventLogMessageStart =
                "Test message\r\n" +
                "Severity: Error\r\n" +
                "Source: This is a source\r\n" +
                "\r\n" +
                "System.InvalidOperationException: Invalid operation\r\n";

            // Act
            var actualEventLogMessage = provider.BuildEventLogMessage(entry);

            // Arrange
            Assert.IsTrue(actualEventLogMessage.StartsWith(expectedEventLogMessageStart),
                          "EventLogMessage doesn't start with the expected text.");
            Assert.AreNotEqual(expectedEventLogMessageStart, actualEventLogMessage,
                               "The actualEventLogMessage does not contain a stack trace.");
        }