public void Log_WithNullArgument_ThrowsException()
        {
            // Arrange
            ILogger provider = new FakeLoggingProviderBase();

            // Act
            provider.Log(null);
        }
        public void Initialize_WithNullConfiguration_ThrowsException()
        {
            // Arrange
            var provider = new FakeLoggingProviderBase();
            NameValueCollection invalidConfiguration = null;

            // Act
            provider.Initialize("Valid provider name", invalidConfiguration);
        }
        public void Initiailze_WithConfigurationWithInvalidThreshold_ThrowsException()
        {
            // Arrange
            var provider = new FakeLoggingProviderBase();
            var configurationWithInvalidThreshold = new NameValueCollection();

            configurationWithInvalidThreshold.Add("threshold", "Incorrect threshold");

            // Act
            provider.Initialize("Valid provider name", configurationWithInvalidThreshold);
        }
        public void Initialize_WithEmptyConfiguration_Succeeds()
        {
            // Arrange
            var provider           = new FakeLoggingProviderBase();
            var emptyConfiguration = new NameValueCollection();
            var validProviderName  = "Valid name";

            // Act
            // Using an empty configuration should succeed, the 'threshold' and 'fallbackProvider' attributes
            // are optional.
            provider.Initialize(validProviderName, emptyConfiguration);
        }
        public void Log_WithValidEntry_CallsLogInternal()
        {
            // Arrange
            var provider      = new FakeLoggingProviderBase();
            var validLogEntry = new LogEntry(LoggingEventType.Error, "message", "source", new Exception());

            // Act
            ((ILogger)provider).Log(validLogEntry);

            // Assert
            Assert.AreEqual(validLogEntry, provider.LastEntry);
        }
        public void Initialize_WithNonEmptyProviderName_SetsNamePropertyToSuppliedValue()
        {
            // Arrange
            var provider             = new FakeLoggingProviderBase();
            var validConfiguration   = new NameValueCollection();
            var expectedProviderName = "Valid name";

            // Act
            provider.Initialize(expectedProviderName, validConfiguration);

            // Assert
            Assert.AreEqual(expectedProviderName, provider.Name);
        }
        public void Initialize_WithUnrecognizedAttribute_Succeeds()
        {
            // Arrange
            var provider      = new FakeLoggingProviderBase();
            var configuration = new NameValueCollection();

            configuration.Add("badAttribute", "some value");

            // Act
            // While the initialization has an unrecognized attribute, the initialization still succeeds.
            // Classes inheriting from LoggingProviderBase should validate and throw an exception.
            provider.Initialize("Valid provider name", configuration);
        }
        public void Initialize_CallsTwice_ThrowsException()
        {
            // Arrange
            var provider           = new FakeLoggingProviderBase();
            var validConfiguration = new NameValueCollection();
            var validProviderName  = "Valid provider name";

            // Act
            provider.Initialize(validProviderName, validConfiguration);

            // This second call should fail.
            provider.Initialize(validProviderName, validConfiguration);
        }
        public void Initialize_WithConfigurationWithoutThreshold_SetsThesholdPropertyToDebug()
        {
            // Arrange
            var provider = new FakeLoggingProviderBase();
            var configurationWithoutThreshold = new NameValueCollection();
            var expectedThreshold             = LoggingEventType.Debug;

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

            // Assert
            Assert.AreEqual(expectedThreshold, provider.Threshold);
        }
        public void Initialize_WithNullProviderName_SetNamePropertyToTypeName()
        {
            // Arrange
            var    provider             = new FakeLoggingProviderBase();
            var    validConfiguration   = new NameValueCollection();
            string emptyProviderName    = null;
            var    expectedProviderName = "FakeLoggingProviderBase";

            // Act
            provider.Initialize(emptyProviderName, validConfiguration);

            // Assert
            Assert.AreEqual(expectedProviderName, provider.Name);
        }
        public void Initialize_WithConfigurationWithThreshold_SetsThesholdPropertyToSuppliedValue()
        {
            // Arrange
            var provider = new FakeLoggingProviderBase();
            var configurationWithThreshold = new NameValueCollection();

            configurationWithThreshold.Add("threshold", "Critical");
            var expectedThreshold = LoggingEventType.Critical;

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

            // Assert
            Assert.AreEqual(expectedThreshold, provider.Threshold);
        }
        public void Log_WithThresholdHigherThanSuppliedMessage_DoesNotLog()
        {
            // Arrange
            var provider = new FakeLoggingProviderBase();
            var configurationWithHighTreshold = new NameValueCollection();

            configurationWithHighTreshold.Add("threshold", "Information");
            provider.Initialize("Valid name", configurationWithHighTreshold);

            var validLogEntryWithLogSeverity = new LogEntry(LoggingEventType.Debug, "message", null, null);

            // Act
            ((ILogger)provider).Log(validLogEntryWithLogSeverity);

            // Assert
            Assert.IsNull(provider.LastEntry, "The entry should not be logged.");
        }
        public void FakeLoggingProviderBase_WithNullName_UsesProviderTypeName()
        {
            // Arrange
            var provider      = new FakeLoggingProviderBase();
            var configuration = new NameValueCollection();

            configuration.Add("invalid attribute", "some value");

            try
            {
                // Act
                provider.CheckForUnrecognizedAttributes(null, configuration);

                // Assert
                Assert.Fail("Expection expected.");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("FakeLoggingProviderBase"),
                              "The exception should contain the type name of the provider.");
            }
        }