Ejemplo n.º 1
0
            public void ReturnsConstructorParameter()
            {
                var upgradeActionPalette = new PackageUpgradeActionPalette();
                var palette = new PackageUpgradePalette(upgradeActionPalette);

                Assert.Same(upgradeActionPalette, palette.UpgradeActionPalette);
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageUpgradePalette"/> class.
 /// </summary>
 /// <param name="upgradeActionPalette">The palette to visualize a <see cref="PackageUpgradeAction"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="upgradeActionPalette"/> is <c>null</c>.</exception>
 public PackageUpgradePalette(PackageUpgradeActionPalette upgradeActionPalette)
 {
     if (upgradeActionPalette == null)
     {
         throw new ArgumentNullException(nameof(upgradeActionPalette));
     }
     UpgradeActionPalette = upgradeActionPalette;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Visualizes the upgradeable dependencies of the specified packages.
        /// </summary>
        /// <param name="packages">The packages.</param>
        /// <param name="repository">The repository to resolve package dependencies.</param>
        /// <param name="targetFramework">The framework to find compatible package dependencies.</param>
        /// <returns>The graph of the upgradeable dependencies of the specified packages.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="packages"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="repository"/> is <c>null</c>.</exception>
        /// <seealso cref="UpgradeWalker"/>
        /// <seealso cref="PackageUpgradeVisualizer"/>
        /// <remarks>
        /// The method estimates the impact of an upgrade action. The palette ranges from green to red indicating the risk of an upgrade action.
        /// <list type="table">
        /// <listheader>
        /// <term><see cref="PackageUpgradeAction"/></term>
        /// <term>Color</term>
        /// <term>Risk</term>
        /// </listheader>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.None"/></term>
        /// <term>Black</term>
        /// <term>0</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.MinVersion"/></term>
        /// <term>ForestGreen</term>
        /// <term>1</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.ReleaseToRelease"/></term>
        /// <term>Goldenrod</term>
        /// <term>2</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.PrereleaseToRelease"/></term>
        /// <term>DarkOrange</term>
        /// <term>3</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.PrereleaseToPrerelease"/></term>
        /// <term>OrangeRed</term>
        /// <term>4</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.ReleaseToPrerelease"/></term>
        /// <term>Firebrick</term>
        /// <term>5</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.Unknown"/></term>
        /// <term>DarkGray</term>
        /// <term>-</term>
        /// </item>
        /// </list>
        /// </remarks>
        public static async Task <DirectedGraph> VisualizeUpgradeableDependenciesAsync(
            this IEnumerable <PackageIdentity> packages,
            SourceRepository repository,
            NuGetFramework targetFramework)
        {
            if (packages == null)
            {
                throw new ArgumentNullException(nameof(packages));
            }
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            var walker = new UpgradeWalker(repository, targetFramework);

            var directedGraph = DirectedGraphFactory.CreateDependencyGraph();

            var packageUpgradeActionPalette = new PackageUpgradeActionPalette();

            packageUpgradeActionPalette[PackageUpgradeAction.None]                   = "Black";
            packageUpgradeActionPalette[PackageUpgradeAction.MinVersion]             = "ForestGreen";
            packageUpgradeActionPalette[PackageUpgradeAction.ReleaseToRelease]       = "Goldenrod";
            packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToRelease]    = "DarkOrange";
            packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToPrerelease] = "OrangeRed";
            packageUpgradeActionPalette[PackageUpgradeAction.ReleaseToPrerelease]    = "Firebrick";
            packageUpgradeActionPalette[PackageUpgradeAction.Unknown]                = "DarkGray";

            var packageUpgradePalette = new PackageUpgradePalette(packageUpgradeActionPalette)
            {
                MissingPackageColor = "Red",
                PrereleaseColor     = "Gainsboro",
            };

            var visualizer = new PackageUpgradeVisualizer(directedGraph, packageUpgradePalette);

            foreach (var recentPackage in packages)
            {
                var upgrades = await walker.GetPackageUpgradesAsync(recentPackage).ConfigureAwait(false);

                visualizer.Visualize(recentPackage, upgrades);
            }

            return(directedGraph);
        }
            public void UsesUpgradeActionPaletteAsStrokeForLink()
            {
                var          packageUpgradeActionPalette = new PackageUpgradeActionPalette();
                const string expected = "myColor";

                packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToRelease] = expected;
                var packageUpgradePalette = new PackageUpgradePalette(packageUpgradeActionPalette);
                var visualizer            = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);
                var package        = StubPackageFactory.CreatePackage("A", "1.0.0");
                var packageUpgrade = new PackageUpgrade(
                    StubPackageDependencyFactory.CreateExact("B", "1.0.0"),
                    PackageUpgradeAction.PrereleaseToRelease,
                    null);

                visualizer.Visualize(package, new[] { packageUpgrade, });

                Assert.Equal(expected, _directedGraph.Links[0].Stroke);
            }
 public Indexer()
 {
     _palette = new PackageUpgradeActionPalette();
 }
            public void UsesUpgradeActionPaletteAsStrokeForLink()
            {
                var packageUpgradeActionPalette = new PackageUpgradeActionPalette();
                const string expected = "myColor";
                packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToRelease] = expected;
                var packageUpgradePalette = new PackageUpgradePalette(packageUpgradeActionPalette);
                var visualizer = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);
                var package = StubPackageFactory.CreatePackage("A", "1.0.0");
                var packageUpgrade = new PackageUpgrade(
                    StubPackageDependencyFactory.CreateExact("B", "1.0.0"),
                    PackageUpgradeAction.PrereleaseToRelease,
                    null);

                visualizer.Visualize(package, new[] { packageUpgrade, });

                Assert.Equal(expected, _directedGraph.Links[0].Stroke);
            }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageUpgradePalette"/> class.
 /// </summary>
 /// <param name="upgradeActionPalette">The palette to visualize a <see cref="PackageUpgradeAction"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="upgradeActionPalette"/> is <c>null</c>.</exception>
 public PackageUpgradePalette(PackageUpgradeActionPalette upgradeActionPalette)
 => UpgradeActionPalette = upgradeActionPalette ?? throw new ArgumentNullException(nameof(upgradeActionPalette));
        /// <summary>
        /// Visualizes the upgradeable dependencies of the specified packages.
        /// </summary>
        /// <param name="packages">The packages.</param>
        /// <param name="packageRepository">The repository to resolve package dependencies.</param>
        /// <param name="targetFramework">The framework to find compatible package dependencies.</param>
        /// <returns>The graph of the upgradeable dependencies of the specified packages.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="packages"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="packageRepository"/> is <c>null</c>.</exception>
        /// <seealso cref="UpgradeWalker"/>
        /// <seealso cref="PackageUpgradeVisualizer"/>
        /// <remarks>
        /// The method estimates the impact of an upgrade action. The palette ranges from green to red indicating the risk of an upgrade action.
        /// <list type="table">
        /// <listheader>
        /// <term><see cref="PackageUpgradeAction"/></term>
        /// <term>Color</term>
        /// <term>Risk</term>
        /// </listheader>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.None"/></term>
        /// <term>Black</term>
        /// <term>0</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.MinVersion"/></term>
        /// <term>ForestGreen</term>
        /// <term>1</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.ReleaseToRelease"/></term>
        /// <term>Goldenrod</term>
        /// <term>2</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.PrereleaseToRelease"/></term>
        /// <term>DarkOrange</term>
        /// <term>3</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.PrereleaseToPrerelease"/></term>
        /// <term>OrangeRed</term>
        /// <term>4</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.ReleaseToPrerelease"/></term>
        /// <term>Firebrick</term>
        /// <term>5</term>
        /// </item>
        /// <item>
        /// <term><see cref="PackageUpgradeAction.Unknown"/></term>
        /// <term>DarkGray</term>
        /// <term>-</term>
        /// </item>
        /// </list>
        /// </remarks>
        public static DirectedGraph VisualizeUpgradeableDependencies(
            this IEnumerable<IPackage> packages,
            IPackageRepository packageRepository,
            FrameworkName targetFramework)
        {
            if (packages == null)
            {
                throw new ArgumentNullException(nameof(packages));
            }
            if (packageRepository == null)
            {
                throw new ArgumentNullException(nameof(packageRepository));
            }

            var walker = new UpgradeWalker(packageRepository, targetFramework);

            var directedGraphFactory = new DirectedGraphFactory();
            var directedGraph = directedGraphFactory.CreateDependencyGraph();

            var packageUpgradeActionPalette = new PackageUpgradeActionPalette();
            packageUpgradeActionPalette[PackageUpgradeAction.None] = "Black";
            packageUpgradeActionPalette[PackageUpgradeAction.MinVersion] = "ForestGreen";
            packageUpgradeActionPalette[PackageUpgradeAction.ReleaseToRelease] = "Goldenrod";
            packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToRelease] = "DarkOrange";
            packageUpgradeActionPalette[PackageUpgradeAction.PrereleaseToPrerelease] = "OrangeRed";
            packageUpgradeActionPalette[PackageUpgradeAction.ReleaseToPrerelease] = "Firebrick";
            packageUpgradeActionPalette[PackageUpgradeAction.Unknown] = "DarkGray";

            var packageUpgradePalette = new PackageUpgradePalette(packageUpgradeActionPalette);
            packageUpgradePalette.MissingPackageColor = "Red";
            packageUpgradePalette.PrereleaseColor = "Gainsboro";

            var visualizer = new PackageUpgradeVisualizer(directedGraph, packageUpgradePalette);

            foreach (var recentPackage in packages)
            {
                var upgrades = walker.GetPackageUpgrades(recentPackage);
                visualizer.Visualize(recentPackage, upgrades);
            }

            return directedGraph;
        }