Ejemplo n.º 1
0
        public void GivenManagedInstallItCanInstallPacksFromOfflineCache()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var packInfo  = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk");
            var version   = "6.0.100";
            var cachePath = Path.Combine(dotnetRoot, "MockCache");

            // Write mock cache
            Directory.CreateDirectory(cachePath);
            var nupkgPath = Path.Combine(cachePath, $"{packInfo.ResolvedPackageId}.{packInfo.Version}.nupkg");

            File.Create(nupkgPath);

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context, new DirectoryPath(cachePath)));
            var mockNugetInstaller = nugetInstaller as MockNuGetPackageDownloader;

            // We shouldn't download anything, use the cache
            mockNugetInstaller.DownloadCallParams.Count.Should().Be(0);

            // Otherwise install should be normal
            mockNugetInstaller.ExtractCallParams.Count.Should().Be(1);
            mockNugetInstaller.ExtractCallParams[0].Item1.Should().Be(nupkgPath);
            mockNugetInstaller.ExtractCallParams[0].Item2.ToString().Should().Contain($"{packInfo.Id}-{packInfo.Version}-extracted");
            var installationRecordPath = Path.Combine(dotnetRoot, "metadata", "workloads", "InstalledPacks", "v1", packInfo.Id, packInfo.Version, version);

            File.Exists(installationRecordPath).Should().BeTrue();
            Directory.Exists(packInfo.Path).Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void GivenManagedInstallItCanInstallPacksWithAliases()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var alias    = "Xamarin.Android.BuildTools.Alias";
            var packInfo = CreatePackInfo("Xamarin.Android.BuildTools", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", alias, "8.4.7"), alias);
            var version  = "6.0.100";

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context));

            (nugetInstaller as MockNuGetPackageDownloader).DownloadCallParams.Count.Should().Be(1);
            (nugetInstaller as MockNuGetPackageDownloader).DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId(alias), new NuGetVersion(packInfo.Version), null as DirectoryPath?, null as PackageSourceLocation));
        }
Ejemplo n.º 3
0
        public void GivenManagedInstallItDetectsInstalledPacks()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var packInfo = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk");
            var version  = "6.0.100";

            // Mock installing the pack
            Directory.CreateDirectory(packInfo.Path);

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context));

            (nugetInstaller as MockNuGetPackageDownloader).DownloadCallParams.Count.Should().Be(0);
        }
Ejemplo n.º 4
0
        public void GivenManagedInstallItCanErrorsWhenMissingOfflineCache()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var packInfo  = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk");
            var version   = "6.0.100";
            var cachePath = Path.Combine(dotnetRoot, "MockCache");

            var exceptionThrown = Assert.Throws <Exception>(() =>
                                                            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context, new DirectoryPath(cachePath))));

            exceptionThrown.Message.Should().Contain(packInfo.ResolvedPackageId);
            exceptionThrown.Message.Should().Contain(packInfo.Version);
            exceptionThrown.Message.Should().Contain(cachePath);
        }
Ejemplo n.º 5
0
        public void GivenManagedInstallItHonorsNuGetSources()
        {
            var packageSource = new PackageSourceLocation(new FilePath("mock-file"));

            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller(packageSourceLocation: packageSource);
            var packInfo = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk");
            var version  = "6.0.100";

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context));

            var mockNugetInstaller = nugetInstaller as MockNuGetPackageDownloader;

            mockNugetInstaller.DownloadCallParams.Count.Should().Be(1);
            mockNugetInstaller.DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId(packInfo.Id), new NuGetVersion(packInfo.Version), null as DirectoryPath?, packageSource));
        }
Ejemplo n.º 6
0
        public void GivenManagedInstallItCanInstallManifestVersion()
        {
            var(_, installer, nugetDownloader) = GetTestInstaller(manifestDownload: true);
            var featureBand     = new SdkFeatureBand("6.0.100");
            var manifestId      = new ManifestId("test-manifest-1");
            var manifestVersion = new ManifestVersion("5.0.0");

            var manifestUpdate = new ManifestVersionUpdate(manifestId, null, null, manifestVersion, featureBand.ToString());

            CliTransaction.RunNew(context => installer.InstallWorkloadManifest(manifestUpdate, context));

            var mockNugetInstaller = nugetDownloader as MockNuGetPackageDownloader;

            mockNugetInstaller.DownloadCallParams.Count.Should().Be(1);
            mockNugetInstaller.DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId($"{manifestId}.manifest-{featureBand}"),
                                                                           new NuGetVersion(manifestVersion.ToString()), null as DirectoryPath?, null as PackageSourceLocation));
        }
