本文整理汇总了C#中NuGet.Test.Mocks.MockFileSystem.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem.AddFile方法的具体用法?C# MockFileSystem.AddFile怎么用?C# MockFileSystem.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGet.Test.Mocks.MockFileSystem
的用法示例。
在下文中一共展示了MockFileSystem.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPackageFindTheRightPackage
public void FindPackageFindTheRightPackage()
{
// Arrange
var fileSystem = new MockFileSystem("c:\\");
AddPackage(fileSystem, "A", "1.0");
AddPackage(fileSystem, "B", "1.0-alpha");
AddPackage(fileSystem, "C", "2.0.1-RC");
AddPackage(fileSystem, "D", "3.0");
// these are invalid packages (missing corresponding directory)
fileSystem.AddFile("AA.2.0.nupkg");
fileSystem.AddFile("BB.4.0.nupkg");
fileSystem.CreateDirectory("BB.3.0");
var pathResolver = new DefaultPackagePathResolver("c:\\");
var repository = new UnzippedPackageRepository(pathResolver, fileSystem);
// Act
var packageA = repository.FindPackage("A", new SemanticVersion("1.0"));
var packageB = repository.FindPackage("B", new SemanticVersion("1.0-alpha"));
// Assert
AssertPackage(packageA, "A", new SemanticVersion("1.0"));
AssertPackage(packageB, "B", new SemanticVersion("1.0.0-alpha"));
}
示例2: GetPackagesReturnsAllValidPackages
public void GetPackagesReturnsAllValidPackages()
{
// Arrange
var fileSystem = new MockFileSystem("c:\\");
AddPackage(fileSystem, "A", "1.0");
AddPackage(fileSystem, "B", "1.0-alpha");
AddPackage(fileSystem, "C", "2.0.1-RC");
AddPackage(fileSystem, "D", "3.0");
// these are invalid packages (missing corresponding directory)
fileSystem.AddFile("AA.2.0.nupkg");
fileSystem.AddFile("BB.4.0.nupkg");
fileSystem.CreateDirectory("BB.3.0");
var pathResolver = new DefaultPackagePathResolver("c:\\");
var repository = new UnzippedPackageRepository(pathResolver, fileSystem);
// Act
var packages = repository.GetPackages().ToList();
// Assert
Assert.Equal(4, packages.Count);
AssertPackage(packages[0], "A", new SemanticVersion("1.0"));
AssertPackage(packages[1], "B", new SemanticVersion("1.0.0-alpha"));
AssertPackage(packages[2], "C", new SemanticVersion("2.0.1-RC"));
AssertPackage(packages[3], "D", new SemanticVersion("3.0"));
}
示例3: ConfigFoundInDirectoryHierarchyIsCached
public void ConfigFoundInDirectoryHierarchyIsCached()
{
// Arrange
var solutionManager = new Mock<ISolutionManager>();
solutionManager.Setup(m => m.SolutionDirectory).Returns(@"bar\baz");
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"bar\nuget.config", @"
<settings>
<repositoryPath>lib</repositoryPath>
</settings>");
var fileSystemProvider = new Mock<IFileSystemProvider>();
fileSystemProvider.Setup(m => m.GetFileSystem(@"bar\baz")).Returns(fileSystem);
var repositorySettings = new RepositorySettings(solutionManager.Object, fileSystemProvider.Object);
// Act
string p1 = repositorySettings.RepositoryPath;
fileSystem.AddFile(@"bar\baz\nuget.config", @"
<settings>
<repositoryPath>foo</repositoryPath>
</settings>");
string p2 = repositorySettings.RepositoryPath;
// Assert
Assert.AreEqual(@"bar\lib", p1);
Assert.AreEqual(@"bar\lib", p2);
}
示例4: LoadPortableProfileWithMonoAsSupportedFramework
public void LoadPortableProfileWithMonoAsSupportedFramework()
{
// Arrange
string content1 = @"
<Framework
Identifier="".NETFramework""
Profile=""*""
MinimumVersion=""4.5""
DisplayName="".NET Framework"" />";
string content2 = @"
<Framework
Identifier=""MonoTouch""
MinimumVersion=""1.0""
DisplayName=""Mono Touch"" />";
var mockFileSystem = new MockFileSystem();
mockFileSystem.AddFile("frameworkFile1.xml", content1);
mockFileSystem.AddFile("frameworkFile2.xml", content2);
var frameworkFiles = new string[] { "frameworkFile1.xml", "frameworkFile2.xml" };
// Act
var netPortableProfile = NetPortableProfileTable.LoadPortableProfile("4.5.0.0", "Profile1", mockFileSystem, frameworkFiles);
// Assert
Assert.True(netPortableProfile.SupportedFrameworks.Count == 1);
Assert.True(netPortableProfile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));
Assert.True(netPortableProfile.OptionalFrameworks.Count == 1);
Assert.True(netPortableProfile.OptionalFrameworks.Contains(new FrameworkName("MonoTouch, Version=1.0")));
}
示例5: ResolvedRefreshPathsIgnoresFilesThatDoNotExist
public void ResolvedRefreshPathsIgnoresFilesThatDoNotExist()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"bin\Foo.refresh", "x:\foo.dll");
fileSystem.AddFile(@"bin\bar.refresh", "bar.dll");
fileSystem.AddFile(@"C:\MockFileSystem\bar.dll");
// Act
var resolvedPaths = fileSystem.ResolveRefreshPaths();
// Assert
Assert.Equal(new[] { @"C:\MockFileSystem\bar.dll" }, resolvedPaths);
}
示例6: AddingBindingRedirectToEmptyConfig
public void AddingBindingRedirectToEmptyConfig()
{
// Arrange
var mockFileSystem = new MockFileSystem();
mockFileSystem.AddFile("config", @"<configuration></configuration>");
var bindingRedirectManager = new BindingRedirectManager(mockFileSystem, "config");
AssemblyBinding assemblyBinding = GetAssemblyBinding("AssemblyName", "token", "3.0.0.0");
// Act
bindingRedirectManager.AddBindingRedirects(new[] { assemblyBinding });
// Assert
string outputContent = mockFileSystem.OpenFile("config").ReadToEnd();
Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<runtime>
<assemblyBinding xmlns=""urn:schemas-microsoft-com:asm.v1"">
<dependentAssembly>
<assemblyIdentity name=""AssemblyName"" publicKeyToken=""token"" culture=""neutral"" />
<bindingRedirect oldVersion=""0.0.0.0-3.0.0.0"" newVersion=""3.0.0.0"" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>", outputContent);
}
示例7: MirrorCommandForPackageReferenceFileWarnsIfThereIsNoPackageToMirror
public void MirrorCommandForPackageReferenceFileWarnsIfThereIsNoPackageToMirror()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
</packages>".AsStream());
MessageLevel? level = null;
string message = null;
var console = new Mock<IConsole>();
console.Setup(c => c.Log(It.IsAny<MessageLevel>(), It.IsAny<string>(), It.IsAny<object[]>())).Callback((MessageLevel a, string b, object[] c) =>
{
if (a == MessageLevel.Warning)
{
level = a;
message = b;
}
});
var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Console = console.Object };
// Act
mirrorCommand.ExecuteCommand();
// Assert
Assert.Equal(level, MessageLevel.Warning);
Assert.Equal(message, "No packages found to check for mirroring.");
}
示例8: DeleteFileAndEmptyParentDirectoriesDoNotDeleteParentDirectoryIfNotEmpty
public void DeleteFileAndEmptyParentDirectoriesDoNotDeleteParentDirectoryIfNotEmpty()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\");
fileSystem.AddFile("foo\\bar\\hell\\x.txt");
fileSystem.AddFile("foo\\bar\\y.txt");
// Act
fileSystem.DeleteFileAndParentDirectoriesIfEmpty("foo\\bar\\hell\\x.txt");
// Assert
Assert.False(fileSystem.FileExists("foo\\bar\\hell\\x.txt"));
Assert.True(fileSystem.DirectoryExists("foo"));
Assert.True(fileSystem.DirectoryExists("foo\\bar"));
Assert.False(fileSystem.DirectoryExists("foo\\bar\\hell"));
}
示例9: GetConfigurationDefaults
private ConfigurationDefaults GetConfigurationDefaults(string configurationDefaultsContent)
{
var mockFileSystem = new MockFileSystem();
var configurationDefaultsPath = "NuGetDefaults.config";
mockFileSystem.AddFile(configurationDefaultsPath, configurationDefaultsContent);
return new ConfigurationDefaults(mockFileSystem, configurationDefaultsPath);
}
示例10: RestoreCommandMultipleSolutionFiles
public void RestoreCommandMultipleSolutionFiles()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile("a.sln");
fileSystem.AddFile("b.sln");
var restoreCommand = new RestoreCommand()
{
FileSystem = fileSystem
};
// Assert
ExceptionAssert.Throws<InvalidOperationException>(
() => restoreCommand.DetermineRestoreMode(),
"This folder contains more than one solution file.");
}
示例11: RestoreCommandPreferSolutionFile
public void RestoreCommandPreferSolutionFile()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.AddFile("a.sln");
fileSystem.AddFile("packages.config");
var restoreCommand = new RestoreCommand()
{
FileSystem = fileSystem
};
// Act
restoreCommand.DetermineRestoreMode();
// Assert
Assert.True(restoreCommand.RestoringForSolution);
Assert.Equal(fileSystem.GetFullPath("a.sln"), restoreCommand.SolutionFileFullPath);
}
示例12: AddRefreshFilesForAssembliesReferencesIncludeFilesUnderLibRoot
public void AddRefreshFilesForAssembliesReferencesIncludeFilesUnderLibRoot()
{
// Arrange
var projectSystem = new MockProjectSystem();
var projectSystemFactory = new Mock<IProjectSystemFactory>();
projectSystemFactory.Setup(p => p.CreateProjectSystem(It.IsAny<Project>(), It.IsAny<IFileSystemProvider>()))
.Returns(projectSystem);
var websiteHandler = new VsWebsiteHandler(null, projectSystemFactory.Object);
var packagesFileSystem = new MockFileSystem("x:\\some\\path");
packagesFileSystem.CreateDirectory("A.1.0");
packagesFileSystem.CreateDirectory("A.1.0\\lib");
packagesFileSystem.AddFile("A.1.0\\lib\\one.dll");
packagesFileSystem.AddFile("A.1.0\\lib\\two.winmd");
packagesFileSystem.CreateDirectory("B.3.0.0-beta");
packagesFileSystem.CreateDirectory("B.3.0.0-beta\\lib");
packagesFileSystem.AddFile("B.3.0.0-beta\\lib\\three.dll");
packagesFileSystem.AddFile("B.3.0.0-beta\\lib\\four.exe");
var properties = new MockDteProperties();
properties.AddProperty("FullPath", "x:\\project");
properties.AddProperty("TargetFrameworkMoniker", ".NETFramework,Version=v4.0");
var website = new Mock<Project>();
website.Setup(p => p.Kind).Returns(VsConstants.WebSiteProjectTypeGuid);
website.Setup(p => p.Properties).Returns(properties);
// Act
websiteHandler.AddRefreshFilesForReferences(
website.Object, packagesFileSystem, new[] { new PackageName("A", new SemanticVersion("1.0")),
new PackageName("B", new SemanticVersion("3.0.0-beta"))});
// Assert
Assert.True(projectSystem.DirectoryExists("bin"));
var refreshFiles = projectSystem.GetFiles("bin", "*.refresh").OrderBy(s => s).ToList();
Assert.Equal(4, refreshFiles.Count);
Assert.Equal("bin\\four.exe.refresh", refreshFiles[0]);
Assert.Equal("bin\\one.dll.refresh", refreshFiles[1]);
Assert.Equal("bin\\three.dll.refresh", refreshFiles[2]);
Assert.Equal("bin\\two.winmd.refresh", refreshFiles[3]);
}
示例13: MissingManifestFileThrows
public void MissingManifestFileThrows()
{
// Arrange
var fileSystem = new MockFileSystem();
fileSystem.CreateDirectory("jQuery.2.0.0");
fileSystem.AddFile("jQuery.2.0.0.nupkg");
// Act & Assert
Assert.Throws(typeof(InvalidOperationException), () => new UnzippedPackage(fileSystem, "jQuery.2.0.0"));
}
示例14: GetPackageReferencesNormalizeProjectName
public void GetPackageReferencesNormalizeProjectName()
{
// Arrange
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
<package id=""luan"" version=""1.0"" />
</packages>";
var fileSystem = new MockFileSystem();
fileSystem.AddFile("packages.config", config);
fileSystem.AddFile("packages.project_with_space.config", config);
var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config", "project with space");
// Act
var values = packageReferenceFile.GetPackageReferences().ToArray();
// Assert
Assert.Equal(1, values.Length);
Assert.Equal("luan", values[0].Id);
}
示例15: CallingCtorWithMalformedConfigThrowsException
public void CallingCtorWithMalformedConfigThrowsException()
{
var mockFileSystem = new MockFileSystem();
var nugetConfigPath = "NuGet.Config";
string config = @"<configuration><sectionName></configuration>";
mockFileSystem.AddFile(nugetConfigPath, config);
// Act & Assert
ExceptionAssert.Throws<System.Xml.XmlException>(() => new Settings(mockFileSystem));
}