本文整理汇总了C#中NuGet.Test.Mocks.MockFileSystem.ReadAllText方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.ReadAllText方法的具体用法?C# MockFileSystem.ReadAllText怎么用?C# MockFileSystem.ReadAllText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.Test.Mocks.MockFileSystem
的用法示例。
在下文中一共展示了MockFileSystem.ReadAllText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallAddPackageWillNotAddEntryToPackageConfigWhenPackageConfigAlreadyExists
public void CallAddPackageWillNotAddEntryToPackageConfigWhenPackageConfigAlreadyExists()
{
// Arrange
var fileSystem = new Mock<MockFileSystem>() { CallBase = true };
fileSystem.Setup(m => m.Root).Returns(@"c:\foo\");
var configFileSystem = new MockFileSystem();
configFileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""2.0"" />
</packages>");
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object, configFileSystem);
// Act
repository.AddPackage(PackageUtility.CreatePackage("B", "1.0"));
// Assert
Assert.True(configFileSystem.FileExists("packages.config"));
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""2.0"" />
</packages>", configFileSystem.ReadAllText("packages.config"));
}
示例2: AddPackageAddsEntryToPackagesConfig
public void AddPackageAddsEntryToPackagesConfig()
{
// Arrange
var sharedRepository = new Mock<ISharedPackageRepository>();
string path = null;
sharedRepository.Setup(m => m.RegisterRepository(It.IsAny<string>()))
.Callback<string>(p => path = p);
var fileSystem = new MockFileSystem();
var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
var package = PackageUtility.CreatePackage("A");
// Act
referenceRepository.AddPackage(package);
// Assert
Assert.Equal(@"C:\MockFileSystem\packages.config", path);
Assert.True(fileSystem.FileExists("packages.config"));
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
</packages>", fileSystem.ReadAllText("packages.config"));
}
示例3: AddPackageDoesNotAddEntryToPackagesConfigIfExists
public void AddPackageDoesNotAddEntryToPackagesConfigIfExists()
{
// Arrange
var sharedRepository = new Mock<ISharedPackageRepository>();
var fileSystem = new MockFileSystem();
fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
</packages>");
var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
var package = PackageUtility.CreatePackage("A");
// Act
referenceRepository.AddPackage(package);
// Assert
Assert.IsTrue(fileSystem.FileExists("packages.config"));
Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
</packages>", fileSystem.ReadAllText("packages.config"));
}
示例4: 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));
}
示例5: CallingSetNestedAppendsValuesToExistingKeys
public void CallingSetNestedAppendsValuesToExistingKeys()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var nugetConfigPath = "NuGet.Config";
string config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<MyKey>
<add key=""key1"" value=""Value1"" />
<add key=""key2"" value=""Value2"" />
</MyKey>
</SectionName>
</configuration>";
mockFileSystem.AddFile(nugetConfigPath, config);
var values = new[] { new KeyValuePair<string, string>("key3", "Value3"),
new KeyValuePair<string, string>("key4", "Value4") };
Settings settings = new Settings(mockFileSystem);
// Act
settings.SetNestedValues("SectionName", "MyKey", values);
// Assert
Assert.Equal(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<MyKey>
<add key=""key1"" value=""Value1"" />
<add key=""key2"" value=""Value2"" />
<add key=""key3"" value=""Value3"" />
<add key=""key4"" value=""Value4"" />
</MyKey>
</SectionName>
</configuration>", mockFileSystem.ReadAllText(nugetConfigPath));
}
示例6: SetValueWithMachineWideSettings
public void SetValueWithMachineWideSettings()
{
// Arrange
var mockFileSystem = new MockFileSystem(@"C:\");
var a1Config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key1"" value=""value1"" />
</SectionName>
</configuration>";
var a2Config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key2"" value=""value2"" />
<add key=""key3"" value=""value3"" />
</SectionName>
</configuration>";
mockFileSystem.AddFile(
@"NuGet\Config\a1.config",
a1Config);
mockFileSystem.AddFile(
@"NuGet\Config\IDE\a2.config",
a2Config);
mockFileSystem.AddFile(
"user.config",
@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key3"" value=""user"" />
</SectionName>
</configuration>");
var m = new Mock<IMachineWideSettings>();
m.SetupGet(obj => obj.Settings).Returns(
Settings.LoadMachineWideSettings(mockFileSystem, "IDE", "Version", "SKU"));
var settings = Settings.LoadDefaultSettings(
mockFileSystem,
"user.config",
m.Object);
// Act
settings.SetValue("SectionName", "key1", "newValue");
// Assert
var text = mockFileSystem.ReadAllText("user.config");
Assert.Equal(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key3"" value=""user"" />
<add key=""key1"" value=""newValue"" />
</SectionName>
</configuration>",
text);
text = mockFileSystem.ReadAllText(@"NuGet\Config\a1.config");
Assert.Equal(a1Config, text);
text = mockFileSystem.ReadAllText(@"NuGet\Config\IDE\a2.config");
Assert.Equal(a2Config, text);
}
示例7: CallingSetValueWillOverrideValueIfKeyExists
public void CallingSetValueWillOverrideValueIfKeyExists()
{
// 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);
Settings settings = new Settings(mockFileSystem);
// Act
settings.SetValue("SectionName", "key", "NewValue");
// Assert
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<SectionName>
<add key=""key"" value=""NewValue"" />
</SectionName>
</configuration>", mockFileSystem.ReadAllText(nugetConfigPath));
}
示例8: AddPackageReferenceEntryAddsReferenceToPackagesConfigFile
public void AddPackageReferenceEntryAddsReferenceToPackagesConfigFile()
{
// Arrange
var fileSystem = new MockFileSystem();
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
var solutionPackage = PackageUtility.CreatePackage("SolutionLevel", tools: new[] { "Install.ps1" });
// Act
repository.AddPackageReferenceEntry(solutionPackage.Id, solutionPackage.Version);
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""SolutionLevel"" version=""1.0"" />
</packages>", configFileSystem.ReadAllText("packages.config"));
}
示例9: RemovePackageRemovesEntryFromPackagesConfig
public void RemovePackageRemovesEntryFromPackagesConfig()
{
// Arrange
var sharedRepository = new Mock<ISharedPackageRepository>();
var fileSystem = new MockFileSystem();
fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
<package id=""B"" version=""1.0"" />
</packages>");
var referenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: sharedRepository.Object);
var package = PackageUtility.CreatePackage("A");
// Act
referenceRepository.RemovePackage(package);
// Assert
Assert.True(fileSystem.FileExists("packages.config"));
AssertConfig(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""B"" version=""1.0"" />
</packages>", fileSystem.ReadAllText("packages.config"));
}
示例10: RemovingAndAddingPackageReferenceWithSameIdPreservesConstraint
public void RemovingAndAddingPackageReferenceWithSameIdPreservesConstraint()
{
// Arrange
var sharedRepository = new Mock<ISharedPackageRepository>();
var fileSystem = new MockFileSystem();
fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" allowedVersions=""[1.0, 5.0)"" />
</packages>");
var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
var A10 = PackageUtility.CreatePackage("A");
var A20 = PackageUtility.CreatePackage("A", "2.0");
// Act
referenceRepository.RemovePackage(A10);
referenceRepository.AddPackage(A20);
// Assert
Assert.True(fileSystem.FileExists("packages.config"));
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""2.0"" allowedVersions=""[1.0, 5.0)"" />
</packages>", fileSystem.ReadAllText("packages.config"));
}
示例11: TheDisabledStateOfWindows8FeedIsPersistedWhenRunningOnWindows8Express
public void TheDisabledStateOfWindows8FeedIsPersistedWhenRunningOnWindows8Express()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var settings = Settings.LoadDefaultSettings(
mockFileSystem,
configFileName: null,
machineWideSettings: null);
var packageSourceProvider = new PackageSourceProvider(settings);
var vsShellInfo = new Mock<IVsShellInfo>();
vsShellInfo.Setup(_ => _.IsVisualStudioExpressForWindows8).Returns(true);
var provider = new VsPackageSourceProvider(settings, packageSourceProvider, vsShellInfo.Object);
var packageSources = provider.LoadPackageSources().ToList();
Assert.Equal(1, packageSources.Count);
Assert.Equal(NuGetConstants.VSExpressForWindows8FeedUrl, packageSources[0].Source);
Assert.True(packageSources[0].IsEnabled);
// Act
packageSources[0].IsEnabled = false;
provider.SavePackageSources(packageSources);
// Assert
// the Win8ExpressFeed is not saved in <disabledPackageSources>.
Assert.Equal(1, mockFileSystem.Paths.Count);
var configFile = mockFileSystem.Paths.First().Key;
var configFileContent = mockFileSystem.ReadAllText(configFile);
Assert.Equal(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<packageSources />
<disabledPackageSources>
<add key=""Windows 8 Packages"" value=""true"" />
</disabledPackageSources>
</configuration>".Replace("\r", ""),
configFileContent.Replace("\r", ""));
}
示例12: RegisterRepositoryDoesNotAddRelativePathToRepositoriesConfigIfExists
public void RegisterRepositoryDoesNotAddRelativePathToRepositoriesConfigIfExists()
{
// Arrange
var fileSystem = new MockFileSystem(@"x:\foo");
fileSystem.AddFile("repositories.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<repositories>
<repository path=""A\packages.config"" />
<repository path=""B\packages.config"" />
</repositories>");
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, new MockFileSystem());
var packageReferenceFile = new PackageReferenceFile(new MockFileSystem(), @"x:\foo\A\packages.config");
// Act
repository.RegisterRepository(packageReferenceFile);
// Assert
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<repositories>
<repository path=""A\packages.config"" />
<repository path=""B\packages.config"" />
</repositories>", fileSystem.ReadAllText("repositories.config"));
}
示例13: GetRepositoryPathsRemovesInvalidOrNonExistantPathsAndReturnsRelativePaths
public void GetRepositoryPathsRemovesInvalidOrNonExistantPathsAndReturnsRelativePaths()
{
// Arrange
var fileSystem = new MockFileSystem(@"x:\foo\bar\baz");
fileSystem.AddFile(@"A\packages.config", "");
fileSystem.AddFile(@"x:\foo\packages.config", "");
fileSystem.AddFile(@"..\..\packages.config", "");
fileSystem.AddFile("repositories.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<repositories>
<repository path=""A\packages.config"" />
<repository path=""B\packages.config"" />
<repository path=""x:\foo\packages.config"" />
<repository path=""..\..\packages.config"" />
<repository path="""" />
<repository />
</repositories>");
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, new MockFileSystem());
// Act
var paths = repository.GetRepositoryPaths().ToList();
// Assert
Assert.Equal(2, paths.Count);
Assert.Equal(@"A\packages.config", paths[0]);
Assert.Equal(@"..\..\packages.config", paths[1]);
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<repositories>
<repository path=""A\packages.config"" />
<repository path=""x:\foo\packages.config"" />
</repositories>", fileSystem.ReadAllText("repositories.config"));
}
示例14: 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));
}
示例15: RemovePackagePreservesProjectConfigFile
public void RemovePackagePreservesProjectConfigFile()
{
// Arrange
var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var packageA = PackageUtility.CreatePackage("A");
repository.Object.AddPackage(packageA);
var fileSystem = new MockFileSystem();
fileSystem.AddFile("packages.cool.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
<package id=""B"" version=""3.0"" />
</packages>");
var referenceRepository = new PackageReferenceRepository(fileSystem, projectName: "cool", sourceRepository: repository.Object);
var packageB = PackageUtility.CreatePackage("B", "3.0");
// Act
referenceRepository.RemovePackage(packageB);
// Assert
Assert.False(fileSystem.FileExists("packages.config"));
Assert.True(fileSystem.FileExists("packages.cool.config"));
string content = fileSystem.ReadAllText("packages.cool.config");
AssertConfig(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""A"" version=""1.0"" />
</packages>", content);
}