Ejemplo n.º 1
0
 internal static PackageIdentity BuildPackageIdentity([NotNull] this SnapApp snapApp)
 {
     if (snapApp == null)
     {
         throw new ArgumentNullException(nameof(snapApp));
     }
     return(new PackageIdentity(snapApp.BuildNugetUpstreamId(), snapApp.Version.ToNuGetVersion()));
 }
Ejemplo n.º 2
0
        internal void SetupGetMetadatasAsync([NotNull] Mock <INugetService> nugetServiceMock, [NotNull] INuGetPackageSources nuGetPackageSources, [NotNull] SnapApp snapApp)
        {
            if (nugetServiceMock == null)
            {
                throw new ArgumentNullException(nameof(nugetServiceMock));
            }
            if (nuGetPackageSources == null)
            {
                throw new ArgumentNullException(nameof(nuGetPackageSources));
            }
            if (snapApp == null)
            {
                throw new ArgumentNullException(nameof(snapApp));
            }

            var upstreamPackageId = snapApp.BuildNugetUpstreamId();

            nugetServiceMock.Setup(x =>
                                   x.GetMetadatasAsync(
                                       It.Is <string>(v => string.Equals(v, upstreamPackageId)),
                                       It.IsAny <NuGetPackageSources>(),
                                       It.IsAny <CancellationToken>(),
                                       It.IsAny <bool>(),
                                       It.IsAny <bool>()))
            .ReturnsAsync(() =>
            {
                var packageSearchMedatadata = snapApp.BuildPackageSearchMetadata(nuGetPackageSources);
                return(new List <NuGetPackageSearchMedatadata> {
                    packageSearchMedatadata
                });
            });

            nugetServiceMock.Setup(x =>
                                   x.GetLatestMetadataAsync(
                                       It.Is <string>(v => string.Equals(v, upstreamPackageId)),
                                       It.IsAny <PackageSource>(),
                                       It.IsAny <CancellationToken>(),
                                       It.IsAny <bool>(),
                                       It.IsAny <bool>()))
            .ReturnsAsync(() =>
            {
                return(snapApp.BuildPackageSearchMetadata(nuGetPackageSources));
            });
        }
Ejemplo n.º 3
0
        public void TestBuildNugetUpstreamId_SnapApp(bool isDelta)
        {
            var snapApp = new SnapApp
            {
                Id      = "demoapp",
                Version = new SemanticVersion(1, 0, 0, "preview-123"),
                IsFull  = !isDelta,
                Target  = new SnapTarget
                {
                    Os        = OSPlatform.Windows,
                    Framework = "netcoreapp2.1",
                    Rid       = "win7-x64"
                }
            };

            var fullOrDelta       = snapApp.IsFull ? "full" : "delta";
            var expectedPackageId = $"{snapApp.Id}_{fullOrDelta}_{snapApp.Target.Rid}_snapx".ToLowerInvariant();

            var actualPackageId = snapApp.BuildNugetUpstreamId();

            Assert.Equal(expectedPackageId, actualPackageId);
        }
Ejemplo n.º 4
0
        static async Task <int> CommandListAsync([NotNull] ListOptions options, [NotNull] ISnapFilesystem filesystem,
                                                 [NotNull] ISnapAppReader appReader, [NotNull] INuGetPackageSources nuGetPackageSources, [NotNull] INugetService nugetService,
                                                 [NotNull] ISnapExtractor snapExtractor, [NotNull] ILog logger,
                                                 [NotNull] string workingDirectory, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (appReader == null)
            {
                throw new ArgumentNullException(nameof(appReader));
            }
            if (nuGetPackageSources == null)
            {
                throw new ArgumentNullException(nameof(nuGetPackageSources));
            }
            if (nugetService == null)
            {
                throw new ArgumentNullException(nameof(nugetService));
            }
            if (snapExtractor == null)
            {
                throw new ArgumentNullException(nameof(snapExtractor));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            var(snapApps, snapAppses, errorBuildingSnapApps, _) = BuildSnapAppsesFromDirectory(filesystem, appReader, nuGetPackageSources, workingDirectory);

            if (!snapApps.Apps.Any() || errorBuildingSnapApps)
            {
                return(1);
            }

            if (options.Id != null)
            {
                if (!snapApps.Apps.Any(x => string.Equals(x.Id, options.Id, StringComparison.OrdinalIgnoreCase)))
                {
                    logger.Error($"Unable to find application with id: {options.Id}");
                    return(1);
                }
            }

            var stopwatch = new Stopwatch();

            stopwatch.Restart();

            var snapAppses1DGraph = new List <(SnapApp snapApp,
                                               string channelName, string fullOrDeltaPackageId, PackageSource packageSource)>();

            var tables = new List <(SnapApp snapApp, ConsoleTable table)>();

            foreach (var snapApp in snapAppses)
            {
                if (options.Id != null &&
                    !string.Equals(snapApp.Id, options.Id, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                foreach (var channel in snapApp.Channels)
                {
                    var snapAppTmp = new SnapApp(snapApp);
                    snapAppTmp.SetCurrentChannel(channel.Name);

                    var packageSource = nuGetPackageSources.Items.Single(x => x.Name == channel.PushFeed.Name &&
                                                                         x.SourceUri == channel.PushFeed.Source);

                    snapAppses1DGraph.Add((snapApp, channel.Name, snapAppTmp.BuildNugetUpstreamId(), packageSource));
                    snapAppses1DGraph.Add((snapApp, channel.Name, snapAppTmp.BuildNugetUpstreamId(), packageSource));
                }

                var table = tables.SingleOrDefault(x => x.snapApp.Id == snapApp.Id);
                if (table != default)
                {
                    continue;
                }

                var tableColumns = new List <string>();
                tableColumns.Add("Rid");
                tableColumns.AddRange(snapApp.Channels.Select(x => $"Channel: {x.Name}"));
                tableColumns.Add("Summary");

                tables.Add((snapApp, new ConsoleTable(tableColumns)
                {
                    Header = $"Id: {snapApp.Id}"
                }));