public void Test_GetValue_Int()
        {
            var configuration = new ConfigurationMockHelper().AddValue("SomeKey", "1234").Object;
            var node = new HierarchicalConfigurationNode(null, configuration);

            Assert.Equal(1234, node.GetValue<int>("SomeKey"));
        }
Пример #2
0
        public void Test_GetValue_Int_Invalid()
        {
            var configuration = new ConfigurationMockHelper().AddValue("SomeKey", "sdafdv").Object;
            var node          = new HierarchicalConfigurationNode(null, configuration);

            Assert.Throws <ArgumentException>(() => node.GetValue <int>("SomeKey"));
        }
        public void Test_GetValue_Int_Invalid()
        {
            var configuration = new ConfigurationMockHelper().AddValue("SomeKey", "sdafdv").Object;
            var node = new HierarchicalConfigurationNode(null, configuration);

            Assert.Throws<ArgumentException>(() => node.GetValue<int>("SomeKey"));
        }
Пример #4
0
        /// <summary>
        /// Loads configuration for the specified directory and its subdirectories and file using the specified configuration node as parent node
        /// </summary>
        internal void LoadConfiguration(IConfigurationNode parentNode, IDirectory directory)
        {
            m_Logger.Info($"Loading configuration for directory '{directory.FullPath}'");

            // determine configuration node for directory
            IConfigurationNode configNode;

            // config file present in directory => create new node
            if (directory.FileExists(s_DirectoryConfigName))
            {
                configNode = new HierarchicalConfigurationNode(parentNode, LoadConfigurationFile(directory.GetFile(s_DirectoryConfigName)));
            }
            // no config file found => use parent node
            else
            {
                configNode = parentNode;
            }

            m_Mapper.AddMapping(configNode, directory);

            // load configuration for files in the directory
            foreach (var file in directory.Files)
            {
                LoadConfiguration(configNode, file);
            }

            // load configuration for subdirectories
            foreach (var dir in directory.Directories)
            {
                LoadConfiguration(configNode, dir);
            }
        }
Пример #5
0
        public void Test_GetValue_Int()
        {
            var configuration = new ConfigurationMockHelper().AddValue("SomeKey", "1234").Object;
            var node          = new HierarchicalConfigurationNode(null, configuration);

            Assert.Equal(1234, node.GetValue <int>("SomeKey"));
        }
        public void Test_GetValue_String()
        {
            var configurationMock = new ConfigurationMockHelper()
                .AddValue("SomeKey", "SomeValue")
                .Mock;

            var node = new HierarchicalConfigurationNode(null, configurationMock.Object);

            Assert.Equal("SomeValue", node.GetValue<string>("SomeKey"));
        }
Пример #7
0
        public void Test_GetValue_String()
        {
            var configurationMock = new ConfigurationMockHelper()
                                    .AddValue("SomeKey", "SomeValue")
                                    .Mock;

            var node = new HierarchicalConfigurationNode(null, configurationMock.Object);

            Assert.Equal("SomeValue", node.GetValue <string>("SomeKey"));
        }
Пример #8
0
        public void Test_GetValue_FromParentNode()
        {
            var expectedValue = Guid.NewGuid().ToString();

            var parentNodeMock = new Mock <IConfigurationNode>(MockBehavior.Strict);

            parentNodeMock.Setup(x => x.GetValue <string>("SomeKey")).Returns(expectedValue);

            var node = new HierarchicalConfigurationNode(parentNodeMock.Object, new ConfigurationMockHelper().Object);

            Assert.Equal(expectedValue, node.GetValue <string>("SomeKey"));
            parentNodeMock.Verify(x => x.GetValue <string>("SomeKey"), Times.Once);
        }
Пример #9
0
        public void Test_GetValue_Bool()
        {
            var node = new HierarchicalConfigurationNode(null,
                                                         new ConfigurationMockHelper()
                                                         .AddValue("SomeKey", "true")
                                                         .AddValue("SomeKey2", "trUE")
                                                         .AddValue("SomeKey3", "FALse")
                                                         .Object);

            Assert.Equal(true, node.GetValue <bool>("SomeKey"));
            Assert.Equal(true, node.GetValue <bool>("SomeKey2"));
            Assert.Equal(false, node.GetValue <bool>("SomeKey3"));
        }
        public void Test_GetValue_Bool()
        {
            var node = new HierarchicalConfigurationNode(null,
                new ConfigurationMockHelper()
                .AddValue("SomeKey", "true")
                .AddValue("SomeKey2", "trUE")
                .AddValue("SomeKey3", "FALse")
                .Object);

            Assert.Equal(true, node.GetValue<bool>("SomeKey"));
            Assert.Equal(true, node.GetValue<bool>("SomeKey2"));
            Assert.Equal(false, node.GetValue<bool>("SomeKey3"));
        }
