public void BaseErrors_ProcessConfigurationSection() { var builder = new FakeConfigBuilder() { FailGetValues = true }; try { builder.Initialize("Stefano", new NameValueCollection() { { "mode", "Strict" } }); builder.ProcessConfigurationSection(GetAppSettings()); // If we don't get an exception, that's bad Assert.Fail(); } catch (Exception e) { // ProcessConfigurationSection exception in Strict mode contains builder name Assert.IsTrue(e.Message.Contains("Stefano")); Assert.IsTrue(e.ToString().Contains("Unique Exception Message in GetValue")); } builder = new FakeConfigBuilder() { FailGetValues = true }; try { builder.Initialize("Stepanya", new NameValueCollection() { { "mode", "Greedy" } }); builder.ProcessConfigurationSection(GetAppSettings()); // If we don't get an exception, that's bad Assert.Fail(); } catch (Exception e) { // ProcessConfigurationSection exception in Greedy mode contains builder name Assert.IsTrue(e.Message.Contains("Stepanya")); Assert.IsTrue(e.ToString().Contains("Unique Exception Message in GetAllValues")); } // In Expand mode, ProcessConfigurationSection is a noop builder = new FakeConfigBuilder() { FailGetValues = true }; builder.Initialize("Josef", new NameValueCollection() { { "mode", "Expand" } }); builder.ProcessConfigurationSection(GetAppSettings()); Assert.IsTrue(true); // I hate implicit success. ;) }
public void BaseBehavior_Expand() { // Expand - ProcessConfigurationSection is a noop var builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } }); AppSettingsSection origSettings = GetAppSettings(); AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count); foreach (string key in origSettings.Settings.AllKeys) { Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value); } // Expand - ProcessConfigurationSection is a noop, even with prefix stuff builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" }, { "stripPrefix", "true" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count); foreach (string key in origSettings.Settings.AllKeys) { Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value); } // Expand - ProcessRawXml builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } }); XmlNode xmlInput = GetNode(rawXmlInput); XmlNode xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); // Expand - ProcessRawXml with prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with prefix - NOT Case-Sensitive builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with prefix and strip builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "Prefix_TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with strip with no prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); // Expand - ProcessRawXml with alternate tokenPattern builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.AreEqual("ThisWasAnAlternateTokenPattern", GetValueFromXml(xmlOutput, "AltTokenTest")); Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml does not work with alternate tokenPattern with no capture group builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%[\w:]+%%" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest")); Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml does not blow up with alternate tokenPattern with empty capture group builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%(.?)%" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest")); Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with alternate tokenPattern and prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" }, { "prefix", "Prefix_" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest")); Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with alternate tokenPattern and strip prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" }, { "prefix", "Prefix_" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest")); Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); }
public void BaseBehavior_Greedy() { // Greedy - ProcessRawXml is a noop var builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" } }); XmlNode xmlInput = GetNode(rawXmlInput); Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput)); // Greedy - ProcessRawXml is a noop, even with prefix stuff builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "PreFIX_" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput)); // Greedy - ProcessConfigurationSection builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" } }); AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value); Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value); Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value); Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value); Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value); Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value); Assert.AreEqual("TestKey2Value", newSettings.Settings["TestKey2"]?.Value); Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value); // Greedy - ProcessConfigurationSection with prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "Prefix_" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value); Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value); Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value); Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value); Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value); Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value); Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value); Assert.IsNull(newSettings.Settings["TestKey2"]?.Value); // Greedy - ProcessConfigurationSection with prefix - NOT Case-Sensitive builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "preFIX_" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value); Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value); Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value); Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value); Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value); Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value); Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value); Assert.IsNull(newSettings.Settings["TestKey2"]?.Value); // Greedy - ProcessConfigurationSection with prefix and strip builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "preFIX_" }, { "stripPrefix", "true" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["TestKey1"]?.Value); Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value); Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value); Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["TestKey"]?.Value); Assert.AreEqual("PrefixTest2", newSettings.Settings["Prefix_TestKey"]?.Value); Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value); Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value); Assert.IsNull(newSettings.Settings["TestKey2"]?.Value); // Greedy - ProcessConfigurationSection with strip with no prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "stripPrefix", "true" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value); Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value); Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value); Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value); Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value); Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value); Assert.AreEqual("TestKey2Value", newSettings.Settings["TestKey2"]?.Value); Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value); }
public void BaseBehavior_Expand() { // Expand - ProcessConfigurationSection is a noop var builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } }); AppSettingsSection origSettings = GetAppSettings(); AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count); foreach (string key in origSettings.Settings.AllKeys) { Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value); } // Expand - ProcessConfigurationSection is a noop, even with prefix stuff builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" }, { "stripPrefix", "true" } }); newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings()); Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count); foreach (string key in origSettings.Settings.AllKeys) { Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value); } // Expand - ProcessRawXml builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } }); XmlNode xmlInput = GetNode(rawXmlInput); XmlNode xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); // Expand - ProcessRawXml with prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with prefix - NOT Case-Sensitive builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with prefix and strip builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "Prefix_TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value")); // Expand - ProcessRawXml with strip with no prefix builder = new FakeConfigBuilder(); builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "stripPrefix", "true" } }); xmlInput = GetNode(rawXmlInput); xmlOutput = builder.ProcessRawXml(xmlInput); Assert.AreEqual("appSettings", xmlOutput.Name); Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1")); Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1")); Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value")); Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey")); Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey")); Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2")); Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1")); Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2")); Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}")); }