Ejemplo n.º 7
0
        private void ReinstallWorkloadsBasedOnCurrentManifests(IEnumerable <WorkloadId> workloadIds, SdkFeatureBand sdkFeatureBand)
        {
            if (_workloadInstaller.GetInstallationUnit().Equals(InstallationUnit.Packs))
            {
                var installer = _workloadInstaller.GetPackInstaller();

                var packsToInstall = workloadIds
                                     .SelectMany(workloadId => _workloadResolver.GetPacksInWorkload(workloadId))
                                     .Distinct()
                                     .Select(packId => _workloadResolver.TryGetPackInfo(packId))
                                     .Where(pack => pack != null);

                foreach (var packId in packsToInstall)
                {
                    CliTransaction.RunNew(context => installer.RepairWorkloadPack(packId, sdkFeatureBand, context));
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 8
0
        public void GivenManagedInstallItCanInstallSingleFilePacks()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var packInfo = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Template, Path.Combine(dotnetRoot, "template-packs", "Xamarin.Android.Sdk.8.4.7.nupkg"), "Xamarin.Android.Sdk");
            var version  = "6.0.100";

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context));

            (nugetInstaller as MockNuGetPackageDownloader).DownloadCallParams.Count.Should().Be(1);
            (nugetInstaller as MockNuGetPackageDownloader).DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId(packInfo.Id), new NuGetVersion(packInfo.Version), null as DirectoryPath?, null as PackageSourceLocation));
            (nugetInstaller as MockNuGetPackageDownloader).ExtractCallParams.Count.Should().Be(0);

            var installationRecordPath = Path.Combine(dotnetRoot, "metadata", "workloads", "InstalledPacks", "v1", packInfo.Id, packInfo.Version, version);

            File.Exists(installationRecordPath).Should().BeTrue();
            var content = File.ReadAllText(installationRecordPath);

            content.Should().Contain(packInfo.Id.ToString());
            content.Should().Contain(packInfo.Version.ToString());

            File.Exists(packInfo.Path).Should().BeTrue();
        }
Ejemplo n.º 9
0
        public void GivenManagedInstallItCanInstallDirectoryPacks()
        {
            var(dotnetRoot, installer, nugetInstaller) = GetTestInstaller();
            var packInfo = CreatePackInfo("Xamarin.Android.Sdk", "8.4.7", WorkloadPackKind.Sdk, Path.Combine(dotnetRoot, "packs", "Xamarin.Android.Sdk", "8.4.7"), "Xamarin.Android.Sdk");
            var version  = "6.0.100";

            CliTransaction.RunNew(context => installer.InstallWorkloadPacks(new[] { packInfo }, new SdkFeatureBand(version), context));

            var mockNugetInstaller = nugetInstaller as MockNuGetPackageDownloader;

            mockNugetInstaller.DownloadCallParams.Count.Should().Be(1);
            mockNugetInstaller.DownloadCallParams[0].ShouldBeEquivalentTo((new PackageId(packInfo.Id), new NuGetVersion(packInfo.Version), null as DirectoryPath?, null as PackageSourceLocation));
            mockNugetInstaller.ExtractCallParams.Count.Should().Be(1);
            mockNugetInstaller.ExtractCallParams[0].Item1.Should().Be(mockNugetInstaller.DownloadCallResult[0]);
            mockNugetInstaller.ExtractCallParams[0].Item2.ToString().Should().Contain($"{packInfo.Id}-{packInfo.Version}-extracted");

            var installationRecordPath = Path.Combine(dotnetRoot, "metadata", "workloads", "InstalledPacks", "v1", packInfo.Id, packInfo.Version, version);

            File.Exists(installationRecordPath).Should().BeTrue();

            Directory.Exists(packInfo.Path).Should().BeTrue();
        }