本文整理汇总了C#中DefaultPackagePathResolver类的典型用法代码示例。如果您正苦于以下问题:C# DefaultPackagePathResolver类的具体用法?C# DefaultPackagePathResolver怎么用?C# DefaultPackagePathResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPackagePathResolver类属于命名空间,在下文中一共展示了DefaultPackagePathResolver类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: IsPackageInstalled
/// <summary>
/// Checks whether an IPackage exists within a PackageManager. By default, will use the UseSideBySide settings of the DefaultPackagePathProvider the PackageManager is instantiated with.
/// If passed in TRUE for exhaustive, will check both with and without UseSideBySide set.
/// </summary>
/// <param name="packageManager"></param>
/// <param name="package"></param>
/// <param name="exhaustive"></param>
/// <returns></returns>
public static bool IsPackageInstalled(this PackageManager packageManager, IPackage package, bool exhaustive = false)
{
var pathsDictionary = new Dictionary<string, bool>();
//Oh god oh god. The <center> cannot hold it is too late.
var useSideBySide = packageManager.PathResolver.GetPrivateField<bool>("_useSideBySidePaths");
pathsDictionary.Add(Path.Combine(packageManager.PathResolver.GetInstallPath(package),
packageManager.PathResolver.GetPackageFileName(package.Id, package.Version)), useSideBySide);
//We need to also check the inverse, to see if it was installed with the other setting....
if (exhaustive)
{
var inversePathResolver = new DefaultPackagePathResolver(packageManager.PathResolver.GetPrivateField<IFileSystem>("_fileSystem"), !useSideBySide);
pathsDictionary.Add(Path.Combine(inversePathResolver.GetInstallPath(package), inversePathResolver.GetPackageFileName(package.Id, package.Version)), !useSideBySide);
}
foreach (var path in pathsDictionary.Where(path => packageManager.FileSystem.FileExists(path.Key)))
{
if (path.Value)
{
return true;
}
//If not useSideBySide, we need to crack open the zip file.
//Need to crack the package open at this point and check the version, otherwise we just need to download it regardless
var zipPackage = new ZipPackage(packageManager.FileSystem.OpenFile(path.Key));
if (zipPackage.Version == package.Version)
{
return true;
}
}
//Its not here. Really. We tried.
return false;
}
开发者ID:modulexcite,项目名称:NuGet.Extras,代码行数:43,代码来源:IPackageManagerExtensions.cs
示例2: ResolvePackage
private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package)
{
string id = package.ItemSpec;
string version = package.GetMetadata("Version");
Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version);
// Initial version just searches a machine-level repository
var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib"));
var defaultResolver = new DefaultPackagePathResolver(localFs);
var machineRepo = new LocalPackageRepository(defaultResolver, localFs);
var buildRepo = new BuildPackageRepository();
var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2"));
var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences);
var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo);
var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo);
// Install the package
var ver = new SemanticVersion(version);
manager.PackageInstalling += manager_PackageInstalling;
manager.InstallPackage(id, ver);
projectManager.AddPackageReference(id, ver);
return project.OutputReferences.Select(item =>
{
var name = AssemblyName.GetAssemblyName(item);
return new TaskItem(name.FullName, new Dictionary<string, string>() {
{"HintPath", item },
{"Private", "true"}
});
});
}
开发者ID:anurse,项目名称:NuGetBuild,代码行数:33,代码来源:ResolvePackageReference.cs
示例3: 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"));
}
开发者ID:Newtopian,项目名称:nuget,代码行数:25,代码来源:UnzippedPackageRepositoryTest.cs
示例4: InstallMetadataPackageWithReadMeInstallsIntoProjectAndPackageManager
public void InstallMetadataPackageWithReadMeInstallsIntoProjectAndPackageManager()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B") });
var mockPackageA = Mock.Get(packageA);
mockPackageA.Setup(m => m.GetFiles()).Returns(PackageUtility.CreateFiles(new[] { "readme.txt" }));
var packageB = PackageUtility.CreatePackage("B", "1.0", content: new[] { "hello.txt" });
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
// Act
packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists(packageA));
Assert.True(projectManager.LocalRepository.Exists(packageA));
Assert.True(packageManager.LocalRepository.Exists(packageB));
Assert.True(projectManager.LocalRepository.Exists(packageB));
}
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:28,代码来源:VsPackageManagerTest.cs
示例5: InstallPackageAddsAllFilesToFileSystem
public void InstallPackageAddsAllFilesToFileSystem()
{
// Arrange
var projectSystem = new MockProjectSystem();
var sourceRepository = new MockPackageRepository();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new PackageManager(sourceRepository, pathResolver, projectSystem,
new SharedPackageRepository(pathResolver, projectSystem, projectSystem));
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "contentFile", @"sub\contentFile" },
new[] { @"lib\reference.dll" },
new[] { @"readme.txt" });
sourceRepository.AddPackage(packageA);
// Act
Install("A", new NullProjectManager(packageManager));
// Assert
Assert.Equal(0, projectSystem.References.Count);
Assert.Equal(5, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"A.1.0\content\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\content\sub\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\lib\reference.dll"));
Assert.True(projectSystem.FileExists(@"A.1.0\tools\readme.txt"));
Assert.True(projectSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
}
开发者ID:rikoe,项目名称:nuget,代码行数:28,代码来源:PackageManagerTest.cs
示例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"));
}
开发者ID:Newtopian,项目名称:nuget,代码行数:27,代码来源:UnzippedPackageRepositoryTest.cs
示例7: 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());
}
开发者ID:xero-github,项目名称:Nuget,代码行数:29,代码来源:VsInstallerTest.cs
示例8: ReinstallPackagesRestoresPackageWithTheSameVersion
public void ReinstallPackagesRestoresPackageWithTheSameVersion()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" });
sourceRepository.Add(packageA);
localRepository.AddPackage(packageA);
projectManager.LocalRepository.AddPackage(packageA);
// Act
packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: null);
// Assert
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
}
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:30,代码来源:VsPackageManagerTest.Reinstall.cs
示例9: InstallPackageSetOperationToInstall3
public void InstallPackageSetOperationToInstall3()
{
// Arrange
var localRepository = new MockSharedPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" });
sourceRepository.AddPackage(package);
var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" });
sourceRepository.AddPackage(package2);
// Act
packageManager.InstallPackage(
projectManager,
package2,
new PackageOperation[] {
new PackageOperation(package, PackageAction.Install),
new PackageOperation(package2, PackageAction.Install),
},
ignoreDependencies: false,
allowPrereleaseVersions: false,
logger: NullLogger.Instance);
// Assert
Assert.Equal("Install", sourceRepository.LastOperation);
Assert.Equal("bar", sourceRepository.LastMainPackageId);
Assert.Equal("2.0", sourceRepository.LastMainPackageVersion);
}
开发者ID:Newtopian,项目名称:nuget,代码行数:33,代码来源:VsPackageManagerTest.Operation.cs
示例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());
}
开发者ID:monoman,项目名称:NugetCracker,代码行数:32,代码来源:VsInstallerTest.cs
示例11: InstallPackageWithOperationsExecuteAllOperations
public void InstallPackageWithOperationsExecuteAllOperations()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), new MockPackageRepository());
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, projectSystem, localRepository, new Mock<IRecentPackageRepository>().Object);
var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, dependencies: new PackageDependency[] { new PackageDependency("bar") });
sourceRepository.AddPackage(package);
var package2 = PackageUtility.CreatePackage("bar", "2.0", new[] { "world" });
sourceRepository.AddPackage(package2);
var package3 = PackageUtility.CreatePackage("awesome", "1.0", new[] { "candy" });
localRepository.AddPackage(package3);
var operations = new PackageOperation[] {
new PackageOperation(package, PackageAction.Install),
new PackageOperation(package2, PackageAction.Install),
new PackageOperation(package3, PackageAction.Uninstall)
};
// Act
packageManager.InstallPackage(projectManager, package, operations, ignoreDependencies: false, logger: NullLogger.Instance);
// Assert
Assert.IsTrue(packageManager.LocalRepository.Exists(package));
Assert.IsTrue(packageManager.LocalRepository.Exists(package2));
Assert.IsTrue(!packageManager.LocalRepository.Exists(package3));
Assert.IsTrue(projectManager.LocalRepository.Exists(package));
Assert.IsTrue(projectManager.LocalRepository.Exists(package2));
}
开发者ID:jacksonh,项目名称:nuget,代码行数:35,代码来源:VsPackageManagerTest.cs
示例12: SupportsPrereleasePackagesReturnsTrue
public void SupportsPrereleasePackagesReturnsTrue()
{
// Arrange
var fileSystem = new MockFileSystem("c:\\");
var pathResolver = new DefaultPackagePathResolver("c:\\");
// Act
var repository = new UnzippedPackageRepository(pathResolver, fileSystem);
// Assert
Assert.True(repository.SupportsPrereleasePackages);
}
开发者ID:Newtopian,项目名称:nuget,代码行数:12,代码来源:UnzippedPackageRepositoryTest.cs
示例13: Setup
public void Setup()
{
var mfs = new Mock<MockFileSystem>() { CallBase = true };
var pr = new DefaultPackagePathResolver(mfs.Object);
var mc = MachineCache.Default;
var l = new LocalPackageRepository(pr, mfs.Object);
var r1 = new DataServicePackageRepository(new Uri(@"http://nuget.org"));
var r2 = new DataServicePackageRepository(new Uri(@"http://beta.nuget.org"));
ar = new AggregateRepository(new List<IPackageRepository>() { mc, l, r1, r2 });
}
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:12,代码来源:AggregateRepositoryExtensionsTests.cs
示例14: GetPackageDirectoryWithSideBySideOnAppendsVersionToEndOfPackageDirectory
public void GetPackageDirectoryWithSideBySideOnAppendsVersionToEndOfPackageDirectory()
{
// Arrange
MockFileSystem fs = new MockFileSystem();
DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs);
IPackage testPackage = PackageUtility.CreatePackage("Test");
// Act
string packageDir = resolver.GetPackageDirectory(testPackage);
// Assert
Assert.Equal("Test.1.0", packageDir);
}
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:13,代码来源:DefaultPackagePathResolverTest.cs
示例15: GetPackageFileNameWithSideBySideOffDoesNotAppendVersionToEndOfPackageDirectory
public void GetPackageFileNameWithSideBySideOffDoesNotAppendVersionToEndOfPackageDirectory()
{
// Arrange
MockFileSystem fs = new MockFileSystem();
DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs, useSideBySidePaths: false);
IPackage testPackage = PackageUtility.CreatePackage("Test");
// Act
string packageDir = resolver.GetPackageFileName(testPackage);
// Assert
Assert.Equal("Test" + Constants.PackageExtension, packageDir);
}
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:13,代码来源:DefaultPackagePathResolverTest.cs
示例16: GetInstallPathPrependsFileSystemRootToPackageDirectory
public void GetInstallPathPrependsFileSystemRootToPackageDirectory()
{
// Arrange
MockFileSystem fs = new MockFileSystem();
DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs);
IPackage testPackage = PackageUtility.CreatePackage("Test");
// Act
string installPath = resolver.GetInstallPath(testPackage);
// Assert
Assert.Equal(fs.Root + "Test.1.0", installPath);
}
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:13,代码来源:DefaultPackagePathResolverTest.cs
示例17: FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver
public void FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver(string id, string version, string packageName)
{
// Arrange
var repositoryRoot = CreatePackage(id, version, packageName);
var fileSystem = new PhysicalFileSystem(repositoryRoot);
var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false);
var repository = new LocalPackageRepository(pathResolver, fileSystem);
// Act
var findPackage = repository.FindPackage(id, new SemanticVersion(version));
// Assert
AssertPackage(id, version, findPackage);
}
开发者ID:xero-github,项目名称:Nuget,代码行数:14,代码来源:LocalPackageRepositoryTest.cs
示例18: InstallPackageUsesProjectTargetFramework
public void InstallPackageUsesProjectTargetFramework()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5"));
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var dependencySets = new PackageDependencySet[] {
new PackageDependencySet(
new FrameworkName(".NETFramework, Version=4.5"),
new [] { new PackageDependency("B") }),
new PackageDependencySet(
new FrameworkName(".NETFramework, Version=4.0"),
new [] { new PackageDependency("C") })
};
var package = PackageUtility.CreatePackageWithDependencySets(
"foo",
"1.0",
new[] { "hello" },
dependencySets: dependencySets);
var packageB = PackageUtility.CreatePackage("B", "2.0", new[] { "good morning" });
var packageC = PackageUtility.CreatePackage("C", "2.0", new[] { "good morning" });
sourceRepository.AddPackage(package);
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage(projectManager, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists(package));
Assert.True(packageManager.LocalRepository.Exists(packageB));
Assert.False(packageManager.LocalRepository.Exists(packageC));
Assert.True(projectManager.LocalRepository.Exists(package));
Assert.True(projectManager.LocalRepository.Exists(packageB));
}
开发者ID:themotleyfool,项目名称:NuGet,代码行数:49,代码来源:VsPackageManagerTest.cs
示例19: ReinstallPackagesSkipsReinstallingIfPackageDoesNotExistAndLogWarning
public void ReinstallPackagesSkipsReinstallingIfPackageDoesNotExistAndLogWarning()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());
var installerEvents = new Mock<VsPackageInstallerEvents>(MockBehavior.Strict);
int eventCount = 0;
RegisterInstallerEvents(installerEvents, _ => eventCount++);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
installerEvents.Object);
var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" });
sourceRepository.Add(packageA);
localRepository.AddPackage(packageA);
projectManager.LocalRepository.AddPackage(packageA);
// remove package from source repository to simulate missing package condition
sourceRepository.Remove(packageA);
var logger = new Mock<ILogger>();
logger.Setup(s => s.Log(
MessageLevel.Warning,
"Skipped reinstalling package '{0}' in project '{1}' because the package does not exist in the package source.",
"A 1.2",
"x:\\MockFileSystem")
).Verifiable();
// Act
packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: logger.Object);
// Assert
logger.Verify();
Assert.Equal(0, eventCount);
Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
}
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:48,代码来源:VsPackageManagerTest.Reinstall.cs
示例20: UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite
public void UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var constraintProvider = NullConstraintProvider.Instance;
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var projectSystem = new MockProjectSystem();
projectSystem.AddFile("one.txt", "this is one");
projectSystem.AddFile("two.txt", "this is two");
var packages = new List<IPackage>();
var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" });
localRepository.Add(package_A10);
sourceRepository.Add(package_A12);
var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p));
sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());
var repositoryFactory = new Mock<IPackageRepositoryFactory>();
repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository);
var packageSourceProvider = new Mock<IPackageSourceProvider>();
packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });
var console = new Mock<IConsole>();
console.Setup(c => c.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.Ignore);
var updateCommand = new UpdateCommand()
{
RepositoryFactory = repositoryFactory.Object,
SourceProvider = packageSourceProvider.Object,
Console = console.Object,
FileConflictAction = FileConflictAction.Overwrite
};
// Act
updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);
// Assert
Assert.True(localRepository.Exists("A", new SemanticVersion("1.2")));
Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));
}
开发者ID:Newtopian,项目名称:nuget,代码行数:47,代码来源:UpdateCommandTest.cs
注:本文中的DefaultPackagePathResolver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论