/// <summary>
        /// Sets the current application configuration provider to the specified one
        /// </summary>
        /// <param name="provider">Application configuration provider instance</param>
        public static void Configure(IConfigurationProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            var oldValue = CurrentProvider;

            CurrentProvider  = provider;
            ProviderSettings = new AppConfigurationSettings(provider.GetType());
            OnOnConfigurationChanged(
                new ConfigurationChangedEventArgs <IConfigurationProvider>(oldValue, CurrentProvider));
        }
        /// <summary>
        /// Sets the current application configuration provider according to the
        /// specified settings.
        /// </summary>
        /// <param name="settings">Application configuration provider settings</param>
        public static void Configure(AppConfigurationSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            var oldValue = CurrentProvider;

            ProviderSettings = settings;
            CurrentProvider  = ConfigurationHelper.CreateInstance(settings.Provider,
                                                                  settings.ConstructorParameters,
                                                                  settings.Properties) as IConfigurationProvider;
            OnOnConfigurationChanged(
                new ConfigurationChangedEventArgs <IConfigurationProvider>(oldValue, CurrentProvider));
        }
        public void WriteXmlAndReadXmlWorksAsExpectedWithEmptyProperties()
        {
            // --- Act
            var settings = new AppConfigurationSettings(null, null);

            var element = settings.WriteToXml("Temp");
            var newSetting = new AppConfigurationSettings(element);

            // --- Assert
            newSetting.Provider.ShouldEqual(typeof(AppConfigProvider));
            newSetting.InstancePrefix.ShouldEqual("");
            newSetting.InstanceName.ShouldEqual("");
            newSetting.ConstructorParameters.ShouldHaveCountOf(0);
            newSetting.Properties.ShouldHaveCountOf(0);
        }
        public void DefaultLogSourceMapperWorksAsExpected()
        {
            // --- Arrange
            var configSettings = new AppConfigurationSettings(
                typeof(AppConfigProvider), null, null, "TestInstancePrefix", "TestInstanceName");
            AppConfigurationManager.Configure(configSettings);
            var mapper1 = new DefaultLogSourceNameMapper();
            configSettings = new AppConfigurationSettings(typeof(AppConfigProvider));
            AppConfigurationManager.Configure(configSettings);
            var mapper2 = new DefaultLogSourceNameMapper();
            var mapper3 = new DefaultLogSourceNameMapper("Dummy");

            // --- Act
            var name1 = mapper1.Map("Hi");
            var name2 = mapper2.Map("Hello");
            var name3 = mapper3.Map("Howdy");

            // --- Assert
            name1.ShouldEqual("TestInstancePrefixHi");
            name2.ShouldEqual("Hello");
            name3.ShouldEqual("DummyHowdy");
        }
        public void WithInstancePrefixWorksAsExpected()
        {
            // --- Arrange
            var configSettings = new AppConfigurationSettings(
                typeof(AppConfigProvider), null, null, "TestInstancePrefix", "TestInstanceName");
            AppConfigurationManager.Configure(configSettings);
            WindowsEventLogger.LogSourceMapper = new DefaultLogSourceNameMapper();
            var eventLog = new EventLog(SEEMPLEST_LOG2);

            // --- Act
            WindowsEventLogger.Log<WithStringNameAttribute>("Message");

            // --- Assert
            var after = eventLog.Entries;
            var afterCount = after.Count;
            afterCount.ShouldEqual(1);
            var lastentry = after[after.Count - 1];
            lastentry.Category.ShouldEqual("(5)");
            lastentry.InstanceId.ShouldEqual(3);
            lastentry.Message.ShouldEqual("Message");
            lastentry.Source.ShouldEqual("TestInstancePrefix" + SEEMPLEST_SOURCE);
            lastentry.EntryType.ShouldEqual(EventLogEntryType.Information);
            eventLog.Dispose();
        }
 public void TestInit()
 {
     if (EventLog.Exists(SEEMPLEST_LOG)) EventLog.Delete(SEEMPLEST_LOG);
     if (EventLog.Exists(SEEMPLEST_LOG2)) EventLog.Delete(SEEMPLEST_LOG2);
     var configSettings = new AppConfigurationSettings(typeof (AppConfigProvider));
     AppConfigurationManager.Configure(configSettings);
     WindowsEventLogger.LogSourceMapper = new DefaultLogSourceNameMapper();
     WindowsEventLogger.Reset();
 }