Пример #11
0
        public void Test_GetValue_NodeValueOverridesParentNodeValue()
        {
            var expectedValue = Guid.NewGuid().ToString();

            var parentNodeMock = new Mock <IConfigurationNode>(MockBehavior.Strict);

            parentNodeMock.Setup(x => x.GetValue <string>("SomeKey")).Returns("");

            var configuraiton = new ConfigurationMockHelper().AddValue("SomeKey", expectedValue).Object;
            var node          = new HierarchicalConfigurationNode(parentNodeMock.Object, configuraiton);

            Assert.Equal(expectedValue, node.GetValue <string>("SomeKey"));
            parentNodeMock.Verify(x => x.GetValue <string>("SomeKey"), Times.Never);
        }
Пример #12
0
        /// <summary>
        /// Loads configuration for the specified file using the specified configuration node as parent node
        /// </summary>
        internal void LoadConfiguration(IConfigurationNode parentNode, IFile file)
        {
            m_Logger.Info($"Loading configuration for file '{file.FullPath}'");

            // determine the configuration node to associate with the file
            IConfigurationNode configNode;
            var configFileName = String.Format(s_FileConfigName, file.NameWithExtension);

            // there is a file-specific configuration file => create new config node
            if (file.Directory.FileExists(configFileName))
            {
                configNode = new HierarchicalConfigurationNode(parentNode, LoadConfigurationFile(file.Directory.GetFile(configFileName)));
            }
            // no config file found => use parent node
            else
            {
                configNode = parentNode;
            }

            // associate configuration node with file
            m_Mapper.AddMapping(configNode, file);
        }
 public void Test_Constructor_ParentNodeIsNull()
 {
     var node = new HierarchicalConfigurationNode(null, new ConfigurationMockHelper().Mock.Object);
 }
Пример #14
0
        public void Test_GetValue_NotFound()
        {
            var node = new HierarchicalConfigurationNode(null, new ConfigurationMockHelper().Object);

            Assert.Throws <KeyNotFoundException>(() => node.GetValue <string>("SomeKey"));
        }
        public void Test_GetValue_FromParentNode()
        {
            var expectedValue = Guid.NewGuid().ToString();

            var parentNodeMock = new Mock<IConfigurationNode>(MockBehavior.Strict);
            parentNodeMock.Setup(x => x.GetValue<string>("SomeKey")).Returns(expectedValue);

            var node = new HierarchicalConfigurationNode(parentNodeMock.Object, new ConfigurationMockHelper().Object);

            Assert.Equal(expectedValue, node.GetValue<string>("SomeKey"));
            parentNodeMock.Verify(x => x.GetValue<string>("SomeKey"), Times.Once);
        }
        public void Test_GetValue_NotFound()
        {
            var node = new HierarchicalConfigurationNode(null, new ConfigurationMockHelper().Object);

            Assert.Throws<KeyNotFoundException>(() => node.GetValue<string>("SomeKey"));
        }
        public void Test_GetValue_NodeValueOverridesParentNodeValue()
        {
            var expectedValue = Guid.NewGuid().ToString();

            var parentNodeMock = new Mock<IConfigurationNode>(MockBehavior.Strict);
            parentNodeMock.Setup(x => x.GetValue<string>("SomeKey")).Returns("");

            var configuraiton = new ConfigurationMockHelper().AddValue("SomeKey", expectedValue).Object;
            var node = new HierarchicalConfigurationNode(parentNodeMock.Object, configuraiton);
            
            Assert.Equal(expectedValue, node.GetValue<string>("SomeKey"));
            parentNodeMock.Verify(x => x.GetValue<string>("SomeKey"), Times.Never);
        }
Пример #18
0
 public void Test_Constructor_ParentNodeIsNull()
 {
     var node = new HierarchicalConfigurationNode(null, new ConfigurationMockHelper().Mock.Object);
 }