private void LoadFileB_Click(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog() { DefaultExt = ".config" }; if (openFileDialog.ShowDialog() != true) { return; } try { _filePath = openFileDialog.FileName; FileName.Content += openFileDialog.SafeFileName; _xml = AppConfig.LoadXml(_filePath); _configurationPoker = new ConfigurationPoker(_xml); var connectionStringNames = _configurationPoker.GetConnectionStringNames(); ConnectionList.ItemsSource = connectionStringNames; ConnectionList.Text = connectionStringNames.FirstOrDefault() ?? ""; } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public void GetsNullOnMiss() { var poker = new ConfigurationPoker(XmlShizzle); Assert.That(poker.GetAppSetting("appSetting2"), Is.Null); Assert.That(poker.GetAppSetting("appSetting_does_not_exist"), Is.Null); Assert.That(poker.GetConnectionString("connectionString2"), Is.Null); Assert.That(poker.GetConnectionString("connectionString_does_not_exist"), Is.Null); }
public void CanReadAppSettings() { //var path = Path.Combine(@"C:\apps\fm\cli", "fm.exe.config"); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Fake", "FakeApp02.config"); var poker = ConfigurationPoker.ReadFile(path); Assert.That(poker.GetAppSettingKeys().Count, Is.EqualTo(0)); }
public void CanGetAppSettingsAndConnectionStringsToo() { var poker = new ConfigurationPoker(XmlShizzle); var appSettingValue = poker.GetAppSetting("appSetting1"); var connectionStringValue = poker.GetConnectionString("connectionString1"); Assert.That(appSettingValue, Is.EqualTo("local")); Assert.That(connectionStringValue, Is.EqualTo(@"host=localhost; db=fleetmanager; user id=postgres; password=postgres")); }
public void CanGetKeysAndNames() { var poker = new ConfigurationPoker(XmlShizzle); var appSettingKeys = poker.GetAppSettingKeys(); var connectionStringNames = poker.GetConnectionStringNames(); Assert.That(appSettingKeys, Is.EqualTo(new[] { "appSetting1", "appSetting2" })); Assert.That(connectionStringNames, Is.EqualTo(new[] { "connectionString1", "connectionString2" })); }
public void ItWorksAsItShould() { var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bugs", "test01.xml"); var xml = File.ReadAllText(filePath, Encoding.UTF8); Console.WriteLine(xml); var poker = new ConfigurationPoker(xml); Assert.That(poker.GetAppSetting("masterkey"), Is.EqualTo("bimmelimmelim")); Assert.That(poker.GetAppSetting("logpath"), Is.EqualTo(@"c:\data\fm5")); }
public void CanPokeXmlValuesIn_NonExistentConnectionString() { var applicator = new ConfigurationPoker(XmlShizzle); applicator.SetConnectionString("connectionString3", "a_connection"); var xml = applicator.RenderXml(); const string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""appSetting1"" value=""local"" /> <add key=""appSetting2"" /> </appSettings> <connectionStrings> <add name=""connectionString1"" connectionString=""host=localhost; db=fleetmanager; user id=postgres; password=postgres"" /> <add name=""connectionString2"" /> <add name=""connectionString3"" connectionString=""a_connection"" /> </connectionStrings> <startup> <supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v4.6.1"" /> </startup> <runtime> <assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1""> <dependentAssembly> <assemblyIdentity name=""Newtonsoft.Json"" publicKeyToken=""30ad4fe6b2a6aeed"" culture=""neutral"" /> <bindingRedirect oldVersion=""0.0.0.0-9.0.0.0"" newVersion=""9.0.0.0"" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name=""Microsoft.Owin"" publicKeyToken=""31bf3856ad364e35"" culture=""neutral"" /> <bindingRedirect oldVersion=""0.0.0.0-3.0.1.0"" newVersion=""3.0.1.0"" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name=""Npgsql"" publicKeyToken=""5d8b90d52f46fda7"" culture=""neutral"" /> <bindingRedirect oldVersion=""0.0.0.0-3.1.0.0"" newVersion=""3.1.0.0"" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name=""Serilog"" publicKeyToken=""24c2f752a8e58a10"" culture=""neutral"" /> <bindingRedirect oldVersion=""0.0.0.0-2.0.0.0"" newVersion=""2.0.0.0"" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>"; AssertXmlsAreEqual(xml, expectedXml); }