public void Init()
        {
            Directory.CreateDirectory(_tempDirectory);

            _configManager = new RuntimeConfigManager()
            {
                ConfigDirectory = _tempDirectory
            };

            var config = new LoggingConfig()
            {
                LoggerConfigs = new List <ModuleLoggerConfig>()
                {
                    new ModuleLoggerConfig()
                    {
                        LoggerName = "Test"
                    }
                }
            };

            _configManager.SaveConfiguration(config);
            _management = new ServerLoggerManagement()
            {
                ConfigManager = _configManager
            };

            _host = new ModuleManager()
            {
                ConfigManager    = _configManager,
                LoggerManagement = _management
            };
            _management.ActivateLogging(_host);
        }
        public void SaveTest(bool liveUpdate)
        {
            DeleteTempFolder();
            CreateTempFolder();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            var configChangedEvent            = false;

            // create a config by saving it.
            _manager.SaveConfiguration(new RuntimeConfigManagerTestConfig1(), liveUpdate);

            // try to read the config
            var config = _manager.GetConfiguration <RuntimeConfigManagerTestConfig1>(false);

            Assert.NotNull(config, "Config not saved!");
            // get a copy of the config
            var copyOfConfig = _manager.GetConfiguration <RuntimeConfigManagerTestConfig1>(true);

            // add the config changed event
            config.ConfigChanged += delegate(object sender, ConfigChangedEventArgs args)
            {
                configChangedEvent = true;
                Assert.True(args.Contains(() => copyOfConfig.BooleanField), "the changed event do not acknowlege the correct property.");
                manualResetEvent.Set();
            };

            // change a property of the copied config (the original will not cause any event on save)
            copyOfConfig.BooleanField = true;
            _manager.SaveConfiguration(copyOfConfig, liveUpdate);

            // wait for the event
            manualResetEvent.WaitOne(1000);

            // check if the event has been rised or not.
            Assert.True(liveUpdate == configChangedEvent);
        }
        public void TestFixtureSetUp()
        {
            Directory.CreateDirectory(HogHelper.ConfigDir);

            _configManager = new RuntimeConfigManager
            {
                ConfigDirectory = HogHelper.ConfigDir
            };

            _hogController = new HeartOfGoldController
            {
                RuntimeDir       = HogHelper.RuntimeDir,
                ConfigDir        = HogHelper.ConfigDirParam,
                ExecutionTimeout = 1000,
                TimerInterval    = 100
            };

            _hogController.LogMessagesReceived += HandleLogMessages;

            ModuleConfig config = new ModuleConfig
            {
                Config = new PortConfig(),

                SleepTime = ServerSleepTime,
                LogLevel  = LogLevel.Info
            };

            _configManager.SaveConfiguration(config);

            Console.WriteLine("Starting HeartOfGold");

            bool started = _hogController.StartApplication();

            _hogController.CreateClients();

            Assert.IsTrue(started, "Can't start HeartOfGold.");
            Assert.IsFalse(_hogController.Process.HasExited, "HeartOfGold has exited unexpectedly.");

            bool result = _hogController.WaitForService("TestModule", ServerModuleState.Running, 10);

            Assert.IsTrue(result, "Service 'TestModule' did not reach state 'Running'");

            _loggers = _hogController.GetAllLoggers();

            _testModuleLogger = _loggers.FirstOrDefault(l => l.Name == "TestModule");
            Assert.NotNull(_testModuleLogger, "Can't get logger configuration for TestModule");
        }