public void IniConfiguration_Does_Not_Throw_On_Optional_Configuration() { var configSource = new IniConfigurationSource("NotExistingConfig.ini", optional: true); configSource.Load(); Assert.Throws <InvalidOperationException>(() => configSource.Get("key")); }
public void LoadMethodCanHandleEmptyValue() { var ini = @"DefaultKey="; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal(string.Empty, iniConfigSrc.Get("DefaultKey")); }
public void ThrowExceptionWhenFoundInvalidLine() { var ini = @" ConnectionString "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); var expectedMsg = Resources.FormatError_UnrecognizedLineFormat("ConnectionString"); var exception = Assert.Throws <FormatException>(() => iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini))); Assert.Equal(expectedMsg, exception.Message); }
public void DoubleQuoteIsPartOfValueIfAppearInTheMiddleOfValue() { var ini = "[ConnectionString]\n" + "DefaultConnection=Test\"Connection\"String\n" + "Provider=Sql\"Client"; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("Test\"Connection\"String", iniConfigSrc.Get("ConnectionString:DefaultConnection")); Assert.Equal("Sql\"Client", iniConfigSrc.Get("ConnectionString:Provider")); }
public void DoubleQuoteIsPartOfValueIfNotPaired() { var ini = "[ConnectionString]\n" + "DefaultConnection=\"TestConnectionString\n" + "Provider=SqlClient\""; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("\"TestConnectionString", iniConfigSrc.Get("ConnectionString:DefaultConnection")); Assert.Equal("SqlClient\"", iniConfigSrc.Get("ConnectionString:Provider")); }
public void IniConfiguration_Throws_On_Missing_Configuration_File() { var configSource = new IniConfigurationSource("NotExistingConfig.ini", optional: false); Assert.Throws<FileNotFoundException>(() => { try { configSource.Load(); } catch (FileNotFoundException exception) { Assert.Equal(Resources.FormatError_FileNotFound("NotExistingConfig.ini"), exception.Message); throw; } }); }
public void LoadKeyValuePairsFromValidIniFile() { var ini = @"[DefaultConnection] ConnectionString=TestConnectionString Provider=SqlClient [Data:Inventory] ConnectionString=AnotherTestConnectionString SubHeader:Provider=MySql"; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("TestConnectionString", iniConfigSrc.Get("defaultconnection:ConnectionString")); Assert.Equal("SqlClient", iniConfigSrc.Get("DEFAULTCONNECTION:PROVIDER")); Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:CONNECTIONSTRING")); Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:SubHeader:Provider")); }
public void IniConfiguration_Throws_On_Missing_Configuration_File() { var configSource = new IniConfigurationSource("NotExistingConfig.ini", optional: false); Assert.Throws <FileNotFoundException>(() => { try { configSource.Load(); } catch (FileNotFoundException exception) { Assert.Equal(Resources.FormatError_FileNotFound("NotExistingConfig.ini"), exception.Message); throw; } }); }
public void LoadKeyValuePairsFromValidIniFileWithQuotedValues() { var ini = "[DefaultConnection]\n" + "ConnectionString=\"TestConnectionString\"\n" + "Provider=\"SqlClient\"\n" + "[Data:Inventory]\n" + "ConnectionString=\"AnotherTestConnectionString\"\n" + "Provider=\"MySql\""; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString")); Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider")); Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider")); }
public void ThrowExceptionWhenKeyIsDuplicated() { var ini = @" [Data:DefaultConnection] ConnectionString=TestConnectionString Provider=SqlClient [Data] DefaultConnection:ConnectionString=AnotherTestConnectionString Provider=MySql "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); var expectedMsg = Resources.FormatError_KeyIsDuplicated("Data:DefaultConnection:ConnectionString"); var exception = Assert.Throws <FormatException>(() => iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini))); Assert.Equal(expectedMsg, exception.Message); }
public void LoadKeyValuePairsFromValidIniFileWithoutSectionHeader() { var ini = @" DefaultConnection:ConnectionString=TestConnectionString DefaultConnection:Provider=SqlClient Data:Inventory:ConnectionString=AnotherTestConnectionString Data:Inventory:Provider=MySql "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString")); Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider")); Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider")); }
public void SupportAndIgnoreComments() { var ini = @" ; Comments [DefaultConnection] # Comments ConnectionString=TestConnectionString / Comments Provider=SqlClient [Data:Inventory] ConnectionString=AnotherTestConnectionString Provider=MySql "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini)); Assert.Equal("TestConnectionString", iniConfigSrc.Get("DefaultConnection:ConnectionString")); Assert.Equal("SqlClient", iniConfigSrc.Get("DefaultConnection:Provider")); Assert.Equal("AnotherTestConnectionString", iniConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider")); }
public void ThrowExceptionWhenFoundInvalidLine() { var ini = @" ConnectionString "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); var expectedMsg = Resources.FormatError_UnrecognizedLineFormat("ConnectionString"); var exception = Assert.Throws<FormatException>(() => iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini))); Assert.Equal(expectedMsg, exception.Message); }
public void ThrowExceptionWhenKeyIsDuplicated() { var ini = @" [Data:DefaultConnection] ConnectionString=TestConnectionString Provider=SqlClient [Data] DefaultConnection:ConnectionString=AnotherTestConnectionString Provider=MySql "; var iniConfigSrc = new IniConfigurationSource(TestStreamHelpers.ArbitraryFilePath); var expectedMsg = Resources.FormatError_KeyIsDuplicated("Data:DefaultConnection:ConnectionString"); var exception = Assert.Throws<FormatException>(() => iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini))); Assert.Equal(expectedMsg, exception.Message); }
public void IniConfiguration_Does_Not_Throw_On_Optional_Configuration() { var configSource = new IniConfigurationSource("NotExistingConfig.ini", optional: true); configSource.Load(); Assert.Throws<InvalidOperationException>(() => configSource.Get("key")); }