public void ResolveDependenciesForInstallPackageResolvesDependencyUsingDependencyProvider() { // Arrange IPackage packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new List<PackageDependency> { new PackageDependency("B") }); IPackage packageB = PackageUtility.CreatePackage("B"); var repository = new Mock<PackageRepositoryBase>(); repository.Setup(c => c.GetPackages()).Returns(new[] { packageA }.AsQueryable()); var dependencyProvider = repository.As<IDependencyResolver>(); dependencyProvider.Setup(c => c.ResolveDependency(It.Is<PackageDependency>(p => p.Id == "B"), It.IsAny<IPackageConstraintProvider>(), false, true, DependencyVersion.Lowest)) .Returns(packageB).Verifiable(); var localRepository = new MockPackageRepository(); IPackageOperationResolver resolver = new InstallWalker(localRepository, repository.Object, NullLogger.Instance, ignoreDependencies: false, allowPrereleaseVersions: false); // Act var operations = resolver.ResolveOperations(packageA).ToList(); // Assert Assert.Equal(2, operations.Count); Assert.Equal(PackageAction.Install, operations.First().Action); Assert.Equal(packageB, operations.First().Package); Assert.Equal(PackageAction.Install, operations.Last().Action); Assert.Equal(packageA, operations.Last().Package); dependencyProvider.Verify(); }
public void AddPackageReferenceAddingPackageWithDuplicateReferenceOverwritesReference() { // Arrange var projectSystem = new MockProjectSystem(); var localRepository = new MockPackageRepository(); var mockRepository = new MockPackageRepository(); var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository); var packageA = PackageUtility.CreatePackage("A", "1.0", assemblyReferences: new[] { "reference.dll" }); var packageB = PackageUtility.CreatePackage("B", "1.0", assemblyReferences: new[] { "reference.dll" }); mockRepository.AddPackage(packageA); mockRepository.AddPackage(packageB); // Act projectManager.AddPackageReference("A"); projectManager.AddPackageReference("B"); // Assert Assert.AreEqual(0, projectSystem.Paths.Count); Assert.AreEqual(1, projectSystem.References.Count); Assert.IsTrue(projectSystem.References.ContainsKey(@"reference.dll")); Assert.IsTrue(projectSystem.References.ContainsValue(@"B.1.0\reference.dll")); Assert.IsTrue(localRepository.Exists("A")); Assert.IsTrue(localRepository.Exists("B")); }
public void IsReferencedReturnsTrueIfAnyOtherRepositoryReferencesAPackage() { // Arrange var fileSystem = new Mock<MockFileSystem>() { CallBase = true }; fileSystem.Setup(m => m.FileExists(@"A\packages.config")).Returns(true); fileSystem.Setup(m => m.FileExists(@"..\..\packages.config")).Returns(true); fileSystem.Object.AddFile("repositories.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <repositories> <repository path=""A\packages.config"" /> <repository path=""..\..\packages.config"" /> <repository /> </repositories>"); fileSystem.Setup(m => m.Root).Returns(@"c:\foo\bar\baz"); var repository = new Mock<MockSharedRepository>(new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object) { CallBase = true }; var r1 = new MockPackageRepository { PackageUtility.CreatePackage("A") }; var r2 = new MockPackageRepository { PackageUtility.CreatePackage("B") }; repository.Setup(m => m.Create(@"A\packages.config")).Returns(r1); repository.Setup(m => m.Create(@"..\..\packages.config")).Returns(r2); // Act && Assert Assert.IsTrue(repository.Object.IsReferenced("A", new Version("1.0"))); Assert.IsTrue(repository.Object.IsReferenced("B", new Version("1.0"))); Assert.IsFalse(repository.Object.IsReferenced("C", new Version("1.0"))); }
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)); }
public void XdtTransformOnXmlNodeWithAttributes() { // Arrange var mockProjectSystem = new MockProjectSystem(); var mockRepository = new MockPackageRepository(); mockProjectSystem.AddFile("test.xml", @"<a attrib=""b""/>".AsStream()); var projectManager = new ProjectManager(mockRepository, new DefaultPackagePathResolver(new MockProjectSystem()), mockProjectSystem, new MockPackageRepository()); var package = new Mock<IPackage>(); package.Setup(m => m.Id).Returns("A"); package.Setup(m => m.Version).Returns(new SemanticVersion("1.0")); package.Setup(m => m.Listed).Returns(true); var file = new Mock<IPackageFile>(); file.Setup(m => m.Path).Returns(@"content\test.xml.install.xdt"); file.Setup(m => m.EffectivePath).Returns("test.xml.install.xdt"); file.Setup(m => m.GetStream()).Returns(() => @"<a xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform""><test xdt:Transform=""InsertIfMissing""/></a>".AsStream()); package.Setup(m => m.GetFiles()).Returns(new[] { file.Object }); mockRepository.AddPackage(package.Object); // Act projectManager.AddPackageReference("A"); // Assert Assert.True(mockProjectSystem.FileExists("test.xml")); var actual = mockProjectSystem.OpenFile("test.xml").ReadToEnd(); Assert.Equal("<a attrib=\"b\">\t<test/></a>", actual); }
public void GetPackagesReturnPrereleasePackages() { // Arrange MockPackageRepository repository = new MockPackageRepository(); int numberOfPackages = 3; IPackage[] packages = new IPackage[numberOfPackages]; for (int i = 0; i < numberOfPackages; i++) { packages[i] = PackageUtility.CreatePackage("A" + i, "1.0-alpha"); repository.AddPackage(packages[i]); } SimpleTreeNode node = CreateSimpleTreeNode(repository); // Act var producedPackages = node.GetPackages(allowPrereleaseVersions: true).ToList(); // Assert Assert.Equal(packages.Length, producedPackages.Count); for (int i = 0; i < numberOfPackages; i++) { Assert.Same(packages[i], producedPackages[i]); } }
public void GetUpdatesReturnAllPackageVersionsWhenFlagIsSpecified() { // Arrange var sourceRepository = new MockPackageRepository(); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0", new string[] { "hello" })); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "2.0", new string[] { "hello" })); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "3.0", new string[] { "hello" })); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "3.0-alpha", new string[] { "hello" })); var packages = new IPackage[] { PackageUtility.CreatePackage("A", "1.5") }; // Act var foundPackages = PackageRepositoryExtensions.GetUpdates(sourceRepository, packages, includePrerelease: true, includeAllVersions: true).ToList(); // Assert Assert.Equal(3, foundPackages.Count); Assert.Equal("A", foundPackages[0].Id); Assert.Equal(new SemanticVersion("2.0"), foundPackages[0].Version); Assert.Equal("A", foundPackages[1].Id); Assert.Equal(new SemanticVersion("3.0"), foundPackages[1].Version); Assert.Equal("A", foundPackages[2].Id); Assert.Equal(new SemanticVersion("3.0-alpha"), foundPackages[2].Version); }
public void GetRemotePackagesTest() { // Arrange var siteRoot = "x:\\"; var localRepository = new MockPackageRepository(); var sourceRepository = new MockServiceBasePackageRepository(); var projectSystem = new WebProjectSystem(siteRoot); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(sourceRepository, pathResolver, projectSystem, localRepository); var net40 = new FrameworkName(".NETFramework", new Version("4.0.0.0")); var net45 = new FrameworkName(".NETFramework", new Version("4.5.0.0")); IPackage packageA = PackageFactory.Create("A", new Version("1.0"), null, new FrameworkName[]{ net40 }); IPackage packageB = PackageFactory.Create("B", new Version("1.0"), null, new FrameworkName[]{ net45 }); IPackage packageC = PackageFactory.Create("C", new Version("1.0")); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageB); sourceRepository.AddPackage(packageC); // NOTE THAT target framework used by WebProjectManager would be .NETFramework, Version=4.0.0.0 var webProjectManager = new WebProjectManager(projectManager, siteRoot); // Act var packages = webProjectManager.GetRemotePackages(null, false).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal(packageA, packages[0]); Assert.Equal(packageC, packages[1]); }
public static MockPackageRepository CreateMockRepository() { var mockRepo = new MockPackageRepository(); mockRepo.AddPackage(PackageUtility.CreatePackage(PackageInRepository, isLatest: true, assemblyReferences: new List<string> { AssemblyFilenameInPackageRepository, "Assembly12.dll" }, dependencies: new List<PackageDependency>())); mockRepo.AddPackage(PackageUtility.CreatePackage("Test2", isLatest: true, assemblyReferences: new List<string> { AnotherAssemblyInPackageRepository, "Assembly22.dll" }, dependencies: new List<PackageDependency> { new PackageDependency(PackageInRepository) })); return mockRepo; }
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); }
public void EnsurePackageDownloadsThePackageIfItIsNotCachedInMemoryOnInMachineCache() { // Arrange var zipPackage = PackageUtility.CreatePackage("A", "1.2"); var uri = new Uri("http://nuget.org"); var packageDownloader = new Mock<PackageDownloader>(); packageDownloader.Setup(d => d.DownloadPackage(uri, It.IsAny<IPackageMetadata>())) .Returns(zipPackage) .Verifiable(); var hashProvider = new Mock<IHashProvider>(MockBehavior.Strict); var mockRepository = new MockPackageRepository(); var context = new Mock<IDataServiceContext>(); context.Setup(c => c.GetReadStreamUri(It.IsAny<object>())).Returns(uri).Verifiable(); var servicePackage = new DataServicePackage { Id = "A", Version = "1.2", PackageHash = "NEWHASH", Downloader = packageDownloader.Object, HashProvider = hashProvider.Object, Context = context.Object }; // Act servicePackage.EnsurePackage(mockRepository); // Assert context.Verify(); packageDownloader.Verify(); Assert.True(mockRepository.Exists(zipPackage)); }
public void AddPackageReferenceWhenNewVersionOfPackageAlreadyReferencedThrows() { // Arrange var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository()); IPackage packageA10 = PackageUtility.CreatePackage("A", "1.0", dependencies: new List<PackageDependency> { new PackageDependency("B") }, content: new[] { "foo" }); IPackage packageA20 = PackageUtility.CreatePackage("A", "2.0", dependencies: new List<PackageDependency> { new PackageDependency("B") }, content: new[] { "foo" }); IPackage packageB10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "foo" }); projectManager.LocalRepository.AddPackage(packageA20); projectManager.LocalRepository.AddPackage(packageB10); sourceRepository.AddPackage(packageA20); sourceRepository.AddPackage(packageB10); sourceRepository.AddPackage(packageA10); sourceRepository.AddPackage(packageA20); sourceRepository.AddPackage(packageB10); // Act & Assert ExceptionAssert.Throws<InvalidOperationException>(() => projectManager.AddPackageReference("A", SemanticVersion.Parse("1.0")), @"Already referencing a newer version of 'A'."); }
public void GetPackagesWithPagingTakesLowestNElements() { // Arrange var r1 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("B"), PackageUtility.CreatePackage("E"), }; var r2 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("C"), PackageUtility.CreatePackage("D"), PackageUtility.CreatePackage("F"), }; var repository = new AggregateRepository(new[] { r1, r2 }); // Act var packages = repository.GetPackages().OrderBy(p => p.Id).Take(5).ToList(); // Assert Assert.Equal(5, packages.Count); Assert.Equal("A", packages[0].Id); Assert.Equal("B", packages[1].Id); Assert.Equal("C", packages[2].Id); Assert.Equal("D", packages[3].Id); Assert.Equal("E", packages[4].Id); }
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")); }
public void AfterPackageWalkMetaPackageIsClassifiedTheSameAsDependencies() { // Arrange var mockRepository = new MockPackageRepository(); var walker = new TestWalker(mockRepository); IPackage metaPackage = PackageUtility.CreatePackage("A", "1.0", dependencies: new List<PackageDependency> { new PackageDependency("B"), new PackageDependency("C") }); IPackage projectPackageA = PackageUtility.CreatePackage("B", "1.0", content: new[] { "contentB" }); IPackage projectPackageB = PackageUtility.CreatePackage("C", "1.0", content: new[] { "contentC" }); mockRepository.AddPackage(projectPackageA); mockRepository.AddPackage(projectPackageB); Assert.AreEqual(PackageTargets.None, walker.GetPackageInfo(metaPackage).Target); // Act walker.Walk(metaPackage); // Assert Assert.AreEqual(PackageTargets.Project, walker.GetPackageInfo(metaPackage).Target); }
public void CanExecuteReturnsCorrectResult() { // Local repository contains Package A and Package B // We test the CanExecute() method on Package A and Package C // Arrange var repository = new MockPackageRepository(); var packageA = PackageUtility.CreatePackage("A", "1.0"); repository.AddPackage(packageA); var packageB = PackageUtility.CreatePackage("B", "2.0"); repository.AddPackage(packageB); var packageC = PackageUtility.CreatePackage("C", "2.0"); var projectManager = new Mock<IProjectManager>(); projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => repository.Exists(p)); var provider = CreateInstalledProvider(null, projectManager.Object); var extensionA = new PackageItem(provider, packageA, null); var extensionC = new PackageItem(provider, packageC, null); // Act bool canExecuteA = provider.CanExecute(extensionA); bool canExecuteC = provider.CanExecute(extensionC); // Assert Assert.IsTrue(canExecuteA); Assert.IsFalse(canExecuteC); }
public void GetPackagesRemoveDuplicates() { // Arrange var r1 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("B"), PackageUtility.CreatePackage("C"), PackageUtility.CreatePackage("D"), }; var r2 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("D"), PackageUtility.CreatePackage("E"), PackageUtility.CreatePackage("F"), }; var repository = new AggregateRepository(new[] { r1, r2 }); // Act var packages = repository.GetPackages().OrderBy(p => p.Id).ToList(); // Assert Assert.Equal(6, packages.Count); Assert.Equal("A", packages[0].Id); Assert.Equal("B", packages[1].Id); Assert.Equal("C", packages[2].Id); Assert.Equal("D", packages[3].Id); Assert.Equal("E", packages[4].Id); Assert.Equal("F", packages[5].Id); }
public void ReverseDependencyWalkerUsersVersionAndIdToDetermineVisited() { // Arrange // A 1.0 -> B 1.0 IPackage packageA1 = PackageUtility.CreatePackage("A", "1.0", dependencies: new List<PackageDependency> { PackageDependency.CreateDependency("B", "[1.0]") }); // A 2.0 -> B 2.0 IPackage packageA2 = PackageUtility.CreatePackage("A", "2.0", dependencies: new List<PackageDependency> { PackageDependency.CreateDependency("B", "[2.0]") }); IPackage packageB1 = PackageUtility.CreatePackage("B", "1.0"); IPackage packageB2 = PackageUtility.CreatePackage("B", "2.0"); var mockRepository = new MockPackageRepository(); mockRepository.AddPackage(packageA1); mockRepository.AddPackage(packageA2); mockRepository.AddPackage(packageB1); mockRepository.AddPackage(packageB2); // Act IDependentsResolver lookup = new DependentsWalker(mockRepository); // Assert Assert.Equal(0, lookup.GetDependents(packageA1).Count()); Assert.Equal(0, lookup.GetDependents(packageA2).Count()); Assert.Equal(1, lookup.GetDependents(packageB1).Count()); Assert.Equal(1, lookup.GetDependents(packageB2).Count()); }
public void ExecuteMethodCallsUninstallPackageMethodOnPackageManager() { // Local repository contains Package A and Package B // Arrange var repository = new MockPackageRepository(); var packageA = PackageUtility.CreatePackage("A", "1.0"); repository.AddPackage(packageA); var projectManager = new Mock<IProjectManager>(); projectManager.Setup(p => p.LocalRepository).Returns(repository); var packageManager = new Mock<IVsPackageManager>(); var provider = CreateInstalledProvider(packageManager.Object, projectManager.Object); var extensionA = new PackageItem(provider, packageA, null); var mockLicenseWindowOpener = new Mock<ILicenseWindowOpener>(); // Act provider.Execute(extensionA); // Assert packageManager.Verify(p => p.UninstallPackage(projectManager.Object, "A", null, false, false, provider), Times.Once()); mockLicenseWindowOpener.Verify(p => p.ShowLicenseWindow(It.IsAny<IEnumerable<IPackage>>()), Times.Never()); }
public void GetPackagesReturnsUpdatesWhenThereAreMultipleVersionsOfTheSamePackageId() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockServiceBasePackageRepository(); UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false); localRepository.AddPackage(PackageUtility.CreatePackage("A", "9.0-rtm")); localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0")); localRepository.AddPackage(PackageUtility.CreatePackage("A", "9.0")); localRepository.AddPackage(PackageUtility.CreatePackage("A", "10.0")); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "9.5")); sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "4.0-beta")); sourceRepository.AddPackage(PackageUtility.CreatePackage("C", "1.2.3.4-alpha")); // Act var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList(); // Assert Assert.Equal(2, packages.Count); AssertPackage(packages[0], "A", "9.5"); AssertPackage(packages[1], "B", "4.0-beta"); }
public void AddPackageReferenceAppliesPackageReferencesCorrectly2() { // Arrange var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=4.5")); var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository()); IPackage packageA = PackageUtility.CreatePackage( "A", "1.0", assemblyReferences: new[] { "lib\\net35\\a.dll", "lib\\net35\\b.dll" }); sourceRepository.AddPackage(packageA); Mock<IPackage> mockPackageA = Mock.Get<IPackage>(packageA); mockPackageA.Setup(m => m.PackageAssemblyReferences).Returns( new PackageReferenceSet[] { new PackageReferenceSet(VersionUtility.ParseFrameworkName("net40"), new [] { "a.dll" }), new PackageReferenceSet(VersionUtility.ParseFrameworkName("net45"), new [] { "b.dll" }) } ); // Act projectManager.AddPackageReference("A"); // Assert Assert.True(projectManager.LocalRepository.Exists("A")); Assert.False(projectSystem.ReferenceExists("a.dll")); Assert.True(projectSystem.ReferenceExists("b.dll")); }
public void InstallPackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified() { // Arrange var packageA28 = PackageUtility.CreatePackage("A", "2.8"); var packageA31 = PackageUtility.CreatePackage("A", "3.1"); var packageRepository = new MockPackageRepository { packageA28, packageA31 }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new InstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true); cmdlet.Id = "A"; cmdlet.Version = new SemanticVersion("2.8"); cmdlet.Execute(); // Assert: version 2.8 is installed. var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(1, installedPackages.Count); Assert.Equal(packageA28, installedPackages[0], PackageEqualityComparer.IdAndVersion); }
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)); }
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"))); }
public void UninstallPackageCmdletWhenIdAndVersionAreSpecified() { // Arrange var packageA = PackageUtility.CreatePackage("A", "1.0"); var packageRepository = new MockPackageRepository { packageA }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA }, installedPackages, PackageEqualityComparer.IdAndVersion); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.Version = new SemanticVersion("1.1"); // Act and Assert ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.GetResults(), "Unable to find package 'A'."); }
public void AddPackageReferenceLoadPackagesProjectNameConfigIfPresent() { // Arrange var sourceRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem( new FrameworkName(".NETFramework, Version=4.5")); projectSystem.ProjectName = "CoolProject"; projectSystem.AddFile("packages.CoolProject.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""luan"" version=""3.0"" /> </packages>"); var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository()); IPackage packageA = PackageUtility.CreatePackage( "A", "1.0", assemblyReferences: new[] { "lib\\a.dll"}); sourceRepository.AddPackage(packageA); // Act projectManager.AddPackageReference("A"); // Assert Assert.True(projectManager.LocalRepository.Exists("A")); Assert.True(projectManager.Project.FileExists("packages.CoolProject.config")); Assert.False(projectManager.Project.FileExists("packages.config")); }
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()); }
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)); }
public void UninstallPackageDoesNotRemoveDependenciesIfFlagIsFalse() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); var project = packageManager.SolutionManager.GetProject("default"); var packageManagerFactory = new Mock<IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), false)).Returns(packageManager); var scriptExecutor = new Mock<IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"c:\solution\A.1.0", "uninstall.ps1", packageA, project, new FrameworkName(".NETFramework,Version=v4.0.0.0"), NullLogger.Instance)).Returns(true).Verifiable(); var packageUninstaller = new VsPackageUninstaller( packageManagerFactory.Object, packageManager.LocalRepository, scriptExecutor.Object); // Act packageUninstaller.UninstallPackage(project, "A", removeDependencies: false); // Assert: packageA is uninstalled, while packageB is not scriptExecutor.Verify(); installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); }
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)); }
public void PackageRestoreRepositoryFindPackageReturnsNull() { // Arrange var mockRepositoryFactory = new Mock <IPackageRepositoryFactory>(); var mockSourceProvider = new Mock <IVsPackageSourceProvider>(); var mockRepository1 = new MockPackageRepository(); var mockRepository2 = new MockPackageRepository(); var mockRepository3 = new MockPackageRepository(); var source1 = new PackageSource("Source1"); var source2 = new PackageSource("Source2"); var source3 = new PackageSource("Source3"); mockRepository1.AddPackage(PackageUtility.CreatePackage("A", "1.0")); mockRepository2.AddPackage(PackageUtility.CreatePackage("B", "2.0")); mockRepository3.AddPackage(PackageUtility.CreatePackage("C", "3.0")); mockSourceProvider.Setup(m => m.LoadPackageSources()).Returns(new[] { source1, source2, source3 }); mockRepositoryFactory.Setup(m => m.CreateRepository(It.IsAny <string>())).Returns <string>(s => { switch (s) { case "Source1": return(mockRepository1); case "Source2": return(mockRepository2); case "Source3": return(mockRepository3); default: return(null); } }); // Act var packageRestoreRepository = mockSourceProvider.Object.CreatePriorityPackageRepository(mockRepositoryFactory.Object, mockRepository1); var package = packageRestoreRepository.FindPackage("D", new SemanticVersion("1.0")); Assert.Null(package); }
public void InstallPackageCmdletCreatesFallbackRepository() { // Arrange var productUpdateService = new Mock <IProductUpdateService>(); IPackageRepository repoA = new MockPackageRepository(), repoB = new MockPackageRepository(); var package = NuGet.Test.PackageUtility.CreatePackage("P1", dependencies: new[] { new PackageDependency("P2") }); repoA.AddPackage(package); repoB.AddPackage(NuGet.Test.PackageUtility.CreatePackage("P2")); var sharedRepo = new Mock <ISharedPackageRepository>(); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository("A")).Returns(repoA); repositoryFactory.Setup(c => c.CreateRepository("B")).Returns(repoB); var sourceProvider = GetPackageSourceProvider(new PackageSource("A"), new PackageSource("B")); var fileSystemProvider = new Mock <IFileSystemProvider>(); fileSystemProvider.Setup(c => c.GetFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); var repositorySettings = new Mock <IRepositorySettings>(); repositorySettings.Setup(c => c.RepositoryPath).Returns(String.Empty); var solutionManager = new Mock <ISolutionManager>(); var packageManagerFactory = new Mock <VsPackageManagerFactory>(solutionManager.Object, repositoryFactory.Object, sourceProvider, fileSystemProvider.Object, repositorySettings.Object, new Mock <VsPackageInstallerEvents>().Object); packageManagerFactory.Setup(f => f.GetConfigSettingsFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, productUpdateService.Object, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "P1"; cmdlet.Source = "A"; // Act cmdlet.Execute(); // Assert // If we've come this far, P1 is successfully installed. Assert.True(true); }
public void ReferenceToPackageIdNotOnFeedStays() { var fileSystem = new MockFileSystem(@"d:\"); fileSystem.AddFile(@"d:\test\packages.config", "<packages>" + "<package id=\"Missing\" version=\"1.0.0.0\" />" + "</packages>"); var repository = new MockPackageRepository("http://test.com"); var command = new FixReferences(fileSystem, repository, new Console()) { Directory = @"d:\test" }; command.Execute(); var packageReferences = new PackageReferenceFile(fileSystem, @"d:\test\packages.config").GetPackageReferences().ToList(); Assert.AreEqual("1.0.0.0", packageReferences.First(p => p.Id == "Missing").Version.Version.ToString()); }
public void EmptySearchTerms_ReturnsAllRemotePackages() { var packageA = new MockPackage { Id = "A" }; var packageB = new MockPackage { Id = "B" }; var mockRepo = new MockPackageRepository(); mockRepo.AddPackage(packageA); mockRepo.AddPackage(packageB); Dependencies.NuGetProjectManagerFactory = MockGenerator.CreateProjectManagerFactory(MockGenerator.CreateMockProjectManager(mockRepo, new MockPackageRepository()).Object); // act var project = new WebNuGetProject(new string[] { "http://dummyFeed" }, @"C:\DummyPath", null, MockGenerator.CreateWebProjectSystemFactory()); var results = project.GetRemotePackages(""); Assert.Equal(new IPackage[] { packageA, packageB }, results); }
public void MirrorCommandLogsWarningsForFailingRepositoriesIfNoSourcesAreSpecified() { // Arrange MessageLevel?level = null; string message = null; var repositoryA = new MockPackageRepository(); repositoryA.AddPackage(PackageUtility.CreatePackage("Foo")); var repositoryB = new Mock <IPackageRepository>(); repositoryB.Setup(c => c.GetPackages()).Returns(GetPackagesWithException().AsQueryable()); 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 sourceProvider = GetSourceProvider(new[] { new PackageSource("A"), new PackageSource("B") }); var factory = new Mock <IPackageRepositoryFactory>(); factory.Setup(c => c.CreateRepository("A")).Returns(repositoryA); factory.Setup(c => c.CreateRepository("B")).Returns(repositoryB.Object); var mirrorCommand = new TestMirrorCommand("Foo", factory.Object, sourceProvider) { Console = console.Object }; // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal("Boom", message); Assert.Equal(MessageLevel.Warning, level.Value); }
public void InstallPackgeWithNullProjectManagerOnlyInstallsIntoPackageManager() { // 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, projectSystem, localRepository, new Mock <IRecentPackageRepository>().Object); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }); sourceRepository.AddPackage(package); // Act packageManager.InstallPackage((IProjectManager)null, "foo", new Version("1.0"), ignoreDependencies: false, logger: NullLogger.Instance); // Assert Assert.IsTrue(packageManager.LocalRepository.Exists(package)); }
public void CreateFallbackRepositoryUsesResolvedSourceNameWhenEnsuringRepositoryIsNotAlreadyListedInAggregate() { // Arrange var mockRepositoryFactory = new Mock <IPackageRepositoryFactory>(); var mockSourceProvider = new Mock <IVsPackageSourceProvider>(); var mockRepository1 = new MockPackageRepository(); var mockRepository2 = new MockPackageRepository("http://redirected"); var aggregateRepo = new AggregateRepository(new[] { mockRepository1, mockRepository2 }); var source1 = new PackageSource("Source1"); var source2 = new PackageSource("Source2"); var aggregateSource = AggregatePackageSource.Instance; mockRepository1.AddPackage(PackageUtility.CreatePackage("A", "1.0")); mockRepository2.AddPackage(PackageUtility.CreatePackage("A", "1.2")); mockSourceProvider.Setup(m => m.LoadPackageSources()).Returns(new[] { source1, source2, aggregateSource }); mockRepositoryFactory.Setup(m => m.CreateRepository(It.IsAny <string>())).Returns <string>(s => { switch (s) { case "Source1": return(mockRepository1); case "Source2": return(mockRepository2); default: return(null); } }); var packageManagerFactory = new VsPackageManagerFactory(new Mock <ISolutionManager>().Object, mockRepositoryFactory.Object, mockSourceProvider.Object, new Mock <IFileSystemProvider>().Object, new Mock <IRepositorySettings>().Object, null, new Mock <VsPackageInstallerEvents>().Object); // Act FallbackRepository repository = (FallbackRepository)packageManagerFactory.CreateFallbackRepository(mockRepository2); // Assert var dependencyResolver = (AggregateRepository)repository.DependencyResolver; Assert.Equal(2, dependencyResolver.Repositories.Count()); }
public void UninstallProjectLevelPackageThrowsIfPackageIsReferenced() { // Arrange var localRepository = new Mock <MockPackageRepository>() { CallBase = true }.As <ISharedPackageRepository>(); localRepository.Setup(m => m.IsReferenced("foo", It.IsAny <Version>())).Returns(true); var sourceRepository = new MockPackageRepository(); var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var package = PackageUtility.CreatePackage("foo", "1.0", new[] { "hello" }); localRepository.Object.AddPackage(package); sourceRepository.AddPackage(package); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, fileSystem, localRepository.Object, new Mock <IRecentPackageRepository>().Object); var projectManager = new ProjectManager(localRepository.Object, pathResolver, new MockProjectSystem(), new MockPackageRepository()); // Act ExceptionAssert.Throws <InvalidOperationException>(() => packageManager.UninstallPackage(projectManager, "foo", version: null, forceRemove: false, removeDependencies: false, logger: NullLogger.Instance), @"Unable to find package 'foo 1.0' in 'C:\MockFileSystem\'."); }
public static void GetPackagesToBeReinstalledReturnsEmptyListForPackageTargetingMultipleFrameworks() { // Create a packageA which has as assembly reference in net 20 and net30. Create a package reference corresponding to this package with the project target framework as 'net40' // Now, Try and check if the created packagereference on a project with targetframework of net35 will require reinstallation. IT SHOULD REQUIRE REINSTALLATION // Arrange IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0", null, assemblyReferences: new[] { @"lib\net20\bar.dll", @"lib\net30\foo.dll" }); MockPackageRepository localRepository = new MockPackageRepository(); localRepository.AddPackage(packageA); List<PackageReference> packageReferences = new List<PackageReference>(); packageReferences.Add(new PackageReference("A", new SemanticVersion("1.0.0"), null, new FrameworkName(".NETFramework, Version=4.0"), isDevelopmentDependency: false)); FrameworkName projectFramework = new FrameworkName(".NETFramework, Version=3.5"); // Act var packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(projectFramework, packageReferences, localRepository); // Assert Assert.True(packagesToBeReinstalled.IsEmpty()); }
public void InstallPackageSetOperationToInstall2() { // 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); // Act packageManager.InstallPackage(projectManager, "foo", new SemanticVersion("1.0"), ignoreDependencies: false, allowPrereleaseVersions: false, skipAssemblyReferences: false, logger: NullLogger.Instance); // Assert Assert.Equal("Install", sourceRepository.LastOperation); Assert.Equal("foo", sourceRepository.LastMainPackageId); Assert.Equal("1.0", sourceRepository.LastMainPackageVersion); }
public void InstallPackageThrowsExceptionPackageIsNotInstalled() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var projectSystem = new Mock <IProjectSystem>(); projectSystem.Setup(m => m.AddFile(@"A.1.0\content\file", It.IsAny <Stream>())).Throws <UnauthorizedAccessException>(); projectSystem.Setup(m => m.Root).Returns("FakeRoot"); PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, localRepository); IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "file" }); sourceRepository.AddPackage(packageA); // Act ExceptionAssert.Throws <UnauthorizedAccessException>(() => packageManager.InstallPackage("A")); // Assert Assert.False(packageManager.LocalRepository.Exists(packageA)); }
public void UpdatePackageCmdletSpecifiesReinstallOperationDuringReinstall() { // Arrange var mockPackageRepository = new MockPackageRepository(); var projectManager = new Mock <IProjectManager>(); projectManager.Setup(p => p.LocalRepository).Returns(new MockPackageRepository()); var vsPackageManager = new Mock <IVsPackageManager>(); vsPackageManager.Setup(v => v.SourceRepository).Returns(mockPackageRepository); vsPackageManager.Setup(v => v.GetProjectManager(It.IsAny <Project>())).Returns(projectManager.Object); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager.Object); var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource")); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(c => c.CreateRepository(It.Is <string>(s => s == "somesource"))).Returns(mockPackageRepository); var cmdlet = new UpdatePackageCommand( TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "my-id"; cmdlet.Reinstall = true; cmdlet.ProjectName = "foo"; // Act cmdlet.Execute(); // Assert Assert.Equal(RepositoryOperationNames.Reinstall, mockPackageRepository.LastOperation); }
public void InstallCommandDoesNotPromptForConsentIfRequireConsentIsNotSet() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock <IPackageManager>(MockBehavior.Strict); var package = PackageUtility.CreatePackage("Abc"); var repository = new MockPackageRepository { package }; packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); packageManager.Setup(p => p.InstallPackage(package, true, true)).Verifiable(); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of <IPackageSourceProvider>(); var console = new MockConsole(); var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; // Act installCommand.Execute(); // Assert packageManager.Verify(); }
public void CreateExtensionAddsOldVersionProperty(string oldVersion, string newVersion) { // Local repository contains Package A 1.0 and Package B // Source repository contains Package A 2.0 and Package C var packageA1 = PackageUtility.CreatePackage("A", oldVersion); var packageA2 = PackageUtility.CreatePackage("A", newVersion); var packageB = PackageUtility.CreatePackage("B", "2.0"); var packageC = PackageUtility.CreatePackage("C", "3.0"); // Arrange var localRepository = new MockPackageRepository(); localRepository.AddPackage(packageA1); localRepository.AddPackage(packageB); var sourceRepository = new MockPackageRepository(); sourceRepository.AddPackage(packageA2); sourceRepository.AddPackage(packageC); var projectManager = new Mock <IProjectManager>(); projectManager.Setup(p => p.LocalRepository).Returns(localRepository); var packageManager = new Mock <IVsPackageManager>(); packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository); var provider = CreateUpdatesProvider(packageManager.Object, localRepository); // Act var packageItem = (PackageItem)provider.CreateExtension(packageA2); // Assert Assert.NotNull(packageItem); Assert.Equal(oldVersion, packageItem.OldVersion); Assert.Equal(newVersion, packageItem.Version); }
public void GetPackagesRemoveDuplicatesIfTheyAreTheSameVersion() { // Arrange var r1 = new MockPackageRepository() { PackageUtility.CreatePackage("A", "2.0"), }; var r2 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), }; var r3 = new MockPackageRepository() { PackageUtility.CreatePackage("A", "3.0"), }; var r4 = new MockPackageRepository() { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("B"), }; var repository = new AggregateRepository(new[] { r1, r2, r3, r4 }); // Act var packages = repository.GetPackages().OrderBy(p => p.Id).ToList(); // Assert Assert.Equal(4, packages.Count); Assert.Equal("A", packages[0].Id); Assert.Equal(new SemanticVersion("2.0"), packages[0].Version); Assert.Equal("A", packages[1].Id); Assert.Equal(new SemanticVersion("1.0"), packages[1].Version); Assert.Equal("A", packages[2].Id); Assert.Equal(new SemanticVersion("3.0"), packages[2].Version); Assert.Equal("B", packages[3].Id); }
public void GetPackageReturnsUpdatesForPrereleasePackagesWhenFlagIsSpecified() { // Arrange var installedPackages = new[] { PackageUtility.CreatePackage("A"), PackageUtility.CreatePackage("B", "1.1.0-a") , PackageUtility.CreatePackage("C", "1.3.7.5-a") }; var sourceRepository = new MockPackageRepository() { PackageUtility.CreatePackage("A", "1.1"), PackageUtility.CreatePackage("B", "1.1.0"), PackageUtility.CreatePackage("C", "1.3.7.5-b"), PackageUtility.CreatePackage("D") }; var packageManagerFactory = new Mock <IVsPackageManagerFactory>(MockBehavior.Strict); var packageManager = GetPackageManager(installedPackages); packageManagerFactory.Setup(f => f.CreatePackageManager()).Returns(packageManager); var repositoryFactory = new Mock <IPackageRepositoryFactory>(MockBehavior.Strict); repositoryFactory.Setup(r => r.CreateRepository("NuGet Official Source")).Returns(sourceRepository); var cmdlet = BuildCmdlet(repositoryFactory: repositoryFactory.Object, packageManagerFactory: packageManagerFactory.Object); cmdlet.Updates = true; cmdlet.IncludePrerelease = true; cmdlet.Source = "NuGet Official Source"; // Act var packages = cmdlet.GetResults <dynamic>(); // Assert Assert.Equal(3, packages.Count()); AssertPackageResultsEqual(packages.ElementAt(0), new { Id = "A", Version = new SemanticVersion("1.1") }); AssertPackageResultsEqual(packages.ElementAt(1), new { Id = "B", Version = new SemanticVersion("1.1.0") }); AssertPackageResultsEqual(packages.ElementAt(2), new { Id = "C", Version = new SemanticVersion("1.3.7.5-b") }); }
public void GetPackagesDoesNotCacheResultsWhenOnClosedIsCalled(bool resetQueryBeforeRefresh) { // Arrange MockPackageRepository localRepository = new MockPackageRepository(); localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0")); localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0")); MockPackageRepository sourceRepository = new MockPackageRepository(); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5-alpha")); PackagesProviderBase provider = new MockPackagesProvider(); IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object; var node = new UpdatesTreeNode(provider, "Mock", parentTreeNode, localRepository, sourceRepository); // Act 1 var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList(); // Assert 1 Assert.Equal(1, packages.Count); AssertPackage(packages[0], "A", "1.5-alpha"); // Act 2 node.OnClosed(); // now we modify the source repository to test if the GetPackages() return the old results sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0-beta")); packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList(); packages.Sort(PackageComparer.Version); // Assert 2 Assert.Equal(2, packages.Count); AssertPackage(packages[0], "A", "1.5-alpha"); AssertPackage(packages[1], "B", "2.0-beta"); }
public void IsReferencedReturnsTrueIfAnyOtherRepositoryReferencesAPackage() { // Arrange var fileSystem = new Mock <MockFileSystem>() { CallBase = true }; fileSystem.Setup(m => m.FileExists(@"A\packages.config")).Returns(true); fileSystem.Setup(m => m.FileExists(@"..\..\packages.config")).Returns(true); fileSystem.Object.AddFile("repositories.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <repositories> <repository path=""A\packages.config"" /> <repository path=""..\..\packages.config"" /> <repository /> </repositories>"); fileSystem.Setup(m => m.Root).Returns(@"c:\foo\bar\baz"); var repository = new Mock <MockSharedRepository>(new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object) { CallBase = true }; var r1 = new MockPackageRepository { PackageUtility.CreatePackage("A") }; var r2 = new MockPackageRepository { PackageUtility.CreatePackage("B") }; repository.Setup(m => m.Create(@"A\packages.config")).Returns(r1); repository.Setup(m => m.Create(@"..\..\packages.config")).Returns(r2); // Act && Assert Assert.True(repository.Object.IsReferenced("A", new SemanticVersion("1.0"))); Assert.True(repository.Object.IsReferenced("B", new SemanticVersion("1.0"))); Assert.False(repository.Object.IsReferenced("C", new SemanticVersion("1.0"))); }
public void CanExecuteReturnsCorrectResult() { // Arrange var packageA = PackageUtility.CreatePackage("A", "1.0"); var packageB = PackageUtility.CreatePackage("B", "2.0"); var packageC = PackageUtility.CreatePackage("C", "3.0"); var sourceRepository = new MockPackageRepository(); sourceRepository.AddPackage(packageA); sourceRepository.AddPackage(packageC); sourceRepository.AddPackage(packageB); var localRepository = new MockPackageRepository(); localRepository.AddPackage(packageA); var packageManager = new Mock <IVsPackageManager>(); packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository); var provider = CreateOnlineProvider(packageManager.Object, localRepository); var extensionA = new PackageItem(provider, packageA); var extensionB = new PackageItem(provider, packageB); var extensionC = new PackageItem(provider, packageC); // Act bool canExecuteA = provider.CanExecute(extensionA); bool canExecuteB = provider.CanExecute(extensionB); bool canExecuteC = provider.CanExecute(extensionC); // Assert Assert.True(canExecuteC); Assert.True(canExecuteB); Assert.False(canExecuteA); }
public void UninstallPackageCmdletWithRemoveDependencySwitch() { // Arrange var packageA = PackageUtility.CreatePackage( "A", "1.0", dependencies: new[] { new PackageDependency("B") }); var packageB = PackageUtility.CreatePackage("B", "1.0"); var packageRepository = new MockPackageRepository { packageA, packageB }; var packageManager = new MockVsPackageManager2( @"c:\solution", packageRepository); InstallPackage("A", packageManager); var installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(new[] { packageA, packageB }, installedPackages, PackageEqualityComparer.IdAndVersion); // Act var packageManagerFactory = new Mock <IVsPackageManagerFactory>(); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); var cmdlet = new UninstallPackageCommand( packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock <IVsCommonOperations>().Object, new Mock <IDeleteOnRestartManager>().Object); cmdlet.Id = "A"; cmdlet.RemoveDependencies = new SwitchParameter(true); cmdlet.Execute(); // Assert: both packageA & packageB are uninstalled installedPackages = packageManager.LocalRepository.GetPackages().ToList(); Assert.Equal(0, installedPackages.Count); }
public void InstallCommandFromConfigIgnoresDependencies() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" version=""1.0.0"" /> <package id=""Qux"" version=""2.3.56-beta"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock <IPackageManager>(MockBehavior.Strict); var package1 = PackageUtility.CreatePackage("Foo", "1.0.0"); var package2 = PackageUtility.CreatePackage("Qux", "2.3.56-beta"); var repository = new MockPackageRepository { package1, package2 }; packageManager.Setup(p => p.InstallPackage(package1, true, true)).Verifiable(); packageManager.Setup(p => p.InstallPackage(package2, true, true)).Verifiable(); packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of <IPackageSourceProvider>(); // Act var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Execute(); // Assert packageManager.Verify(); }
public void InstallCommandPromptsForConsentIfRequireConsentIsSet() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"X:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Abc"" version=""1.0.0"" /> </packages>"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var packageManager = new Mock <IPackageManager>(MockBehavior.Strict); var repository = new MockPackageRepository { PackageUtility.CreatePackage("Abc") }; packageManager.SetupGet(p => p.PathResolver).Returns(pathResolver); packageManager.SetupGet(p => p.LocalRepository).Returns(new LocalPackageRepository(pathResolver, fileSystem)); packageManager.SetupGet(p => p.FileSystem).Returns(fileSystem); packageManager.SetupGet(p => p.SourceRepository).Returns(repository); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("My Source")).Returns(repository); var packageSourceProvider = Mock.Of <IPackageSourceProvider>(); var console = new MockConsole(); var installCommand = new TestInstallCommand(repositoryFactory.Object, packageSourceProvider, fileSystem, packageManager.Object, allowPackageRestore: false); installCommand.Arguments.Add(@"X:\test\packages.config"); installCommand.Console = console; installCommand.RequireConsent = true; // Act var exception = Assert.Throws <AggregateException>(() => installCommand.Execute()); // Assert Assert.Equal("Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.", exception.InnerException.Message); }
public void CreateFallbackRepositoryDoesNotThrowWhenIteratingOverFailingRepositories() { // Arrange var mockRepositoryFactory = new Mock <IPackageRepositoryFactory>(); var mockSourceProvider = new Mock <IVsPackageSourceProvider>(); var mockRepository1 = new MockPackageRepository(); var mockRepository2 = new MockPackageRepository("http://redirected"); var source1 = new PackageSource("Source1"); var source2 = new PackageSource("Source2"); var source3 = new PackageSource("SourceBad"); var aggregateSource = AggregatePackageSource.Instance; mockSourceProvider.Setup(m => m.LoadPackageSources()).Returns(new[] { source1, source3, source2, aggregateSource }); mockRepositoryFactory.Setup(m => m.CreateRepository(It.IsAny <string>())).Returns <string>(s => { switch (s) { case "Source1": return(mockRepository1); case "Source2": return(mockRepository2); case "SourceBad": throw new InvalidOperationException(); default: return(null); } }); var packageManagerFactory = new VsPackageManagerFactory(new Mock <ISolutionManager>().Object, mockRepositoryFactory.Object, mockSourceProvider.Object, new Mock <IFileSystemProvider>().Object, new Mock <IRepositorySettings>().Object, new Mock <VsPackageInstallerEvents>().Object, mockRepository1, machineWideSettings: null); // Act FallbackRepository repository = (FallbackRepository)packageManagerFactory.CreateFallbackRepository(mockRepository2); // Assert var dependencyResolver = (AggregateRepository)repository.DependencyResolver; Assert.Equal(2, dependencyResolver.Repositories.Count()); }
public void UpdatePackagesSetOperationToUpdate3() { // Arrange var localRepository = new MockSharedPackageRepository(); var sourceRepository = new MockPackageRepository(); var projectRepository = new MockPackageRepository(); var projectSystem = new MockProjectSystem(); var pathResolver = new DefaultPackagePathResolver(projectSystem); var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository); 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("phuong", "1.0", new[] { "hello" }); localRepository.AddPackage(package); projectRepository.AddPackage(package); var package2 = PackageUtility.CreatePackage("phuong", "2.0", new[] { "hello" }); sourceRepository.AddPackage(package2); var packageB = PackageUtility.CreatePackage("time", "1.0", new[] { "hello" }); projectRepository.AddPackage(package); // Act packageManager.UpdatePackage( projectManager, "phuong", version: null, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance); // Assert Assert.Equal("Update", sourceRepository.LastOperation); Assert.Equal("phuong", sourceRepository.LastMainPackageId); Assert.Equal("2.0", sourceRepository.LastMainPackageVersion); }
public void MirrorCommandUsesMirrorOperation() { // Arrange var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") }; var mockFactory = new Mock <IPackageRepositoryFactory>(); mockFactory.Setup(r => r.CreateRepository(It.IsAny <string>())).Returns(mockRepo); var mirrorCommand = new TestMirrorCommand("Foo", mockFactory.Object); // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(RepositoryOperationNames.Mirror, mockRepo.LastOperation); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public static void GetPackagesToBeReinstalledReturnsPackageTargetingSingleFrameworkBasedOnTools() { // Create a packageA which has as content only in net40. Create a package reference corresponding to this package with the project target framework as 'net40' // Now, Try and check if the created packagereference on a project with targetframework of net35 will require reinstallation. IT SHOULD REQUIRE REINSTALLATION // Arrange IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0", null, null, tools: new[] { @"net40\init.ps1" }); MockPackageRepository localRepository = new MockPackageRepository(); localRepository.AddPackage(packageA); List<PackageReference> packageReferences = new List<PackageReference>(); packageReferences.Add(new PackageReference("A", new SemanticVersion("1.0.0"), null, new FrameworkName(".NETFramework, Version=4.0"), isDevelopmentDependency: false)); FrameworkName projectFramework = new FrameworkName(".NETFramework, Version=3.5"); // Act var packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(projectFramework, packageReferences, localRepository); // Assert Assert.Equal(1, packagesToBeReinstalled.Count); Assert.Equal(packagesToBeReinstalled[0].Id, "A"); }
public void GetUpdatesReturnPackageWhenSourcePackageHasNullTargetFrameworkInToolsFolder() { // Arrange var sourceRepository = new MockPackageRepository(); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0", new string[] { "hello" })); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "2.0", new string[] { "hello", "world" }, tools: new string[] { "build\\install.ps1" })); var packages = new IPackage[] { PackageUtility.CreatePackage("A", "1.5") }; // Act var foundPackages = PackageRepositoryExtensions.GetUpdates(sourceRepository, packages, includePrerelease: true, targetFrameworks: new [] { new FrameworkName("NETFramework, Version=4.5") }, includeAllVersions: true).ToList(); // Assert Assert.Equal(1, foundPackages.Count); Assert.Equal("A", foundPackages[0].Id); Assert.Equal(new SemanticVersion("2.0"), foundPackages[0].Version); }
public void GetPackagesReturnsPrereleasePackagesIfIncludePrereleaseIsTrue() { // Arrange MockPackageRepository localRepository = new MockPackageRepository(); MockPackageRepository sourceRepository = new MockPackageRepository(); UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: true); localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0")); localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0")); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5")); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.9-alpha")); sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0")); // Act var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList(); // Assert Assert.Equal(2, packages.Count); AssertPackage(packages[0], "A", "1.9-alpha"); AssertPackage(packages[1], "B", "2.0"); }
public void GetPackagesReturnsCorrectPackages4() { // Arrange MockPackageRepository localRepository = new MockPackageRepository(); MockPackageRepository sourceRepository = new MockPackageRepository(); UpdatesTreeNode node = CreateSimpleTreeNode(localRepository, sourceRepository); localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0")); localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0")); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.5")); sourceRepository.AddPackage(PackageUtility.CreatePackage("A", "1.9")); sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "2.0")); // Act var packages = node.GetPackages().ToList(); // Assert Assert.AreEqual(2, packages.Count); AssertPackage(packages[0], "A", "1.9"); AssertPackage(packages[1], "B", "2.0"); }
public void InstallPackageCmdletDoesNotInstallPrereleasePackageIfFlagIsNotPresent() { // Arrange var sharedRepository = new Mock <ISharedPackageRepository>(MockBehavior.Strict); var packageRepository = new MockPackageRepository { PackageUtility.CreatePackage("A", "1.0.0-a") }; var recentPackageRepository = new Mock <IRecentPackageRepository>(); var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock <IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, recentPackageRepository.Object, null); var packageManagerFactory = new Mock <IVsPackageManagerFactory>(MockBehavior.Strict); packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager); // Act var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, null, null, null, new Mock <IVsCommonOperations>().Object); cmdlet.Id = "A"; // Assert ExceptionAssert.Throws <InvalidOperationException>(() => cmdlet.Execute(), "Unable to find package 'A'."); }