本文整理汇总了C#中NuGet.Test.Mocks.MockFileSystem类的典型用法代码示例。如果您正苦于以下问题:C# MockFileSystem类的具体用法?C# MockFileSystem怎么用?C# MockFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockFileSystem类属于NuGet.Test.Mocks命名空间,在下文中一共展示了MockFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConfigurationDefaults
private ConfigurationDefaults GetConfigurationDefaults(string configurationDefaultsContent)
{
var mockFileSystem = new MockFileSystem();
var configurationDefaultsPath = "NuGetDefaults.config";
mockFileSystem.AddFile(configurationDefaultsPath, configurationDefaultsContent);
return new ConfigurationDefaults(mockFileSystem, configurationDefaultsPath);
}
示例2: 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")));
}
示例3: InstallPackageRunsInitAndInstallScripts
public void InstallPackageRunsInitAndInstallScripts()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
var project = TestUtils.GetProject("Foo");
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
var scriptExecutor = new Mock<IScriptExecutor>();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
sourceRepository.AddPackage(package);
var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock<IPackageRepositoryFactory>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object);
// Act
installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, skipAssemblyReferences: false);
// Assert
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Init, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Install, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<ILogger>()), Times.Once());
}
示例4: 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);
}
示例5: 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.");
}
示例6: 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"));
}
示例7: CallAddPackageWillAddNuspecWhichHasReferencesData
public void CallAddPackageWillAddNuspecWhichHasReferencesData()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\root");
var configFileSystem = new MockFileSystem();
var repository = new SharedPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem, configFileSystem);
// Act
repository.AddPackage(PackageUtility.CreatePackage("A",
"1.0",
assemblyReferences: new[] { "lib\\net40\\A.dll", "lib\\B.dll" }));
// Assert
Assert.True(fileSystem.FileExists("A.1.0\\A.1.0.nuspec"));
Stream manifestContentStream = fileSystem.OpenFile("A.1.0\\A.1.0.nuspec");
Manifest manifest = Manifest.ReadFrom(manifestContentStream, validateSchema: true);
Assert.Equal(2, manifest.Metadata.ReferenceSets.Count);
var set1 = manifest.Metadata.ReferenceSets[0];
Assert.Equal(".NETFramework4.0", set1.TargetFramework);
Assert.Equal(1, set1.References.Count);
Assert.Equal("A.dll", set1.References[0].File);
var set2 = manifest.Metadata.ReferenceSets[1];
Assert.Null(set2.TargetFramework);
Assert.Equal(1, set2.References.Count);
Assert.Equal("B.dll", set2.References[0].File);
}
示例8: ConfigurationCacheIsClearedIfSolutionCloses
public void ConfigurationCacheIsClearedIfSolutionCloses()
{
// Arrange
var solutionManager = new Mock<MockSolutionManager>();
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;
solutionManager.Object.CloseSolution();
fileSystem.AddFile(@"bar\baz\nuget.config", @"
<settings>
<repositoryPath>foo</repositoryPath>
</settings>");
string p2 = repositorySettings.RepositoryPath;
// Assert
Assert.AreEqual(@"bar\lib", p1);
Assert.AreEqual(@"bar\baz\foo", p2);
}
示例9: FindPackageReturnsNullForNonExistingPackage
public void FindPackageReturnsNullForNonExistingPackage()
{
// 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("2.0"));
var packageB = repository.FindPackage("BBB", new SemanticVersion("1.0-alpha"));
// Assert
Assert.Null(packageA);
Assert.Null(packageB);
}
示例10: InstallPackageDoesNotUseFallbackRepository
public void InstallPackageDoesNotUseFallbackRepository()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(new MockProjectSystem());
var project = TestUtils.GetProject("Foo");
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
var scriptExecutor = new Mock<IScriptExecutor>();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository, new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false)).Returns(packageManager.Object);
packageManagerFactory.Setup(m => m.CreatePackageManager()).Throws(new Exception("A"));
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true, It.IsAny<bool>())).Throws(new Exception("B"));
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
var package = NuGet.Test.PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, tools: new[] { "init.ps1", "install.ps1" });
sourceRepository.AddPackage(package);
var installer = new VsPackageInstaller(packageManagerFactory.Object, scriptExecutor.Object, new Mock<IPackageRepositoryFactory>().Object);
// Act
installer.InstallPackage(sourceRepository, project, "foo", new SemanticVersion("1.0"), ignoreDependencies: false);
// Assert
packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false, false), Times.Once());
packageManagerFactory.Verify(m => m.CreatePackageManager(), Times.Never());
packageManagerFactory.Verify(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true, It.IsAny<bool>()), Times.Never());
}
示例11: GetFrameworkAssembliesReturnsEmptyListWhenFileDoesNotExist
public void GetFrameworkAssembliesReturnsEmptyListWhenFileDoesNotExist()
{
// Arrange
// Pass in a fileSystem with no file in it. An empty list should be returned
var mockFileSystem = new MockFileSystem(MockFileSystemRoot);
// Act & Assert
Assert.Empty(FrameworkAssemblyResolver.GetFrameworkAssemblies(mockFileSystem));
}
示例12: CallingGetValueWithNullKeyWillThrowException
public void CallingGetValueWithNullKeyWillThrowException()
{
// Arrange
var mockFileSystem = new MockFileSystem();
var settings = new Settings(mockFileSystem);
// Act & Assert
ExceptionAssert.Throws<ArgumentException>(() => settings.GetValue("SomeSection", null));
}
示例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: 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));
}
示例15: ResolveRefreshPathsReturnsEmptyCollectionIfNoRefreshFilesAreFoundInBin
public void ResolveRefreshPathsReturnsEmptyCollectionIfNoRefreshFilesAreFoundInBin()
{
// Arrange
var fileSystem = new MockFileSystem();
// Act
var resolvedPaths = fileSystem.ResolveRefreshPaths();
// Assert
Assert.Empty(resolvedPaths);
}