Exemple #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);
            }
        }
Exemple #2
0
        public void Initialize_WithNullConfiguration_ThrowsException()
        {
            // Arrange
            var provider = new FakeWindowsEventLogLoggingProvider();
            NameValueCollection invalidConfiguration = null;

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

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

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

            // Act
            provider.Log("Some message");
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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.");
            }
        }