コード例 #1
0
            public void ReturnsConstructorParameter()
            {
                var upgradeActionPalette = new PackageUpgradeActionPalette();
                var palette = new PackageUpgradePalette(upgradeActionPalette);

                Assert.Same(upgradeActionPalette, palette.UpgradeActionPalette);
            }
コード例 #2
0
            public void StoresValue()
            {
                var          palette  = new PackageUpgradePalette();
                const string expected = "myColor";

                palette.MissingPackageColor = expected;
                Assert.Equal(expected, palette.MissingPackageColor);
            }
コード例 #3
0
            public void UsesPrereleaseColorOfPaletteAsBackgroundForNodeOfPrereleasePackage()
            {
                var          packageUpgradePalette = new PackageUpgradePalette();
                const string expected = "myColor";

                packageUpgradePalette.PrereleaseColor = expected;
                var visualizer = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);
                var package    = StubPackageFactory.CreatePackage("A", "1.0.0-a");

                visualizer.Visualize(package, Enumerable.Empty <PackageUpgrade>());

                Assert.Equal(expected, _directedGraph.Nodes[0].Background);
            }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageUpgradeVisualizer"/> class.
        /// </summary>
        /// <param name="directedGraph">The directed graph used to visualize package upgrades.</param>
        /// <param name="palette">The color palette to color nodes and links.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="directedGraph"/> is <c>null</c>.
        /// - or -
        /// <paramref name="palette"/> is <c>null</c>.
        /// </exception>
        public PackageUpgradeVisualizer(DirectedGraph directedGraph, PackageUpgradePalette palette)
        {
            if (directedGraph == null)
            {
                throw new ArgumentNullException(nameof(directedGraph));
            }
            if (palette == null)
            {
                throw new ArgumentNullException(nameof(palette));
            }

            _directedGraph = directedGraph;
            _palette = palette;
        }
コード例 #5
0
            public void UsesMissingPackageColorOfPaletteAsStrokeForNodeOfPackageDependency()
            {
                var          packageUpgradePalette = new PackageUpgradePalette();
                const string expected = "myColor";

                packageUpgradePalette.MissingPackageColor = expected;
                var visualizer = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);

                var package        = CreatePackage();
                var packageUpgrade = CreatePackageUpgradeWithoutPackage();

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

                var node = _directedGraph.Nodes[1];

                Assert.Equal(expected, node.Stroke);
            }
コード例 #6
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);
        }
コード例 #7
0
            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);
            }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageUpgradeVisualizer"/> class.
 /// </summary>
 /// <param name="directedGraph">The directed graph used to visualize package upgrades.</param>
 /// <param name="palette">The color palette to color nodes and links.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="directedGraph"/> is <c>null</c>.
 /// - or -
 /// <paramref name="palette"/> is <c>null</c>.
 /// </exception>
 public PackageUpgradeVisualizer(DirectedGraph directedGraph, PackageUpgradePalette palette)
 {
     _directedGraph = directedGraph ?? throw new ArgumentNullException(nameof(directedGraph));
     _palette       = palette ?? throw new ArgumentNullException(nameof(palette));
 }
コード例 #9
0
            public void DefaultValueIsNull()
            {
                var palette = new PackageUpgradePalette();

                Assert.Null(palette.MissingPackageColor);
            }
コード例 #10
0
            public void DefaultValueIsNull()
            {
                var palette = new PackageUpgradePalette();

                Assert.Null(palette.PrereleaseColor);
            }
コード例 #11
0
            public void InitializesADefaultUpgradeActionPalette()
            {
                var palette = new PackageUpgradePalette();

                Assert.NotNull(palette.UpgradeActionPalette);
            }
コード例 #12
0
            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);
            }
コード例 #13
0
            public void UsesMissingPackageColorOfPaletteAsStrokeForNodeOfPackageDependency()
            {
                var packageUpgradePalette = new PackageUpgradePalette();
                const string expected = "myColor";
                packageUpgradePalette.MissingPackageColor = expected;
                var visualizer = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);

                var package = CreatePackage();
                var packageUpgrade = CreatePackageUpgradeWithoutPackage();

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

                var node = _directedGraph.Nodes[1];
                Assert.Equal(expected, node.Stroke);
            }
コード例 #14
0
            public void UsesPrereleaseColorOfPaletteAsBackgroundForNodeOfPrereleasePackage()
            {
                var packageUpgradePalette = new PackageUpgradePalette();
                const string expected = "myColor";
                packageUpgradePalette.PrereleaseColor = expected;
                var visualizer = new PackageUpgradeVisualizer(_directedGraph, packageUpgradePalette);
                var package = StubPackageFactory.CreatePackage("A", "1.0.0-a");

                visualizer.Visualize(package, Enumerable.Empty<PackageUpgrade>());

                Assert.Equal(expected, _directedGraph.Nodes[0].Background);
            }
コード例 #15
0
        /// <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;
        }