public void ShouldAddMissingAppSettings() { // Arrange var appSettings = new AppSettingsSection(); var coll = new NameValueCollection() { { IniConfigurationBuilder.locationTag, iniFileLocation }, { IniConfigurationBuilder.modeTag, KeyValueMode.Greedy.ToString() } }; var sut = new IniConfigurationBuilder(); sut.Initialize("test", coll); // Act sut.ProcessConfigurationSection(appSettings); // Assert Assert.AreEqual(3, appSettings.Settings.Count, "Did not add more add nodes to appSettings"); // Check for the other three settings for (int i = 1; i < 4; i++) { Assert.IsNotNull(appSettings.Settings[$"setting{i}"], $"Missing setting{i}"); } }
public void ShouldApplyAppSettingsToAppSettings() { // Arrange var appSettings = new AppSettingsSection(); var sut = new IniConfigurationBuilder(); sut.Initialize("test", Settings); // Act sut.ProcessConfigurationSection(appSettings); // Assert Assert.AreEqual(3, appSettings.Settings.Count, "Did not add more add nodes to appSettings"); }
public void WhenNotSpecifiedShouldSetKeyValueModeToStrict() { // Arrange var sut = new IniConfigurationBuilder(); var coll = new NameValueCollection { { IniConfigurationBuilder.locationTag, fakeFileLocation } }; // Act sut.Initialize("test", coll); // Assert Assert.AreEqual(KeyValueMode.Strict, sut.Mode, "Did not set the default mode of the ConfigurationBuilder"); }
public void WhenSpecifiedShouldSetKeyValueMode() { // Arrange var sut = new IniConfigurationBuilder(); var coll = new NameValueCollection { { IniConfigurationBuilder.locationTag, fakeFileLocation }, { IniConfigurationBuilder.modeTag, KeyValueMode.Greedy.ToString() } }; // Act sut.Initialize("test", coll); // Assert Assert.AreEqual(KeyValueMode.Greedy, sut.Mode, "Did not capture the specified mode of the ConfigurationBuilder"); }
public void CaptureLocationAndNameInformation() { // Arrange var sut = new IniConfigurationBuilder(); var coll = new NameValueCollection { { IniConfigurationBuilder.locationTag, fakeFileLocation } }; // Act sut.Initialize("test", coll); // Assert Assert.AreEqual("test", sut.Name, "Did not capture the name of the ConfigurationBuilder"); Assert.AreEqual(fakeFileLocation, sut.Location, "Did not capture the ini file location"); }
public void ThrowsExceptionWhenMissingLocation() { // Arrange var sut = new IniConfigurationBuilder(); var coll = new NameValueCollection(); // Act try { sut.Initialize("test", coll); } catch (ConfigurationErrorsException) { // do nothing, expected result return; } // Assert Assert.Fail("Did not throw a ConfigurationErrorsException for a missing location"); }
public void DoesNotApplySettingIfNoSettingFound() { // Arrange var appSettings = new AppSettingsSection(); appSettings.Settings.Add("NotFoundSetting", "inlineValue"); var coll = new NameValueCollection() { { IniConfigurationBuilder.locationTag, iniFileLocation } }; var sut = new IniConfigurationBuilder(); sut.Initialize("test", coll); // Act sut.ProcessConfigurationSection(appSettings); // Assert Assert.AreEqual("inlineValue", appSettings.Settings["NotFoundSetting"].Value, "Changed the value when it shouldn't have"); }
public void AppliesSetting() { // Arrange var appSettings = new AppSettingsSection(); appSettings.Settings.Add("setting", "inlineValue"); var coll = new NameValueCollection() { { IniConfigurationBuilder.locationTag, iniFileLocation } }; var sut = new IniConfigurationBuilder(); sut.Initialize("test", coll); // Act sut.ProcessConfigurationSection(appSettings); // Assert Assert.AreEqual("CorrectTestResult", appSettings.Settings["setting"].Value, "Did not set the value properly on the value"); }
public void ShouldApplySectionName() { // Arrange var appSettings = new AppSettingsSection(); appSettings.Settings.Add("appSettings_appsetting1", "inlineValue"); appSettings.Settings.Add("appSettings_appsetting2", "inlineValue"); var coll = new NameValueCollection() { { IniConfigurationBuilder.locationTag, iniFileLocation } }; var sut = new IniConfigurationBuilder(); sut.Initialize("test", coll); // Act sut.ProcessConfigurationSection(appSettings); // Assert Assert.AreEqual("value1", appSettings.Settings["appSettings_appsetting1"].Value, "Did not set the value properly on the value"); Assert.AreEqual("value2", appSettings.Settings["appSettings_appsetting2"].Value, "Did not set the value properly on the value"); }