using Launcher.Next.Application; using Xunit; namespace Launcher.Next.Tests; public sealed class LegacyProductSelectionTests { [Fact] public void SourceVerifiedProducts_ExposeExactOpenFileFilters() { Assert.Equal("Project files |Project.xml|All files (*.*)|*.*", LegacyProductSelections.Pnid.Filter); Assert.Equal("nwd files (*.nwd)|*.nwd|All files (*.*)|*.*", LegacyProductSelections.Navisworks.Filter); Assert.Equal("Project.xml", LegacyProductSelections.Pnid.RequiredFileName); Assert.Equal(".nwd", LegacyProductSelections.Navisworks.RequiredFileName); } [Fact] public void AutomaticRoster_UsesOnlyExactLegacyRelativeLocation() { using var fixture = new SelectionFixture(); var project = fixture.ProjectFile("Project.xml"); var actual = LegacyProductSelections.AutomaticRoster(LegacyProductSelections.Pnid, project); Assert.Equal(Path.Combine(fixture.Root, "_System", "Plant PnID_2019", "Applications", "download_list.xml"), actual); Assert.DoesNotContain("scan", actual, StringComparison.OrdinalIgnoreCase); } [Fact] public void SelectedProjectFile_IsProductSpecificAndRejectsWrongExtension() { using var fixture = new SelectionFixture(); var nwd = fixture.ProjectFile("model.nwd"); Assert.Equal(nwd, LegacyProductSelections.ValidateSelectedFile(LegacyProductSelections.Navisworks, nwd)); Assert.Throws(() => LegacyProductSelections.ValidateSelectedFile(LegacyProductSelections.Pnid, nwd)); } [Fact] public void AutomaticPnidRoster_PreservesOrderAndReportsExactUnmappedIds() { using var fixture = new SelectionFixture(); var project = fixture.ProjectFile("Project.xml"); fixture.WriteAutomatic("Plant PnID_2019", "c1b999d6c16029e9ac5b1e1a8afe15005b80379c3ec715e7da0ee414c53aa7bc1111"); var plan = LegacyProductSelections.ReadRoster(LegacyProductSelections.Pnid, project, null, new LegacyConfigurationAdapter()); Assert.Equal("Automatic", plan.Source); Assert.Equal(["c1b999d6c16029e9ac5b1e1a8afe1500", "5b80379c3ec715e7da0ee414c53aa7bc", "1111"], plan.OrderedIds); Assert.Equal(plan.OrderedIds, plan.UnmappedIds); } [Fact] public void ManualRoster_DoesNotChangeProjectAndUsesExplicitDownloadList() { using var fixture = new SelectionFixture(); var project = fixture.ProjectFile("model.nwd"); var manual = Path.Combine(fixture.Root, "download_list.xml"); File.WriteAllText(manual, "7dd981169fa14d21aaef3fcdb0e7e970"); var plan = LegacyProductSelections.ReadRoster(LegacyProductSelections.Navisworks, project, manual, new LegacyConfigurationAdapter()); Assert.Equal("Manual", plan.Source); Assert.Equal(manual, plan.RosterPath); Assert.Equal(["7dd981169fa14d21aaef3fcdb0e7e970"], plan.UnmappedIds); Assert.Equal(project, LegacyProductSelections.ValidateSelectedFile(LegacyProductSelections.Navisworks, project)); } [Fact] public void MissingAutomaticRoster_FailsClosedWithoutSearchingOtherDirectories() { using var fixture = new SelectionFixture(); var project = fixture.ProjectFile("model.nwd"); File.WriteAllText(Path.Combine(fixture.Root, "download_list.xml"), "7dd981169fa14d21aaef3fcdb0e7e970"); var ex = Assert.Throws(() => LegacyProductSelections.ReadRoster(LegacyProductSelections.Navisworks, project, null, new LegacyConfigurationAdapter())); Assert.Equal("LEGACY_DOWNLOAD_LIST_NOT_FOUND", ex.Message); } [Fact] public void ProductIncompatibleIds_AreBlocked_AndDuplicateIdsRemainDiagnosticInput() { using var fixture = new SelectionFixture(); var project = fixture.ProjectFile("Project.xml"); fixture.WriteAutomatic("Plant PnID_2019", "unexpected"); Assert.Equal("LEGACY_PLUGIN_PRODUCT_MISMATCH", Assert.Throws(() => LegacyProductSelections.ReadRoster(LegacyProductSelections.Pnid, project, null, new LegacyConfigurationAdapter())).Message); fixture.WriteAutomatic("Plant PnID_2019", "11111111"); var duplicatePlan = LegacyProductSelections.ReadRoster(LegacyProductSelections.Pnid, project, null, new LegacyConfigurationAdapter()); Assert.Equal(["1111", "1111"], duplicatePlan.OrderedIds); } [Fact] public void Navisworks_DoesNotAdvertisePlantBootstrap() { Assert.False(LegacyProductSelections.Navisworks.SupportsPlantBootstrap); Assert.True(LegacyProductSelections.Pnid.SupportsPlantBootstrap); Assert.Equal(["7dd981169fa14d21aaef3fcdb0e7e970"], LegacyProductSelections.Navisworks.UnmappedLegacyIds); } private sealed class SelectionFixture : IDisposable { public SelectionFixture() { Root = Path.Combine(Path.GetTempPath(), "launcher-next-selection-" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(Path.Combine(Root, "Project")); } public string Root { get; } public string ProjectFile(string name) { var path = Path.Combine(Root, "Project", name); File.WriteAllText(path, "fixture"); return path; } public void WriteAutomatic(string pattern, string xml) { var directory = Path.Combine(Root, "_System", pattern, "Applications"); Directory.CreateDirectory(directory); File.WriteAllText(Path.Combine(directory, "download_list.xml"), xml); } public void Dispose() { if (Directory.Exists(Root)) Directory.Delete(Root, true); } } }