Files
launcher-next/tests/Launcher.Next.Tests/LegacyProductSelectionTests.cs
T

100 lines
5.6 KiB
C#

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<InvalidOperationException>(() => 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", "<root><id>c1b999d6c16029e9ac5b1e1a8afe1500</id><id>5b80379c3ec715e7da0ee414c53aa7bc</id><id>1111</id></root>");
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, "<root><id>7dd981169fa14d21aaef3fcdb0e7e970</id></root>");
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"), "<root><id>7dd981169fa14d21aaef3fcdb0e7e970</id></root>");
var ex = Assert.Throws<InvalidOperationException>(() => LegacyProductSelections.ReadRoster(LegacyProductSelections.Navisworks, project, null, new LegacyConfigurationAdapter()));
Assert.Equal("LEGACY_DOWNLOAD_LIST_NOT_FOUND", ex.Message);
}
[Fact]
public void ProductIncompatibleAndDuplicateIds_AreBlocked()
{
using var fixture = new SelectionFixture();
var project = fixture.ProjectFile("Project.xml");
fixture.WriteAutomatic("Plant PnID_2019", "<root><id>unexpected</id></root>");
Assert.Equal("LEGACY_PLUGIN_PRODUCT_MISMATCH", Assert.Throws<InvalidOperationException>(() => LegacyProductSelections.ReadRoster(LegacyProductSelections.Pnid, project, null, new LegacyConfigurationAdapter())).Message);
fixture.WriteAutomatic("Plant PnID_2019", "<root><id>1111</id><id>1111</id></root>");
Assert.Equal("LEGACY_DOWNLOAD_SELECTION_INVALID", Assert.Throws<InvalidOperationException>(() => LegacyProductSelections.ReadRoster(LegacyProductSelections.Pnid, project, null, new LegacyConfigurationAdapter())).Message);
}
[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); }
}
}