当前位置: 首页>>代码示例>>C#>>正文


C# Settings.SetValues方法代码示例

本文整理汇总了C#中Settings.SetValues方法的典型用法代码示例。如果您正苦于以下问题:C# Settings.SetValues方法的具体用法?C# Settings.SetValues怎么用?C# Settings.SetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Settings的用法示例。


在下文中一共展示了Settings.SetValues方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CallingSetValuesWithEmptyKeyThrowsException

        public void CallingSetValuesWithEmptyKeyThrowsException()
        {
            // Arrange 
            var mockFileSystem = new MockFileSystem();
            var values = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("", "value") };
            var settings = new Settings(mockFileSystem);

            // Act & Assert
            ExceptionAssert.Throws<ArgumentException>(() => settings.SetValues("Section", values));
        }
开发者ID:Redth,项目名称:nuget,代码行数:10,代码来源:SettingsTests.cs

示例2: CallingSetValuesWilladdValuesInOrder

        public void CallingSetValuesWilladdValuesInOrder()
        {
            // Arrange
            var mockFileSystem = new MockFileSystem();
            var nugetConfigPath = "NuGet.Config";
            
            string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""Value"" />
  </SectionName>
</configuration>";
            mockFileSystem.AddFile(nugetConfigPath, config);
            var values = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("key1", "Value1"), 
                                                                    new KeyValuePair<string, string>("key2", "Value2") };
            Settings settings = new Settings(mockFileSystem);

            // Act
            settings.SetValues("SectionName", values);

            // Assert
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""Value"" />
    <add key=""key1"" value=""Value1"" />
    <add key=""key2"" value=""Value2"" />
  </SectionName>
</configuration>", mockFileSystem.ReadAllText(nugetConfigPath));
        }
开发者ID:Redth,项目名称:nuget,代码行数:30,代码来源:SettingsTests.cs

示例3: CallingSetValuesWithNullValuesThrowsException

        public void CallingSetValuesWithNullValuesThrowsException()
        {
            // Arrange 
            var mockFileSystem = new MockFileSystem();
            var settings = new Settings(mockFileSystem);

            // Act & Assert
            ExceptionAssert.Throws<ArgumentNullException>(() => settings.SetValues("Section", null));
        }
开发者ID:Redth,项目名称:nuget,代码行数:9,代码来源:SettingsTests.cs

示例4: CallingSetValuseWillAddSectionIfItDoesNotExist

        public void CallingSetValuseWillAddSectionIfItDoesNotExist()
        {
            // Arrange
            var mockFileSystem = new MockFileSystem();
            var nugetConfigPath = "NuGet.Config";
            string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""value"" />
  </SectionName>
</configuration>";
            mockFileSystem.AddFile(nugetConfigPath, config);
            var values = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("key", "value") };
            Settings settings = new Settings(mockFileSystem);

            // Act
            settings.SetValues("NewSectionName", values);

            // Assert
            XmlAssert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""value"" />
  </SectionName>
  <NewSectionName>
    <add key=""key"" value=""value"" />
  </NewSectionName>
</configuration>", mockFileSystem.ReadAllText(nugetConfigPath));
        }
开发者ID:atheken,项目名称:nuget,代码行数:29,代码来源:SettingsTests.cs

示例5: CallingSetValuesWilladdValuesInOrder

        public void CallingSetValuesWilladdValuesInOrder()
        {
            // Arrange
            var nugetConfigPath = "NuGet.Config";

            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""Value"" />
  </SectionName>
</configuration>";
            var values = new[]
                {
                    new SettingValue("key1", "Value1", isMachineWide: false),
                    new SettingValue("key2", "Value2", isMachineWide: false)
                };
            var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
            TestFilesystemUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
            Settings settings = new Settings(mockBaseDirectory);

            // Act
            settings.SetValues("SectionName", values);

            // Assert
            var result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""Value"" />
    <add key=""key1"" value=""Value1"" />
    <add key=""key2"" value=""Value2"" />
  </SectionName>
</configuration>";
            Assert.Equal(TestFilesystemUtility.RemovedLineEndings(result), TestFilesystemUtility.ReadConfigurationFile(Path.Combine(mockBaseDirectory, nugetConfigPath)));
        }
开发者ID:eerhardt,项目名称:NuGet3,代码行数:34,代码来源:SettingsTests.cs

示例6: CallingSetValuesWithEmptyKeyThrowsException

        public void CallingSetValuesWithEmptyKeyThrowsException()
        {
            // Arrange
            const string configFile = "NuGet.Config";
            var values = new[] { new SettingValue("", "value", isMachineWide: false) };
            var mockBaseDirectory = TestFilesystemUtility.CreateRandomTestFolder();
            TestFilesystemUtility.CreateConfigurationFile(configFile, mockBaseDirectory, @"<configuration></configuration>");
            Settings settings = new Settings(mockBaseDirectory);

            // Act & Assert
            Exception ex = Record.Exception(() => settings.SetValues("Section", values));
            Assert.NotNull(ex);
            var tex = Assert.IsAssignableFrom<ArgumentException>(ex);
        }
开发者ID:eerhardt,项目名称:NuGet3,代码行数:14,代码来源:SettingsTests.cs

示例7: UserSettings_CallingSetValuesWilladdValuesInOrder

        public void UserSettings_CallingSetValuesWilladdValuesInOrder()
        {
            // 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=""key"" value=""Value"" />
  </SectionName>
</configuration>";
            mockFileSystem.Setup(m => m.OpenFile(nugetConfigPath)).Returns(config.AsStream());
            var values = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("key1", "Value1"), 
                                                                    new KeyValuePair<string, string>("key2", "Value2") };
            Settings settings = new Settings(mockFileSystem.Object);

            // Act
            settings.SetValues("SectionName", values);

            // Assert
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <SectionName>
    <add key=""key"" value=""Value"" />
    <add key=""key1"" value=""Value1"" />
    <add key=""key2"" value=""Value2"" />
  </SectionName>
</configuration>", ms.ReadToEnd());
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:36,代码来源:UserSettingsTests.cs


注:本文中的Settings.SetValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。