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 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.AreEqual(0, lookup.GetDependents(packageA1).Count()); Assert.AreEqual(0, lookup.GetDependents(packageA2).Count()); Assert.AreEqual(1, lookup.GetDependents(packageB1).Count()); Assert.AreEqual(1, lookup.GetDependents(packageB2).Count()); }
protected void CheckDependentPackages( IPackage package, IPackageRepository localRepository, FrameworkName targetFramework) { // check if there is any other package depends on this package. // if there is, throw to cancel the uninstallation var dependentsWalker = new DependentsWalker(localRepository, targetFramework); IList <IPackage> dependents = dependentsWalker.GetDependents(package).ToList(); if (dependents.Count > 0) { ShowProgressWindow(); throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.PackageHasDependents, package.GetFullName(), String.Join(", ", dependents.Select(d => d.GetFullName())) ) ); } }
protected void CheckDependentPackages( IPackage package, IPackageRepository localRepository, FrameworkName targetFramework) { // check if there is any other package depends on this package. // if there is, throw to cancel the uninstallation var dependentsWalker = new DependentsWalker(localRepository, targetFramework); IList<IPackage> dependents = dependentsWalker.GetDependents(package).ToList(); if (dependents.Count > 0) { ShowProgressWindow(); throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.PackageHasDependents, package.GetFullName(), String.Join(", ", dependents.Select(d => d.GetFullName())) ) ); } }
protected bool? AskRemoveDependencyAndCheckUninstallPSScript(IPackage package, bool checkDependents) { if (checkDependents) { // check if there is any other package depends on this package. // if there is, throw to cancel the uninstallation var dependentsWalker = new DependentsWalker(LocalRepository); IList<IPackage> dependents = dependentsWalker.GetDependents(package).ToList(); if (dependents.Count > 0) { ShowProgressWindow(); throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.PackageHasDependents, package.GetFullName(), String.Join(", ", dependents.Select(d => d.GetFullName())) ) ); } } var uninstallWalker = new UninstallWalker( LocalRepository, new DependentsWalker(LocalRepository), logger: NullLogger.Instance, removeDependencies: true, forceRemove: false) { ThrowOnConflicts = false }; IList<PackageOperation> operations = uninstallWalker.ResolveOperations(package).ToList(); var uninstallPackageNames = (from o in operations where o.Action == PackageAction.Uninstall && !PackageEqualityComparer.IdAndVersion.Equals(o.Package, package) select o.Package.ToString()).ToList(); bool? removeDependencies = false; if (uninstallPackageNames.Count > 0) { // show each dependency package on one line String packageNames = String.Join(Environment.NewLine, uninstallPackageNames); String message = String.Format(CultureInfo.CurrentCulture, Resources.Dialog_RemoveDependencyMessage, package) + Environment.NewLine + Environment.NewLine + packageNames; removeDependencies = _userNotifierServices.ShowRemoveDependenciesWindow(message); } if (removeDependencies == null) { return removeDependencies; } bool hasScriptPackages; if (removeDependencies == true) { // if user wants to remove dependencies, we need to check all of them for PS scripts var scriptPackages = from o in operations where o.Package.HasPowerShellScript() select o.Package; hasScriptPackages = scriptPackages.Any(); } else { // otherwise, just check the to-be-uninstalled package hasScriptPackages = package.HasPowerShellScript(new string[] { PowerShellScripts.Uninstall }); } if (hasScriptPackages) { if (!RegistryHelper.CheckIfPowerShell2Installed()) { throw new InvalidOperationException(Resources.Dialog_PackageHasPSScript); } } return removeDependencies; }