private static IVsPackageManagerFactory GetPackageManagerForMultipleVersions() { var fileSystem = new Mock <IFileSystem>(); var localRepo = new Mock <ISharedPackageRepository>(); var localPackages = new[] { PackageUtility.CreatePackage("jQuery", "1.2"), PackageUtility.CreatePackage("TestPack", "0.1") }; localRepo.Setup(c => c.GetPackages()).Returns(localPackages.AsQueryable()); var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), GetActiveRepository(), fileSystem.Object, localRepo.Object, new Mock <IRecentPackageRepository>().Object); var factory = new Mock <IVsPackageManagerFactory>(); factory.Setup(c => c.CreatePackageManager()).Returns(packageManager); return(factory.Object); }
public void UpdatePackages() { // Arrange Mock <IProjectManager> projectManager; MockPackageRepository localRepository; var updateCmd = ArrangeForUpdatePackages(out projectManager, out localRepository); localRepository.AddPackage(PackageUtility.CreatePackage("Sample")); projectManager.Setup(pm => pm.UpdatePackageReference("Sample", VersionUtility.GetUpgradeVersionSpec(new SemanticVersion("1.0"), PackageUpdateMode.Newest), true, false)); // Act updateCmd.UpdatePackages(localRepository, projectManager.Object); // Assert projectManager.Verify(); }
private static IPackageRepositoryFactory GetFactory() { var repositoryA = new MockPackageRepository { PackageUtility.CreatePackage("Foo"), PackageUtility.CreatePackage("Baz", "0.4"), PackageUtility.CreatePackage("Baz", "0.7") }; var repositoryB = new MockPackageRepository { PackageUtility.CreatePackage("Bar", "0.5"), PackageUtility.CreatePackage("Baz", "0.8.1-alpha") }; var factory = new Mock <IPackageRepositoryFactory>(); factory.Setup(c => c.CreateRepository(It.Is <string>(f => f.Equals("Some source")))).Returns(repositoryA); factory.Setup(c => c.CreateRepository(It.Is <string>(f => f.Equals("Some other source")))).Returns(repositoryB); return(factory.Object); }
private static MockPackageRepository CreateMockRepository() { var mockRepo = new MockPackageRepository(); mockRepo.AddPackage(PackageUtility.CreatePackage("Test1", isLatest: true, assemblyReferences: new List <string> { "Assembly11.dll", "Assembly12.dll" }, dependencies: new List <PackageDependency> { new PackageDependency("Test2") })); mockRepo.AddPackage(PackageUtility.CreatePackage("Test2", isLatest: true, assemblyReferences: new List <string> { "Assembly21.dll", "Assembly22.dll" }, dependencies: new List <PackageDependency> { new PackageDependency("Test1") })); return(mockRepo); }
public static void GetPackagesToBeReinstalledWhenProjectIsNotOfSupportedType() { // Arrange Mock <Project> mockProject = new Mock <Project>(); MockPackageRepository localRepository = new MockPackageRepository(); localRepository.AddPackage(PackageUtility.CreatePackage("A")); mockProject.Setup(p => p.Kind).Returns(Guid.NewGuid().ToString()); // Act var packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(mockProject.Object, localRepository); // Assert Assert.True(packagesToBeReinstalled.IsEmpty()); }
public void CreateExtensionReturnsAPackageItem() { // Arrange var provider = CreateInstalledProvider(); IPackage package = PackageUtility.CreatePackage("A", "1.0"); // Act IVsExtension extension = provider.CreateExtension(package); // Asssert Assert.IsType(typeof(PackageItem), extension); Assert.Equal("A", extension.Name); Assert.Equal("_Uninstall", ((PackageItem)extension).CommandName); Assert.Null(((PackageItem)extension).OldVersion); }
private static IPackageRepository GetRepositoryWithMultiplePackageVersions(string sourceName = "MultiSource") { var repositoryWithMultiplePackageVersions = new Mock <IPackageRepository>(); var packages = new[] { PackageUtility.CreatePackage("jQuery", "1.44"), PackageUtility.CreatePackage("jQuery", "1.51"), PackageUtility.CreatePackage("jQuery", "1.52"), PackageUtility.CreatePackage("NHibernate", "1.1"), PackageUtility.CreatePackage("NHibernate", "1.13"), PackageUtility.CreatePackage("TestPack", "0.7") }; repositoryWithMultiplePackageVersions.Setup(c => c.GetPackages()).Returns(packages.AsQueryable()); return(repositoryWithMultiplePackageVersions.Object); }
public void PackageWithValidCultureFolderHasNoIssue(string culture) { // Arrange var package = PackageUtility.CreatePackage( "A", content: new[] { "one", "two" }, assemblyReferences: new[] { "lib\\" + culture + "\\abc.dll" }, language: culture); var rule = new InvalidFrameworkFolderRule(); // Act IList <PackageIssue> issues = rule.Validate(package).ToList(); // Assert Assert.Equal(0, issues.Count); }
private static IPackageRepositoryFactory CreatePackageRepositoryFactory() { //Default Repository MockPackageRepository defaultPackageRepository = new MockPackageRepository(); var packageA = PackageUtility.CreatePackage("DefaultUrlUsed", "1.0"); defaultPackageRepository.AddPackage(packageA); var packageC = PackageUtility.CreatePackage("SearchPackage", "1.0"); defaultPackageRepository.AddPackage(packageC); var packageD = PackageUtility.CreatePackage("AnotherTerm", "1.0"); defaultPackageRepository.AddPackage(packageD); //Nondefault Repository (Custom URL) MockPackageRepository nondefaultPackageRepository = new MockPackageRepository(); var packageB = PackageUtility.CreatePackage("CustomUrlUsed", "1.0"); nondefaultPackageRepository.AddPackage(packageB); // Repo with multiple versions var multiVersionRepo = new MockPackageRepository(); multiVersionRepo.AddPackage(PackageUtility.CreatePackage("NHibernate", "1.0")); multiVersionRepo.AddPackage(PackageUtility.CreatePackage("NHibernate", "1.1")); multiVersionRepo.AddPackage(PackageUtility.CreatePackage("NHibernate", "1.2")); multiVersionRepo.AddPackage(PackageUtility.CreatePackage("jQuery", "1.44")); multiVersionRepo.AddPackage(PackageUtility.CreatePackage("jQuery", "1.50")); //Setup Factory var packageRepositoryFactory = new Mock <IPackageRepositoryFactory>(); packageRepositoryFactory.Setup(p => p.CreateRepository(It.IsAny <string>())).Returns <string>(s => { switch (s) { case NonDefaultRepoUrl1: return(nondefaultPackageRepository); case NonDefaultRepoUrl2: return(multiVersionRepo); default: return(defaultPackageRepository); } }); //Return the Factory return(packageRepositoryFactory.Object); }
private RecentPackageRepository CreateRecentPackageRepository( IEnumerable <IPackage> packagesList = null, IEnumerable <IPersistencePackageMetadata> settingsMetadata = null, IPackageRepository cacheRepository = null) { if (packagesList == null) { var packageA = PackageUtility.CreatePackage("A", "1.0"); var packageC = PackageUtility.CreatePackage("C", "2.0"); packagesList = new[] { packageA, packageC }; } var mockRepository = new Mock <IPackageRepository>(); mockRepository.Setup(p => p.GetPackages()).Returns(packagesList.AsQueryable()); var mockRepositoryFactory = new Mock <IPackageRepositoryFactory>(); mockRepositoryFactory.Setup(f => f.CreateRepository(It.IsAny <string>())).Returns(mockRepository.Object); var mockSettingsManager = new MockSettingsManager(); if (settingsMetadata == null) { var A = new PersistencePackageMetadata("A", "1.0", new DateTime(2010, 8, 12)); var B = new PersistencePackageMetadata("B", "2.0", new DateTime(2011, 3, 2)); settingsMetadata = new[] { A, B }; } mockSettingsManager.SavePackageMetadata(settingsMetadata); var mockPackageSourceProvider = new MockPackageSourceProvider(); mockPackageSourceProvider.SavePackageSources(new[] { new PackageSource("source") }); if (cacheRepository == null) { cacheRepository = new MockPackageRepository(); } return(new RecentPackageRepository( /* dte */ null, mockRepositoryFactory.Object, mockPackageSourceProvider, mockSettingsManager, cacheRepository)); }
public void CreatePackageMananagerForPackageRestoreUsesPackageRestoreRepositoryWithNonAggregateSecondary() { // Arrange var mockRepositoryFactory = new Mock <IPackageRepositoryFactory>(); var mockSourceProvider = new Mock <IVsPackageSourceProvider>(); var mockFileSystemProvider = new Mock <IFileSystemProvider>(); var mockRepository1 = new MockPackageRepository("Source1"); var mockRepository2 = new MockPackageRepository("Source2"); var source1 = new PackageSource("Source1"); var source2 = new PackageSource("Source2"); mockRepository1.AddPackage(PackageUtility.CreatePackage("A", "1.0")); mockRepository2.AddPackage(PackageUtility.CreatePackage("A", "1.2")); mockSourceProvider.Setup(m => m.LoadPackageSources()).Returns(new[] { source1, source2 }); mockFileSystemProvider.Setup(f => f.GetFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); 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 Mock <VsPackageManagerFactory>(new Mock <ISolutionManager>().Object, mockRepositoryFactory.Object, mockSourceProvider.Object, mockFileSystemProvider.Object, new Mock <IRepositorySettings>().Object, new Mock <VsPackageInstallerEvents>().Object, mockRepository1, null); packageManagerFactory.Setup(f => f.GetConfigSettingsFileSystem(It.IsAny <string>())).Returns(new MockFileSystem()); // Act var packageManager = packageManagerFactory.Object.CreatePackageManagerWithAllPackageSources(mockRepository1); // Assert Assert.IsType(typeof(PriorityPackageRepository), packageManager.SourceRepository); var packageRestoreRepository = (PriorityPackageRepository)packageManager.SourceRepository; Assert.Equal(mockRepository1, packageRestoreRepository.PrimaryRepository); Assert.IsType(typeof(MockPackageRepository), packageRestoreRepository.SecondaryRepository); var secondaryRepository = (MockPackageRepository)packageRestoreRepository.SecondaryRepository; Assert.Equal(mockRepository2, secondaryRepository); }
public void FallbackRepositoryCallsPackagesFindPackageOnThePrimaryRepository() { // Arrange var primaryRepository = new Mock <IPackageRepository>(MockBehavior.Strict); IPackage package = PackageUtility.CreatePackage("A", "1.0"); primaryRepository.As <IPackageLookup>().Setup(p => p.FindPackage("A", new SemanticVersion("1.0"))).Returns(package).Verifiable(); var fallbackRepository = new FallbackRepository(primaryRepository.Object, new MockPackageRepository()); // Act IPackage foundPackage = fallbackRepository.FindPackage("A", new SemanticVersion("1.0")); // Assert primaryRepository.VerifyAll(); Assert.Same(package, foundPackage); }
public void PackageWithLongDescriptionYieldOneIssue() { // Arrange var package = PackageUtility.CreatePackage("A", description: new string('a', 301)); var rule = new MissingSummaryRule(); // Act IList <PackageIssue> issues = rule.Validate(package).ToList(); // Assert Assert.Equal(1, issues.Count); PackageIssueTestHelper.AssertPackageIssue( issues[0], "Consider providing Summary text.", "The Description text is long but the Summary text is empty. This means the Description text will be truncated in the 'Manage NuGet Packages' dialog.", "Provide a brief summary of the package in the Summary field."); }
public void PackageRestoreRepositoryGetPackagesReturnsPrimaryRepositoryPackages() { var mockRepository1 = new MockPackageRepository(); var mockRepository2 = new MockPackageRepository(); mockRepository1.AddPackage(PackageUtility.CreatePackage("A")); mockRepository1.AddPackage(PackageUtility.CreatePackage("B")); mockRepository2.AddPackage(PackageUtility.CreatePackage("C")); var packageRestoreRepository = new PriorityPackageRepository(mockRepository1, mockRepository2); var packages = packageRestoreRepository.GetPackages().ToList(); Assert.Equal(2, packages.Count); Assert.Equal("A", packages[0].Id); Assert.Equal("B", packages[1].Id); }
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(new FrameworkName(".NETCore, Version=4.5")); var projectManager = new ProjectManager(activeRepository, new DefaultPackagePathResolver(new MockFileSystem()), projectSystem, projectRepository); var package = PackageUtility.CreatePackage("A", content: new[] { "file1.txt" }); var scriptExecutor = new Mock <IScriptExecutor>(MockBehavior.Strict); scriptExecutor.Setup(s => s.Execute(@"C:\MockFileSystem\A.1.0", "uninstall.ps1", package, project, new FrameworkName(".NETCore, Version=4.5"), 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, /* multiFrameworkTargeting */ null) { CallBase = true }; projectManager.LocalRepository.AddPackage(package); 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(package); packageUninstaller.UninstallPackage(project, "A", removeDependencies: true); // Assert scriptExecutor.Verify(); Assert.False(localRepository.Object.Contains(package)); }
public void NonAssemblyInsideLibHasIssue() { // Arrange var package = PackageUtility.CreatePackage( "A", assemblyReferences: new[] { "lib\\one.dll", "lib\\abc.xml", "lib\\sl4\\wow.pdb", "lib\\net\\4.0\\kac.txt" }); var rule = new NonAssemblyInsideLibRule(); // Act IList <PackageIssue> issues = rule.Validate(package).ToList(); // Assert Assert.Equal(3, issues.Count); AssertPackageIssueWithPath(issues[0], "lib\\abc.xml"); AssertPackageIssueWithPath(issues[1], "lib\\sl4\\wow.pdb"); AssertPackageIssueWithPath(issues[2], "lib\\net\\4.0\\kac.txt"); }
public void UpdatePackageWithProjectManagerSetOperationToUpdate() { // 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 project = TestUtils.GetProject("project runway", projectFiles: new[] { "dotnetjunky.cs" }); var packageManager = new MockVsPackageManager( TestUtils.GetSolutionManager(defaultProjectName: "project runway", projects: new[] { project }), sourceRepository, new Mock <IFileSystemProvider>().Object, projectSystem, localRepository, new Mock <IDeleteOnRestartManager>().Object, new Mock <VsPackageInstallerEvents>().Object); packageManager.RegisterProjectManager(project, projectManager); 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); // Act packageManager.UpdatePackage( projectManager, "phuong", new SemanticVersion("2.0"), 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 UpdatePackageUpdatesPackagesWithCommonDependency() { // Arrange var localRepository = new MockPackageRepository(); var sourceRepository = new MockPackageRepository(); var constraintProvider = NullConstraintProvider.Instance; var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var projectSystem = new MockProjectSystem(); var packages = new List <IPackage>(); var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_B10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "B.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "A.txt" }, dependencies: new[] { new PackageDependency("C", VersionUtility.ParseVersionSpec("1.0")) }); var package_B20 = PackageUtility.CreatePackage("B", "2.0", content: new[] { "B.txt" }); var package_C10 = PackageUtility.CreatePackage("C", "1.0", content: new[] { "C.txt" }); localRepository.AddRange(new[] { package_A10, package_B10, package_C10 }); sourceRepository.AddRange(new[] { package_A12, package_B20 }); var sharedRepository = new Mock <ISharedPackageRepository>(MockBehavior.Strict); sharedRepository.SetupSet(s => s.PackageSaveMode = PackageSaveModes.Nupkg); sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback <IPackage>(p => packages.Add(p)).Verifiable(); sharedRepository.Setup(s => s.AddPackage(package_B20)).Callback <IPackage>(p => packages.Add(p)).Verifiable(); sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable()); var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(s => s.CreateRepository(It.IsAny <string>())).Returns(sourceRepository); var packageSourceProvider = new Mock <IPackageSourceProvider>(); packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") }); var updateCommand = new UpdateCommand() { RepositoryFactory = repositoryFactory.Object, SourceProvider = packageSourceProvider.Object }; // Act updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem); // Assert sharedRepository.Verify(); }
public void IsCompatibleReturnsTrueIfPackageHasFallbackAssemblyReference() { // Arrange var package = PackageUtility.CreatePackage( "A", "1.0", content: new string[] { "net40\\a.txt", "sl3\\b.txt" }, assemblyReferences: new string[] { "lib\\winrt45\\c.dll", "lib\\d.dll" }); var project = new Mock <Project>(); project.Setup(p => p.Properties.Item("TargetFrameworkMoniker").Value).Returns(".NETFramework, Version=3.0"); // Act bool result = project.Object.IsCompatible(package); // Assert Assert.True(result); }
public void GetPackagesReturnsNoResultsIfPackageDoesNotExistInSourceRepository() { // Arrange MockPackageRepository localRepository = new MockPackageRepository(); MockPackageRepository sourceRepository = new MockPackageRepository(); UpdatesTreeNode node = CreateUpdatesTreeNode(localRepository, sourceRepository, includePrerelease: false); localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0")); sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "1.5")); // Act var packages = node.GetPackages(searchTerm: null, allowPrereleaseVersions: true).ToList(); // Assert Assert.Equal(0, packages.Count); }
public void GetPackagesReturnsCorrectPackages2() { // Arrange MockPackageRepository localRepository = new MockPackageRepository(); MockPackageRepository sourceRepository = new MockPackageRepository(); UpdatesTreeNode node = CreateSimpleTreeNode(localRepository, sourceRepository); localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0")); sourceRepository.AddPackage(PackageUtility.CreatePackage("B", "1.5")); // Act var packages = node.GetPackages().ToList(); // Assert Assert.AreEqual(0, packages.Count); }
public void WinRTGenerateAnIssueForWinRTUnderContent() { // Arrange var package = PackageUtility.CreatePackage("A", "1.0", new[] { "winRT\\one.txt" }); var rule = new WinRTNameIsObsoleteRule(); // Act var results = rule.Validate(package).ToList(); // Assert Assert.Equal(1, results.Count); PackageIssueTestHelper.AssertPackageIssue( results[0], "The framework name 'WinRT' is obsolete.", "The file at 'content\\winRT\\one.txt' uses the obsolete 'WinRT' as the framework folder.", "Replace 'WinRT' or 'WinRT45' with 'NetCore45'."); }
public void ValidateReturnsNoIssueIfThereIsNoWinRT() { // Arrange var package = PackageUtility.CreatePackage( "A", "1.0", content: new [] { "silverlight\\help.txt" }, assemblyReferences: new [] { "lib\\me.winmd" }, tools: new[] { "windows8\\install.ps1" }); var rule = new WinRTNameIsObsoleteRule(); // Act var results = rule.Validate(package).ToList(); // Assert Assert.Equal(0, results.Count); }
public void AssemblyPlacedUnderLibHasOneIssue() { // Arrange var package = PackageUtility.CreatePackage("A", assemblyReferences: new[] { "lib\\abc.exe" }); var rule = new MisplacedAssemblyRule(); // Act IList <PackageIssue> issues = rule.Validate(package).ToList(); // Assert Assert.Equal(1, issues.Count); PackageIssueTestHelper.AssertPackageIssue( issues[0], "Assembly not inside a framework folder.", "The assembly 'lib\\abc.exe' is placed directly under 'lib' folder. It is recommended that assemblies be placed inside a framework-specific folder.", "Move it into a framework-specific folder. If this assembly is targeted for multiple frameworks, ignore this warning." ); }
public void SelfUpdateNoNuGetExeInNuGetExePackageThrows() { // Arrange var factory = new Mock <IPackageRepositoryFactory>(); var repository = new MockPackageRepository(); repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "3.0")); factory.Setup(m => m.CreateRepository(It.IsAny <PackageSource>())).Returns(repository); ConsoleInfo consoleInfo = GetConsoleInfo(); var updateCmd = new UpdateCommand(factory.Object); updateCmd.Console = consoleInfo.Console; updateCmd.Console = consoleInfo.Console; // Act & Assert ExceptionAssert.Throws <CommandLineException>(() => updateCmd.SelfUpdate("c:\foo.exe", new Version("2.0")), "Invalid NuGet.CommandLine package. Unable to locate NuGet.exe within the package."); }
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); }
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, null) { 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."); }
public void InstallCommandUsesRemoteIfCacheHasOldDependencyVersion() { // Arrange var newPackageDependency = PackageUtility.CreatePackage("Foo", "1.1"); var newPackage = PackageUtility.CreatePackage("Foo.UI", "1.1", dependencies: new[] { new PackageDependency("Foo", VersionUtility.ParseVersionSpec("[1.1]")) }); var repository = new MockPackageRepository { newPackageDependency, newPackage }; var repositoryFactory = new Mock <IPackageRepositoryFactory>(); repositoryFactory.Setup(r => r.CreateRepository("Some source")).Returns(repository); var fileSystem = new MockFileSystem(); var localCache = new Mock <IPackageRepository>(MockBehavior.Strict); localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Foo", "1.0") }.AsQueryable()).Verifiable(); var localRepository = new MockPackageRepository(); var installCommand = new TestInstallCommand( repositoryFactory.Object, GetSourceProvider(new[] { new PackageSource("Some source", "Some source name") }), fileSystem, machineCacheRepository: localCache.Object, localRepository: localRepository) { NoCache = false, Version = "1.1" }; installCommand.Arguments.Add("Foo.UI"); installCommand.Source.Add("Some Source name"); // Act installCommand.ExecuteCommand(); // Assert var installedPackages = localRepository.GetPackages().ToList(); Assert.Equal(2, installedPackages.Count); Assert.Same(newPackageDependency, installedPackages[0]); Assert.Same(newPackage, installedPackages[1]); localCache.Verify(); }
public void PackageRestoreRepositoryFindPackagesByIdReturnsUniquePackagesFromNonActiveRepository() { // 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"); IPackage packageA = PackageUtility.CreatePackage("A", "1.86"); IPackage packageB = PackageUtility.CreatePackage("B", "2.5"); mockRepository1.AddPackage(packageA); mockRepository2.AddPackage(packageB); mockRepository3.AddPackage(packageB); 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 packages = packageRestoreRepository.FindPackagesById("B").ToList(); Assert.Equal(1, packages.Count); Assert.Equal("B", packages[0].Id); Assert.Equal(new SemanticVersion("2.5"), packages[0].Version); }
public void TwoAssembliesPlacedOutsideLibHasOneIssues() { // Arrange var package = PackageUtility.CreatePackage("A", assemblyReferences: new[] { "content\\abc.exe", "tools\\def.winmd" }); var rule = new MisplacedAssemblyRule(); // Act IList <PackageIssue> issues = rule.Validate(package).ToList(); // Assert Assert.Equal(1, issues.Count); PackageIssueTestHelper.AssertPackageIssue( issues[0], "Assembly outside lib folder.", "The assembly 'tools\\def.winmd' is not inside the 'lib' folder and hence it won't be added as reference when the package is installed into a project.", "Move it into the 'lib' folder if it should be referenced." ); }