本文整理汇总了C#中NuGet.VisualStudio.Test.MockProjectPackageRepository类的典型用法代码示例。如果您正苦于以下问题:C# MockProjectPackageRepository类的具体用法?C# MockProjectPackageRepository怎么用?C# MockProjectPackageRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockProjectPackageRepository类属于NuGet.VisualStudio.Test命名空间,在下文中一共展示了MockProjectPackageRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UninstallPackageExecutesUninstallScript
public void UninstallPackageExecutesUninstallScript()
{
// Arrange
var activeRepository = new MockPackageRepository();
var localRepository = new Mock<MockPackageRepository>() { CallBase = true };
localRepository.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var project = TestUtils.GetProject("Foo");
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository);
var package = PackageUtility.CreatePackage("A");
var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict);
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", package, project, NullLogger.Instance)).Returns(true).Verifiable();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new MockFileSystem(), localRepository.Object,
new Mock<IRecentPackageRepository>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable();
var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object);
// Act
localRepository.Object.AddPackage(package);
packageUninstaller.UninstallPackage(project, "A", removeDependencies: true);
// Assert
scriptExecutor.Verify();
Assert.False(localRepository.Object.Contains(package));
}
示例2: UninstallPackageRemovesDependenciesIfFlagIsTrue
public void UninstallPackageRemovesDependenciesIfFlagIsTrue()
{
// Arrange
var activeRepository = new MockPackageRepository();
var localRepository = new Mock<MockPackageRepository>() { CallBase = true };
localRepository.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var project = TestUtils.GetProject("Foo");
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository);
var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B");
var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict);
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, It.IsAny<FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable();
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\B.1.0", "uninstall.ps1", packageB, project, It.IsAny<FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable();
var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object);
// Act
localRepository.Object.AddPackage(packageA);
localRepository.Object.AddPackage(packageB);
packageUninstaller.UninstallPackage(project, "A", removeDependencies: true);
// Assert
scriptExecutor.Verify();
Assert.False(localRepository.Object.Contains(packageA));
Assert.False(localRepository.Object.Contains(packageB));
}
示例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: 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());
}
示例5: InstallPackageConvertsVersionToSemanticVersion
public void InstallPackageConvertsVersionToSemanticVersion()
{
// 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<IDeleteOnRestartManager>().Object,
new Mock<VsPackageInstallerEvents>().Object,
/* multiFrameworkTargeting */ null)
{
CallBase = true
};
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>(MockBehavior.Strict);
packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager);
packageRepositoryFactory.Setup(r => r.CreateRepository(@"x:\test")).Returns(new MockPackageRepository()).Verifiable();
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, packageRepositoryFactory.Object, new Mock<IOutputConsoleProvider>().Object, new Mock<IVsCommonOperations>().Object, new Mock<ISolutionManager>().Object, null, null);
// Act
installer.InstallPackage(@"x:\test", project, "foo", new Version("1.0"), ignoreDependencies: false);
// Assert
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Init, It.IsAny<IPackage>(), null, null, It.IsAny<ILogger>()), Times.Once());
scriptExecutor.Verify(e => e.Execute(It.IsAny<string>(), PowerShellScripts.Install, It.IsAny<IPackage>(), It.IsAny<Project>(), It.IsAny<FrameworkName>(), It.IsAny<ILogger>()), Times.Once());
packageRepositoryFactory.Verify();
}
示例6: InstallPackageTurnOffBindingRedirect
public void InstallPackageTurnOffBindingRedirect()
{
// 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>();
packageManager.As<IVsPackageManager>().SetupGet(m => m.BindingRedirectEnabled).Returns(true);
int state = 1;
packageManager.As<IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = false).Callback(() => state += 1);
packageManager.As<IVsPackageManager>().SetupSet(m => m.BindingRedirectEnabled = true).Callback(() => state *= 2);
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
// state = 4 means that BindingRedirectEnabled is set to 'false', then to 'true', in that order.
// no other value of 4 can result in the same value of 4.
Assert.Equal(4, state);
packageManager.As<IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = false, Times.Once());
packageManager.As<IVsPackageManager>().VerifySet(m => m.BindingRedirectEnabled = true, Times.Once());
}
示例7: UpdatePackageWithMultipleSharedDependencies
public void UpdatePackageWithMultipleSharedDependencies()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
// A1 -> B1, C1
// A2 -> B1
var A10 = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "A1.dll" }, dependencies: new[] {
new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")),
new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")),
});
var A20 = PackageUtility.CreatePackage("A", "2.0", assemblyReferences: new[] { "A2.dll" }, dependencies: new[] {
new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0"))
});
var B10 = PackageUtility.CreatePackage("B", "1.0", assemblyReferences: new[] { "B1.dll" });
var C10 = PackageUtility.CreatePackage("C", "1.0", assemblyReferences: new[] { "C1.dll" });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
sourceRepository.AddPackage(B10);
sourceRepository.AddPackage(C10);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
localRepository.Object.AddPackage(B10);
localRepository.Object.AddPackage(C10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);
projectManager.AddPackageReference("A", new SemanticVersion("1.0"));
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.False(packageManager.LocalRepository.Exists(A10));
Assert.False(projectSystem.ReferenceExists("A1.dll"));
Assert.False(packageManager.LocalRepository.Exists(C10));
Assert.False(projectSystem.ReferenceExists("C1.dll"));
Assert.True(packageManager.LocalRepository.Exists(B10));
Assert.True(projectSystem.ReferenceExists("B1.dll"));
Assert.True(packageManager.LocalRepository.Exists(A20));
Assert.True(projectSystem.ReferenceExists("A2.dll"));
}
示例8: UpdatePackagesWithOperationsAddPackageCorrectly
public void UpdatePackagesWithOperationsAddPackageCorrectly()
{
// Arrange
var localRepository = new MockSharedPackageRepository();
var projectRepository = new MockProjectPackageRepository(localRepository);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A1 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello1" });
var A2 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello2" });
var A3 = PackageUtility.CreatePackage("A", "3.0", new[] { "hello3" });
var B1 = PackageUtility.CreatePackage("B", "1.0", new[] { "world1" });
var B2 = PackageUtility.CreatePackage("B", "2.0", new[] { "world2" });
sourceRepository.AddPackage(A2);
sourceRepository.AddPackage(A3);
sourceRepository.AddPackage(B1);
sourceRepository.AddPackage(B2);
localRepository.AddPackage(A1);
localRepository.AddPackage(B1);
projectRepository.Add(A1);
projectRepository.Add(B1);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);
var operations = new PackageOperation[] {
new PackageOperation(A3, PackageAction.Install),
new PackageOperation(B2, PackageAction.Install)
};
// Act
packageManager.UpdatePackages(projectManager, new[] { A3, B2 }, operations, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance);
// Assert
Assert.True(localRepository.Exists("A", new SemanticVersion("3.0")));
Assert.False(localRepository.Exists("A", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("A", new SemanticVersion("1.0")));
Assert.True(localRepository.Exists("B", new SemanticVersion("2.0")));
Assert.False(localRepository.Exists("B", new SemanticVersion("1.0")));
Assert.True(projectRepository.Exists("A", new SemanticVersion("3.0")));
Assert.True(projectRepository.Exists("B", new SemanticVersion("2.0")));
}
示例9: UpdatePackageWithSharedDependency
public void UpdatePackageWithSharedDependency()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
// A1 -> B1
// A2 -> B2
// F1 -> G1
// G1 -> B1
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")) });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("2.0")) });
var B10 = PackageUtility.CreatePackage("B", "1.0", new[] { "hello" });
var B20 = PackageUtility.CreatePackage("B", "2.0", new[] { "hello" });
var F10 = PackageUtility.CreatePackage("F", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("G", VersionUtility.ParseVersionSpec("1.0")) });
var G10 = PackageUtility.CreatePackage("G", "1.0", new[] { "hello" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")) });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
sourceRepository.AddPackage(B10);
sourceRepository.AddPackage(B20);
sourceRepository.AddPackage(F10);
sourceRepository.AddPackage(G10);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
localRepository.Object.AddPackage(B10);
localRepository.Object.AddPackage(B20);
localRepository.Object.AddPackage(F10);
localRepository.Object.AddPackage(G10);
projectRepository.Add(A10);
projectRepository.Add(B10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.False(packageManager.LocalRepository.Exists(A10));
Assert.False(packageManager.LocalRepository.Exists(B10));
Assert.True(packageManager.LocalRepository.Exists(A20));
Assert.True(packageManager.LocalRepository.Exists(B20));
Assert.True(packageManager.LocalRepository.Exists(F10));
Assert.True(packageManager.LocalRepository.Exists(G10));
}
示例10: UpdatePackageThrowsIfNewPackageHasMinClientVersionNotSatisfied
public void UpdatePackageThrowsIfNewPackageHasMinClientVersionNotSatisfied()
{
// 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>();
localRepository.Setup(m => m.IsReferenced("A", new SemanticVersion("1.0"))).Returns(false);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" }, minClientVersion: requiredVersion.ToString());
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
projectRepository.Add(A10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
string expectedErrorMessage =
String.Format("The '{0}' package requires NuGet client version '{1}' or above, but the current NuGet version is '{2}'.", "A 2.0", requiredVersion.ToString(), nugetVersion.ToString());
// Act && Assert
ExceptionAssert.Throws<NuGetVersionNotSatisfiedException>(
() => packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance),
expectedErrorMessage);
}
示例11: UpdatePackageDoesNotRemovesPackageIfPackageIsReferenced
public void UpdatePackageDoesNotRemovesPackageIfPackageIsReferenced()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
localRepository.Setup(m => m.IsReferenced("A", new SemanticVersion("1.0"))).Returns(true);
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
var A10 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello" });
var A20 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello" });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
projectRepository.Add(A10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), projectRepository);
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance);
// Assert
Assert.True(packageManager.LocalRepository.Exists(A10));
}
示例12: 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());
}
示例13: 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")));
}
示例14: UninstallPackageDoesNotForceRemovesPackages
public void UninstallPackageDoesNotForceRemovesPackages()
{
// Arrange
var activeRepository = new MockPackageRepository();
var localRepository = new Mock<MockPackageRepository>() { CallBase = true };
localRepository.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var project = TestUtils.GetProject("Foo");
var projectSystem = new MockProjectSystem();
var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository);
var packageA = PackageUtility.CreatePackage("A", dependencies: new[] { new PackageDependency("B") });
var packageB = PackageUtility.CreatePackage("B");
var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict);
scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", packageA, project, It.IsAny<FrameworkName>(), NullLogger.Instance)).Returns(true).Verifiable();
var packageManager = new Mock<VsPackageManager>(TestUtils.GetSolutionManager(), activeRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), localRepository.Object,
new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object) { CallBase = true };
var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
packageManagerFactory.Setup(m => m.CreatePackageManager(activeRepository, false)).Returns(packageManager.Object);
packageManager.Setup(m => m.GetProjectManager(project)).Returns(projectManager).Verifiable();
var packageUninstaller = new VsPackageUninstaller(packageManagerFactory.Object, activeRepository, scriptExecutor.Object);
// Act and Assert
localRepository.Object.AddPackage(packageA);
localRepository.Object.AddPackage(packageB);
ExceptionAssert.Throws<InvalidOperationException>(() => packageUninstaller.UninstallPackage(project, "B", removeDependencies: true),
"Unable to uninstall 'B 1.0' because 'A 1.0' depends on it.");
}
示例15: UpdatePackageNewVersionOfPackageHasLessDependencies
public void UpdatePackageNewVersionOfPackageHasLessDependencies()
{
// Arrange
var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
var projectRepository = new MockProjectPackageRepository(localRepository.Object);
var sourceRepository = new MockPackageRepository();
var fileSystem = new MockFileSystem();
var projectSystem = new MockProjectSystem();
var pathResolver = new DefaultPackagePathResolver(fileSystem);
// A1 -> B1
// A2
var A10 = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "A1.dll" }, dependencies: new[] { new PackageDependency("B", VersionUtility.ParseVersionSpec("1.0")) });
var A20 = PackageUtility.CreatePackage("A", "2.0", assemblyReferences: new[] { "A2.dll" });
var B10 = PackageUtility.CreatePackage("B", "1.0", assemblyReferences: new[] { "B1.dll" });
sourceRepository.AddPackage(A10);
sourceRepository.AddPackage(A20);
sourceRepository.AddPackage(B10);
localRepository.Object.AddPackage(A10);
localRepository.Object.AddPackage(A20);
localRepository.Object.AddPackage(B10);
var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository.Object, new Mock<IRecentPackageRepository>().Object);
var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);
projectManager.AddPackageReference("A", new Version("1.0"));
// Act
packageManager.UpdatePackage(projectManager, "A", version: null, updateDependencies: true, logger: NullLogger.Instance);
// Assert
Assert.IsFalse(packageManager.LocalRepository.Exists(A10));
Assert.IsFalse(projectSystem.ReferenceExists("A1.dll"));
Assert.IsFalse(packageManager.LocalRepository.Exists(B10));
Assert.IsFalse(projectSystem.ReferenceExists("B1.dll"));
Assert.IsTrue(packageManager.LocalRepository.Exists(A20));
Assert.IsTrue(projectSystem.ReferenceExists("A2.dll"));
}