本文整理汇总了C#中VsPackageManager.InstallPackage方法的典型用法代码示例。如果您正苦于以下问题:C# VsPackageManager.InstallPackage方法的具体用法?C# VsPackageManager.InstallPackage怎么用?C# VsPackageManager.InstallPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VsPackageManager
的用法示例。
在下文中一共展示了VsPackageManager.InstallPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: 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);
}
示例3: 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));
}
示例4: InstallPackageInstallsIntoProjectAndPackageManager
public void InstallPackageInstallsIntoProjectAndPackageManager()
{
// 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 package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" });
sourceRepository.AddPackage(package);
// 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(projectManager.LocalRepository.Exists(package));
}
示例5: InstallPackageInstallsIndirectPrereleaseDependency
public void InstallPackageInstallsIndirectPrereleaseDependency()
{
// 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 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.0", dependencies: new[] { new PackageDependency("bar") });
sourceRepository.AddPackage(package);
var versionSpec = VersionUtility.ParseVersionSpec("[0.6, 1.0)");
var package2 = PackageUtility.CreatePackage("bar", "2.0.0", dependencies: new[] { new PackageDependency("qux", versionSpec) });
sourceRepository.AddPackage(package2);
var package3A = PackageUtility.CreatePackage("qux", "1.0-alpha");
var package3B = PackageUtility.CreatePackage("qux", "1.0-beta");
var package3 = PackageUtility.CreatePackage("qux", "1.0");
localRepository.AddPackage(package3);
localRepository.AddPackage(package3A);
localRepository.AddPackage(package3B);
// Act
packageManager.InstallPackage(package, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(packageManager.LocalRepository.Exists(package));
Assert.True(packageManager.LocalRepository.Exists(package2));
Assert.True(packageManager.LocalRepository.Exists(package3B));
}
示例6: InstallPackageThrowsIfMinClientVersionIsNotSatisfied
public void InstallPackageThrowsIfMinClientVersionIsNotSatisfied()
{
// Arrange
Version nugetVersion = typeof(IPackage).Assembly.GetName().Version;
Version requiredVersion = new Version(nugetVersion.Major, nugetVersion.Minor, nugetVersion.Build, nugetVersion.Revision + 1);
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 package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }, minClientVersion: requiredVersion.ToString());
sourceRepository.AddPackage(package);
string expectedErrorMessage =
String.Format("The '{0}' package requires NuGet client version '{1}' or above, but the current NuGet version is '{2}'.", "foo 1.0", requiredVersion.ToString(), nugetVersion.ToString());
// Act & Assert
ExceptionAssert.Throws<NuGetVersionNotSatisfiedException>(
() => packageManager.InstallPackage(projectManager, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance),
expectedErrorMessage);
}
示例7: InstallPackageDoesNotInstallPackageWithIndirectDependencyThatIsPrerelease
public void InstallPackageDoesNotInstallPackageWithIndirectDependencyThatIsPrerelease()
{
// 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 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.0", dependencies: new[] { new PackageDependency("bar") });
sourceRepository.AddPackage(package);
var versionSpec = VersionUtility.ParseVersionSpec("[0.6, 1.0)");
var package2 = PackageUtility.CreatePackage("bar", "2.0.0", dependencies: new[] { new PackageDependency("qux", versionSpec) });
sourceRepository.AddPackage(package2);
var package3A = PackageUtility.CreatePackage("qux", "1.0-alpha");
var package3B = PackageUtility.CreatePackage("qux", "1.0-beta");
var package3 = PackageUtility.CreatePackage("qux", "1.0");
sourceRepository.AddPackage(package3);
sourceRepository.AddPackage(package3A);
sourceRepository.AddPackage(package3B);
// Act and Assert
ExceptionAssert.Throws<InvalidOperationException>(() => packageManager.InstallPackage(package, ignoreDependencies: false, allowPrereleaseVersions: false),
"Unable to resolve dependency 'qux (≥ 0.6 && < 1.0)'.");
}
示例8: InstallPackageUninstalledSolutionLevelPackagesAreNotAddedToSolutionPackageConfig
public void InstallPackageUninstalledSolutionLevelPackagesAreNotAddedToSolutionPackageConfig()
{
// 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 packageFoo = PackageUtility.CreatePackage("foo", "1.0", content: new[] { "hello" });
sourceRepository.AddPackage(packageFoo);
var packageBar1 = PackageUtility.CreatePackage("bar1", "2.0",
tools: new[] { "install.ps1" });
sourceRepository.AddPackage(packageBar1);
var packageBar2 = PackageUtility.CreatePackage("bar2", "2.0",
tools: new[] { "install.ps1" });
sourceRepository.AddPackage(packageBar2);
var operations = new PackageOperation[] {
new PackageOperation(packageFoo, PackageAction.Install),
new PackageOperation(packageBar1, PackageAction.Uninstall),
new PackageOperation(packageBar2, PackageAction.Uninstall)
};
// Act
packageManager.InstallPackage(
projectManager, packageFoo, operations,
ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.False(localRepository.IsReferenced("bar1", new SemanticVersion("2.0")));
Assert.False(localRepository.IsReferenced("bar2", new SemanticVersion("2.0")));
Assert.True(packageManager.LocalRepository.Exists(packageFoo));
Assert.True(projectManager.LocalRepository.Exists(packageFoo));
}
示例9: InstallPackageDoesNotCallsMarkPackageDirectoryForDeletion
public void InstallPackageDoesNotCallsMarkPackageDirectoryForDeletion()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var sourceRepository = new MockPackageRepository();
var packageA = PackageUtility.CreatePackage("A");
var deleteOnRestartManager = new Mock<IDeleteOnRestartManager>(MockBehavior.Strict);
sourceRepository.AddPackage(packageA);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object,
deleteOnRestartManager.Object, new Mock<VsPackageInstallerEvents>().Object);
// Act
packageManager.InstallPackage(null, "A", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
deleteOnRestartManager.Verify();
}
示例10: FindLocalPackageWhenAnUnusedVersionOfPackageIsPresentInPackagesFolder
public void FindLocalPackageWhenAnUnusedVersionOfPackageIsPresentInPackagesFolder()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
localRepository.Setup(m => m.IsReferenced("A", new SemanticVersion("2.0"))).Returns(true);
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var projectManager = new ProjectManager(sourceRepository, pathResolver, projectSystem, localRepository.Object);
var project = TestUtils.GetProject("foo");
var projects = new Project[] { project };
var packageA10 = PackageUtility.CreatePackage("A", "1.0", new string[] { "hello.txt" });
var packageA20 = PackageUtility.CreatePackage("A", "2.0", new string[] { "hello.txt" });
var packageA30 = PackageUtility.CreatePackage("A", "3.0", new string[] { "hello.txt" });
localRepository.Object.AddPackage(packageA10);
sourceRepository.AddPackage(packageA10);
sourceRepository.AddPackage(packageA20);
sourceRepository.AddPackage(packageA30);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(true, "foo", projects),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
packageManager.InstallPackage(projectManager, "A", packageA20.Version, true, true, null);
bool appliesToProject;
IPackage package = packageManager.FindLocalPackage("A", out appliesToProject);
Assert.True(package.Version.Version.Major == 2);
Assert.True(appliesToProject);
}
示例11: InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig2
public void InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig2(bool skipAssemblyReferences)
{
// Arrange
// Source repository has A -> B, where B is a project-level package and A is a meta-package.
// We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
var localRepository = new MockSharedPackageRepository();
var sourceRepository = new MockPackageRepository();
var packageA = PackageUtility.CreatePackage("A", "2.0", tools: new[] { "install.ps1" });
sourceRepository.Add(packageA);
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var projectRepository = new MockProjectPackageRepository(localRepository);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);
// Act
packageManager.InstallPackage(
projectManager,
"A",
new SemanticVersion("2.0"),
ignoreDependencies: false,
allowPrereleaseVersions: true,
skipAssemblyReferences: skipAssemblyReferences,
logger: null);
// Assert
Assert.True(!projectRepository.Exists("A", new SemanticVersion("2.0")));
// assert that packages.config for solution-level is created.
Assert.True(localRepository.IsSolutionReferenced("A", new SemanticVersion("2.0")));
}
示例12: InstallMetaPackageDoesNotAddEntryToSolutionPackagesConfig2
public void InstallMetaPackageDoesNotAddEntryToSolutionPackagesConfig2(bool skipAssemblyReferences)
{
// Arrange
// Source repository has A -> B, where B is a project-level package and A is a meta-package.
// We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var sourceRepository = new MockPackageRepository();
var packageB = PackageUtility.CreatePackage("B", "1.0", new string[] { "hello.txt" });
var packageA = PackageUtility.CreatePackage("A", "2.0", new string[] { "world" }, dependencies: new[] { new PackageDependency("B") });
sourceRepository.Add(packageA);
sourceRepository.Add(packageB);
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);
localRepository.Setup(r => r.IsReferenced(It.IsAny<string>(), It.IsAny<SemanticVersion>())).
Returns((string id, SemanticVersion version) => projectRepository.Exists(id, version));
// Act
packageManager.InstallPackage(
projectManager,
"A",
new SemanticVersion("2.0"),
ignoreDependencies: false,
allowPrereleaseVersions: true,
skipAssemblyReferences: skipAssemblyReferences,
logger: null);
// Assert
Assert.True(projectRepository.Exists("A", new SemanticVersion("2.0")));
Assert.True(projectRepository.Exists("B", new SemanticVersion("1.0")));
// assert that packages.config for solution-level is not created.
Assert.False(localRepository.Object.IsSolutionReferenced("A", new SemanticVersion("2.0")));
Assert.False(localRepository.Object.IsSolutionReferenced("B", new SemanticVersion("1.0")));
}
示例13: UpdatePackageUpdatesToTheHighestPackageIfPrereleaseFlagIsSetToTrue
public void UpdatePackageUpdatesToTheHighestPackageIfPrereleaseFlagIsSetToTrue()
{
// 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 packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, projectSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var package3_10A = PackageUtility.CreatePackage("qux", "1.0-alpha");
var package3_11B = PackageUtility.CreatePackage("qux", "1.1-alpha");
var package3_10 = PackageUtility.CreatePackage("qux", "1.0");
var package3_09 = PackageUtility.CreatePackage("qux", "0.9");
localRepository.AddPackage(package3_10);
localRepository.AddPackage(package3_10A);
localRepository.AddPackage(package3_11B);
localRepository.AddPackage(package3_09);
// Act
packageManager.InstallPackage(package3_09, ignoreDependencies: false, allowPrereleaseVersions: true);
Assert.True(packageManager.LocalRepository.Exists(package3_09));
packageManager.UpdatePackage("qux", updateDependencies: true, allowPrereleaseVersions: true);
// Assert
Assert.True(packageManager.LocalRepository.Exists(package3_11B));
}
示例14: InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig
public void InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig(bool allowPrerelease)
{
// Arrange
// Source repository has A -> B, where B is a project-level package and A is a meta-package.
// We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var sourceRepository = new MockPackageRepository();
var packageA = PackageUtility.CreatePackage("A", "2.0", tools: new[] { "install.ps1" });
sourceRepository.Add(packageA);
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository.Object,
new Mock<IRecentPackageRepository>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);
localRepository.Setup(r => r.IsReferenced(It.IsAny<string>(), It.IsAny<SemanticVersion>())).
Returns((string id, SemanticVersion version) => projectRepository.Exists(id, version));
// Act
packageManager.InstallPackage(
projectManager,
"A",
new SemanticVersion("2.0"),
ignoreDependencies: false,
allowPrereleaseVersions: allowPrerelease,
logger: null);
// Assert
Assert.True(!projectRepository.Exists("A", new SemanticVersion("2.0")));
// assert that packages.config for solution-level is created.
localRepository.Verify(r => r.AddPackageReferenceEntry("A", new SemanticVersion("2.0")), Times.Once());
}
示例15: MockPackageRepository
public void ReinstallPackagesDoesNotThrowWithNewDependencyWhenProjectFrameworkChangesIfAllowPrereleaseParameterIsFalseAndPackageVersionIsPrerelease()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v4.0"));
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageReferenceRepository = new PackageReferenceRepository(projectSystem, localRepository);
var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, packageReferenceRepository);
var packageManager = new VsPackageManager(
TestUtils.GetSolutionManager(),
sourceRepository,
new Mock<IFileSystemProvider>().Object,
projectSystem,
localRepository,
new Mock<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object);
var packageA = PackageUtility.CreatePackageWithDependencySets(
"A",
"1.2-alpha",
new[] { "contentA.txt" },
dependencySets: new PackageDependencySet[] {
new PackageDependencySet(new FrameworkName(".NETFramework, Version=v4.0"),
new [] { new PackageDependency("B")}),
new PackageDependencySet(new FrameworkName("Silverlight, Version=v5.0"),
new [] { new PackageDependency("C")})
});
var packageB = PackageUtility.CreatePackage(
"B",
"1.0",
new[] { "contentB.txt" });
var packageC = PackageUtility.CreatePackage(
"C",
"2.0-beta",
new[] { "contentC.txt" });
sourceRepository.Add(packageA);
sourceRepository.Add(packageB);
sourceRepository.Add(packageC);
packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
Assert.True(packageManager.LocalRepository.Exists("A"));
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.True(packageManager.LocalRepository.Exists("B"));
Assert.True(projectManager.LocalRepository.Exists("B"));
Assert.False(packageManager.LocalRepository.Exists("C"));
Assert.False(projectManager.LocalRepository.Exists("C"));
Assert.True(projectSystem.FileExists("contentA.txt"));
Assert.True(projectSystem.FileExists("contentB.txt"));
Assert.False(projectSystem.FileExists("contentC.txt"));
// now change project's target framework to silverilght
projectSystem.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v5.0"));
// Act
packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: false, logger: null);
// Assert
Assert.True(packageManager.LocalRepository.Exists("A"));
Assert.True(projectManager.LocalRepository.Exists("A"));
Assert.False(packageManager.LocalRepository.Exists("B"));
Assert.False(projectManager.LocalRepository.Exists("B"));
Assert.True(packageManager.LocalRepository.Exists("C"));
Assert.True(projectManager.LocalRepository.Exists("C"));
}