예제 #1
0
        public void MalformedJSONTest()
        {
            // Initialize the failure test
            ConfigFailed = false;
            var config = new LoggingConfig()
            {
                ExceptionHandler = HandleException
            };
            ICollection<string> sourceLines;

            using (var copy = new ConfigFileCopy(DefaultConfigFile))
            {
                // Load the file
                config.LoadConfig(copy.FileName);

                // Break the file
                sourceLines = MalformnJSON(copy.FileName);

                // Check to see if the failure was detected
                int checkCount = 0;
                while (!ConfigFailed)
                {
                    Thread.Sleep(200);
                    if (checkCount++ > 5)
                        break;
                }
                Assert.IsTrue(ConfigFailed);

                // Next we need to see if we can recover from the error

                // Restore the file
                WriteFile(copy.FileName, sourceLines);

                // Make sure that watch is on
                Assert.IsTrue(config.Watch);

                // Turn off watch
                SetWatch(copy.FileName, false);
                for (int lp = 0; lp < 10; lp++)
                {
                    if (!config.Watch)
                        break;
                    Thread.Sleep(100);
                }

                // Make sure watch is off
                Assert.IsFalse(config.Watch);
            }
        }
예제 #2
0
        public void WatchTest()
        {
            using (var copy = new ConfigFileCopy(DefaultConfigFile))
            {
                var config = new LoggingConfig();
                config.LoadConfig(copy.FileName);

                Assert.IsTrue(config.Watch);

                SetWatch(copy.FileName, false);
                for (int lp = 0; lp < 50; lp++)
                {
                    if (!config.Watch)
                        break;
                    Thread.Sleep(100);
                }

                Assert.IsFalse(config.Watch);
            }
        }