本文整理汇总了C#中Settings.DeleteValue方法的典型用法代码示例。如果您正苦于以下问题:C# Settings.DeleteValue方法的具体用法?C# Settings.DeleteValue怎么用?C# Settings.DeleteValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Settings
的用法示例。
在下文中一共展示了Settings.DeleteValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallingDeleteValueWhenKeyDoesntExistThrowsException
public void CallingDeleteValueWhenKeyDoesntExistThrowsException()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var nugetConfigPath = "NuGet.Config";
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key"" value="""" />
</SectionName>
</configuration>";
mockFileSystem.AddFile(nugetConfigPath, config);
Settings settings = new Settings(mockFileSystem);
// Act & Assert
Assert.False(settings.DeleteValue("SectionName", "KeyDoesNotExist"));
}
示例2: CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue
public void CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var nugetConfigPath = "NuGet.Config";
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""DeleteMe"" value=""value"" />
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>";
mockFileSystem.AddFile(nugetConfigPath, config);
Settings settings = new Settings(mockFileSystem);
// Act & Assert
Assert.True(settings.DeleteValue("SectionName", "DeleteMe"));
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>", mockFileSystem.ReadAllText(nugetConfigPath));
}
示例3: CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue
public void CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue()
{
// Arrange
var nugetConfigPath = "NuGet.Config";
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""DeleteMe"" value=""value"" />
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act & Assert
Assert.True(settings.DeleteValue("SectionName", "DeleteMe"));
var result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>";
Assert.Equal(TestFilesystemUtility.RemovedLineEndings(result), TestFilesystemUtility.ReadConfigurationFile(Path.Combine(mockBaseDirectory, nugetConfigPath)));
}
示例4: CallingDeleteValueWithEmptySectionThrowsException
public void CallingDeleteValueWithEmptySectionThrowsException()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var settings = new Settings(mockFileSystem);
// Act & Assert
ExceptionAssert.Throws<ArgumentException>(() => settings.DeleteValue("", "SomeKey"));
}
示例5: CallingDeleteValueWhenKeyDoesntExistThrowsException
public void CallingDeleteValueWhenKeyDoesntExistThrowsException()
{
// Arrange
var nugetConfigPath = "NuGet.Config";
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key"" value="""" />
</SectionName>
</configuration>";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
Settings settings = new Settings(mockBaseDirectory);
// Act & Assert
Assert.False(settings.DeleteValue("SectionName", "KeyDoesNotExist"));
}
示例6: CallingDeleteValueWithEmptySectionThrowsException
public void CallingDeleteValueWithEmptySectionThrowsException()
{
// Arrange
const string configFile = "NuGet.Config";
var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
TestFilesystemUtility.CreateConfigurationFile(configFile, mockBaseDirectory, @"<configuration></configuration>");
Settings settings = new Settings(mockBaseDirectory);
// Act & Assert
Exception ex = Record.Exception(() => settings.DeleteValue("", "SomeKey"));
Assert.NotNull(ex);
var tex = Assert.IsAssignableFrom<ArgumentException>(ex);
}
示例7: UserSettings_CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue
public void UserSettings_CallingDeleteValueWithValidSectionAndKeyDeletesTheEntryAndReturnsTrue()
{
// Arrange
var mockFileSystem = new Mock<IFileSystem>();
var nugetConfigPath = "NuGet.Config";
mockFileSystem.Setup(m => m.FileExists(nugetConfigPath)).Returns(true);
var ms = new MemoryStream();
mockFileSystem.Setup(m => m.AddFile(nugetConfigPath, It.IsAny<Stream>())).Callback<string, Stream>((path, stream) =>
{
stream.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
});
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""DeleteMe"" value=""value"" />
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>";
mockFileSystem.Setup(m => m.OpenFile(nugetConfigPath)).Returns(config.AsStream());
Settings settings = new Settings(mockFileSystem.Object);
// Act & Assert
Assert.True(settings.DeleteValue("SectionName", "DeleteMe"));
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""keyNotToDelete"" value=""value"" />
</SectionName>
<SectionName2>
<add key=""key"" value=""value"" />
</SectionName2>
</configuration>", ms.ReadToEnd());
}
示例8: UserSettings_CallingDeleteValueWhenKeyDoesntExistThrowsException
public void UserSettings_CallingDeleteValueWhenKeyDoesntExistThrowsException()
{
// Arrange
var mockFileSystem = new Mock<IFileSystem>();
var nugetConfigPath = "NuGet.Config";
mockFileSystem.Setup(m => m.FileExists(nugetConfigPath)).Returns(true);
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key"" value="""" />
</SectionName>
</configuration>";
mockFileSystem.Setup(m => m.OpenFile(nugetConfigPath)).Returns(config.AsStream());
Settings settings = new Settings(mockFileSystem.Object);
// Act & Assert
Assert.False(settings.DeleteValue("SectionName", "KeyDoesNotExist"));
}
示例9: UserSettings_CallingDeleteValueWithEmptyKeyThrowsException
public void UserSettings_CallingDeleteValueWithEmptyKeyThrowsException()
{
// Arrange
var mockFileSystem = new Mock<IFileSystem>();
var settings = new Settings(mockFileSystem.Object);
// Act & Assert
ExceptionAssert.Throws<ArgumentException>(() => settings.DeleteValue("SomeSection", ""));
}