public void GivenWorkloadUpdateAcrossFeatureBandsItUpdatesPacks(bool userLocal) { var testDirectory = _testAssetsManager.CreateTestDirectory(identifier: userLocal ? "userlocal" : "default").Path; var dotnetRoot = Path.Combine(testDirectory, "dotnet"); var userProfileDir = Path.Combine(testDirectory, "user-profile"); var manifestPath = Path.Combine(_testAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest"), "BasicSample.json"); var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { manifestPath }), dotnetRoot, userLocal, userProfileDir); var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot); var manifestUpdater = new MockWorkloadManifestUpdater(); var sdkFeatureVersion = "6.0.100"; var installingWorkload = "simple-workload"; string installRoot = userLocal ? userProfileDir : dotnetRoot; if (userLocal) { WorkloadFileBasedInstall.SetUserLocal(dotnetRoot, sdkFeatureVersion); } var workloadPacks = new List <PackInfo>() { CreatePackInfo("mock-pack-1", "1.0.0", WorkloadPackKind.Framework, Path.Combine(installRoot, "packs", "mock-pack-1", "1.0.0"), "mock-pack-1"), CreatePackInfo("mock-pack-2", "2.0.0", WorkloadPackKind.Framework, Path.Combine(installRoot, "packs", "mock-pack-2", "2.0.0"), "mock-pack-2") }; // Lay out workload installs for a previous feature band var oldFeatureBand = "5.0.100"; var packRecordDir = Path.Combine(installRoot, "metadata", "workloads", "InstalledPacks", "v1"); foreach (var pack in workloadPacks) { Directory.CreateDirectory(Path.Combine(packRecordDir, pack.Id, pack.Version)); File.Create(Path.Combine(packRecordDir, pack.Id, pack.Version, oldFeatureBand)); } Directory.CreateDirectory(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads")); Directory.CreateDirectory(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads")); File.Create(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads", installingWorkload)); File.Create(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)); // Update workload (without installing any workloads to this feature band) var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--from-previous-sdk" }); var updateCommand = new WorkloadUpdateCommand(updateParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userProfileDir: userProfileDir, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); updateCommand.Execute(); foreach (var pack in workloadPacks) { Directory.Exists(pack.Path).Should().BeTrue(because: $"Pack should be installed {testDirectory}"); File.Exists(Path.Combine(packRecordDir, pack.Id, pack.Version, oldFeatureBand)) .Should().BeTrue(because: "Pack install record should still be present for old feature band"); } File.Exists(Path.Combine(installRoot, "metadata", "workloads", oldFeatureBand, "InstalledWorkloads", installingWorkload)) .Should().BeTrue(because: "Workload install record should still be present for old feature band"); File.Exists(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)) .Should().BeTrue(because: "Workload install record should be present for current feature band"); }
public void GivenWorkloadUpdateItRemovesOldPacksAfterInstall(bool userLocal) { var testDirectory = _testAssetsManager.CreateTestDirectory(identifier: userLocal ? "userlocal" : "default").Path; var dotnetRoot = Path.Combine(testDirectory, "dotnet"); var userProfileDir = Path.Combine(testDirectory, "user-profile"); var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), dotnetRoot, userLocal, userProfileDir); var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot); var manifestUpdater = new MockWorkloadManifestUpdater(); var sdkFeatureVersion = "6.0.100"; var installingWorkload = "xamarin-android"; string installRoot = userLocal ? userProfileDir : dotnetRoot; if (userLocal) { WorkloadFileBasedInstall.SetUserLocal(dotnetRoot, sdkFeatureVersion); } // Install a workload var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userProfileDir: userProfileDir, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); // 7 packs in packs dir, 1 template pack var installPacks = Directory.GetDirectories(Path.Combine(installRoot, "packs")); installPacks.Count().Should().Be(7); foreach (var packDir in installPacks) { Directory.GetDirectories(packDir).Count().Should().Be(1); // 1 version of each pack installed } File.Exists(Path.Combine(installRoot, "metadata", "workloads", "InstalledPacks", "v1", "Xamarin.Android.Sdk", "8.4.7", "6.0.100")) // Original pack version is installed .Should().BeTrue(); File.Exists(Path.Combine(installRoot, "template-packs", "xamarin.android.templates.1.0.3.nupkg")) .Should().BeTrue(); // Install records are correct File.Exists(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)) .Should().BeTrue(); var packRecordDirs = Directory.GetDirectories(Path.Combine(installRoot, "metadata", "workloads", "InstalledPacks", "v1")); packRecordDirs.Count().Should().Be(8); foreach (var packRecordDir in packRecordDirs) { var packVersionRecordDirs = Directory.GetDirectories(packRecordDir); packVersionRecordDirs.Count().Should().Be(1); // 1 version of each pack installed Directory.GetFiles(packVersionRecordDirs.First()).Count().Should().Be(1); // 1 feature band file for this pack id and version } // Mock updating the manifest workloadResolver = WorkloadResolver.CreateForTests( new MockManifestProvider(new[] { Path.Combine(_testAssetsManager.GetAndValidateTestProjectDirectory("SampleUpdatedManifest"), "Sample.json") }), dotnetRoot, userLocal, userProfileDir); // Update workload var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update" }); var updateCommand = new WorkloadUpdateCommand(updateParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userProfileDir: userProfileDir, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); updateCommand.Execute(); // 6 packs in packs dir, 1 template pack var updatePacks = Directory.GetDirectories(Path.Combine(installRoot, "packs")); updatePacks.Count().Should().Be(6); foreach (var packDir in updatePacks) { Directory.GetDirectories(packDir).Count().Should().Be(1); // 1 version of each pack installed } File.Exists(Path.Combine(installRoot, "metadata", "workloads", "InstalledPacks", "v1", "Xamarin.Android.Sdk", "8.5.7", "6.0.100")) // New pack version is installed .Should().BeTrue(); File.Exists(Path.Combine(installRoot, "template-packs", "xamarin.android.templates.2.1.3.nupkg")) .Should().BeTrue(); // Install records are correct File.Exists(Path.Combine(installRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)) .Should().BeTrue(); packRecordDirs = Directory.GetDirectories(Path.Combine(installRoot, "metadata", "workloads", "InstalledPacks", "v1")); packRecordDirs.Count().Should().Be(7); foreach (var packRecordDir in packRecordDirs) { var packVersionRecordDirs = Directory.GetDirectories(packRecordDir); packVersionRecordDirs.Count().Should().Be(1); // 1 version of each pack installed Directory.GetFiles(packVersionRecordDirs.First()).Count().Should().Be(1); // 1 feature band file for this pack id and version } }