public void LogInternal_WithNullArgument_ThrowsException()
        {
            // Arrange
            var provider = new FakeDebugLoggingProvider();

            // Act
            provider.LogInternal(null);
        }
        public void Initialize_WithValidArguments_Succeeds()
        {
            // Arrange
            var provider           = new FakeDebugLoggingProvider();
            var validConfiguration = CreateValidConfiguration();

            // Act
            provider.Initialize("Valid provider name", validConfiguration);
        }
        public void Initialize_WithNullConfiguration_ThrowsException()
        {
            // Arrange
            var provider = new FakeDebugLoggingProvider();
            NameValueCollection invalidConfiguration = null;

            // Act
            provider.Initialize("Valid provider name", invalidConfiguration);
        }
        public void Initialize_ConfigurationWithUnrecognizedAttributes_ThrowsException()
        {
            // Arrange
            var provider = new FakeDebugLoggingProvider();
            var configurationWithUnrecognizedAttribute = CreateValidConfiguration();

            configurationWithUnrecognizedAttribute.Add("unknown attribute", "some value");

            // Act
            provider.Initialize("Valid provider name", configurationWithUnrecognizedAttribute);
        }
        public void Log_ProviderInitializedWithDebugThresholdThroughConstructor_LogsMessage()
        {
            // Arrange
            var expectedMessage = "Hello";
            var provider        = new FakeDebugLoggingProvider(LoggingEventType.Debug);

            // Act
            provider.Log(expectedMessage);

            // Assert
            Assert.IsTrue(provider.TextWrittenToDebugWindow.Contains(expectedMessage), "Message not logged");
        }
        public void Log_ProviderInitializedWithCriticalThresholdThroughConstructor_DoesNotLogMessage()
        {
            // Arrange
            var expectedMessage = "Hello";
            var provider        = new FakeDebugLoggingProvider(LoggingEventType.Critical);

            // Act
            provider.Log(expectedMessage);

            // Assert
            Assert.AreEqual(string.Empty, provider.TextWrittenToDebugWindow,
                            "Actual text: " + provider.TextWrittenToDebugWindow);
        }
        public void Log_ProviderInitializedWithDefaultConstructor_LogsSuccesfully()
        {
            // Arrange
            string expectedMessage = "Some message";

            var provider = new FakeDebugLoggingProvider();

            // Act
            // In contrast with most other providers, this provider should succeed in logging the event when
            // it was created with the default constructor, and not initialized with Initialize(string, NVC).
            // This behavior is different, because the the only initialization argument the provider needs is
            // the severity, which will be retain its default value of 'Debug' when not set.
            provider.Log(LoggingEventType.Debug, expectedMessage);

            // Arrange
            Assert.IsTrue(provider.TextWrittenToDebugWindow.Contains(expectedMessage),
                          "The expected message was not logged. Actual: " + provider.TextWrittenToDebugWindow);
        }
        public void Log_WithValidEntry_WritesExpectedTextToConsole()
        {
            // Arrange
            var provider           = new FakeDebugLoggingProvider();
            var validConfiguration = new NameValueCollection();

            provider.Initialize("Valid provider name", validConfiguration);
            var expectedText =
                "LoggingEvent:\r\n" +
                "Severity:\tError\r\n" +
                "Message:\tValid message\r\n";

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

            // Assert
            string actualText = provider.TextWrittenToDebugWindow;

            Assert.AreEqual(expectedText, actualText);
        }