Beispiel #1
0
        public void SetupBuilderLoadConfigurationFromFileOptionalFalseTest()
        {
            // Arrange
            var xmlFile      = new System.IO.StringReader("<nlog autoshutdown='false'></nlog>");
            var appEnv       = new Mocks.AppEnvironmentMock(f => false, f => System.Xml.XmlReader.Create(xmlFile));
            var configLoader = new LoggingConfigurationFileLoader(appEnv);
            var logFactory   = new LogFactory(configLoader);

            // Act / Assert
            Assert.Throws <System.IO.FileNotFoundException>(() => logFactory.Setup().LoadConfigurationFromFile("NLog.config", optional: false));
        }
Beispiel #2
0
        public void SetupBuilderLoadConfigurationFromFileMissingTest()
        {
            // Arrange
            var appEnv       = new Mocks.AppEnvironmentMock(f => false, f => null);
            var configLoader = new LoggingConfigurationFileLoader(appEnv);
            var logFactory   = new LogFactory(configLoader);

            // Act
            logFactory.Setup().LoadConfigurationFromFile(optional: true);

            // Assert
            // no Exception
        }
Beispiel #3
0
        public void SetupBuilderLoadNLogConfigFromFileNotExistsTest()
        {
            // Arrange
            var xmlFile      = new System.IO.StringReader("<nlog autoshutdown='false'></nlog>");
            var appEnv       = new Mocks.AppEnvironmentMock(f => false, f => System.Xml.XmlReader.Create(xmlFile));
            var configLoader = new LoggingConfigurationFileLoader(appEnv);
            var logFactory   = new LogFactory(configLoader);

            // Act
            logFactory.Setup().LoadConfigurationFromFile("NLog.config", optional: true);

            // Assert
            Assert.Null(logFactory.Configuration);
        }
Beispiel #4
0
        public void SetupBuilderLoadConfigurationFromFileTest()
        {
            // Arrange
            var xmlFile      = new System.IO.StringReader("<nlog autoshutdown='false'></nlog>");
            var appEnv       = new Mocks.AppEnvironmentMock(f => true, f => System.Xml.XmlReader.Create(xmlFile));
            var configLoader = new LoggingConfigurationFileLoader(appEnv);
            var logFactory   = new LogFactory(configLoader);

            // Act
            logFactory.Setup().LoadConfigurationFromFile();

            // Assert
            Assert.False(logFactory.AutoShutdown);
        }
Beispiel #5
0
        public void SetupBuilderLoadConfigurationFromXmlPatchTest()
        {
            // Arrange
            var xmlFile      = new System.IO.StringReader("<nlog autoshutdown='true'></nlog>");
            var appEnv       = new Mocks.AppEnvironmentMock(f => true, f => System.Xml.XmlReader.Create(xmlFile));
            var configLoader = new LoggingConfigurationFileLoader(appEnv);
            var logFactory   = new LogFactory(configLoader);

            // Act
            logFactory.Setup().
            LoadConfigurationFromXml("<nlog autoshutdown='false'></nlog>").
            LoadConfigurationFromFile().      // No effect, since config already loaded
            LoadConfiguration(b => { b.Configuration.Variables["Hello"] = "World"; });

            // Assert
            Assert.False(logFactory.AutoShutdown);
            Assert.Single(logFactory.Configuration.Variables);
        }