| 1 | using CascadeIDE.Cockpit.ComputingUnits; |
| 2 | using CascadeIDE.Cockpit.ComputingUnits.Launch; |
| 3 | using CascadeIDE.Features.Launch.DataAcquisition; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class LaunchProfileProjectResolveUnitTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Compose_returns_empty_when_profile_not_found() |
| 12 | { |
| 13 | var root = Path.Combine(Path.GetTempPath(), "cide-lpru-" + Guid.NewGuid().ToString("n")); |
| 14 | Directory.CreateDirectory(root); |
| 15 | try |
| 16 | { |
| 17 | var sln = Path.Combine(root, "App.sln"); |
| 18 | File.WriteAllText(sln, ""); |
| 19 | var snapshot = LaunchProfileProjectResolveUnit.Default.Compose(sln, "Missing", root); |
| 20 | Assert.False(snapshot.HasProfile); |
| 21 | Assert.Null(snapshot.ProjectCsprojFullPath); |
| 22 | } |
| 23 | finally |
| 24 | { |
| 25 | try { Directory.Delete(root, true); } catch { } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | [Fact] |
| 30 | public void Compose_returns_profile_and_resolved_project_when_exists() |
| 31 | { |
| 32 | var root = Path.Combine(Path.GetTempPath(), "cide-lpru-" + Guid.NewGuid().ToString("n")); |
| 33 | Directory.CreateDirectory(root); |
| 34 | try |
| 35 | { |
| 36 | var sln = Path.Combine(root, "App.sln"); |
| 37 | File.WriteAllText(sln, ""); |
| 38 | |
| 39 | var projDir = Path.Combine(root, "src", "App"); |
| 40 | Directory.CreateDirectory(projDir); |
| 41 | var csproj = Path.Combine(projDir, "App.csproj"); |
| 42 | File.WriteAllText(csproj, "<Project />"); |
| 43 | |
| 44 | var launchTomlPath = LaunchProfilesStore.GetStorePath(sln); |
| 45 | Directory.CreateDirectory(Path.GetDirectoryName(launchTomlPath)!); |
| 46 | File.WriteAllText( |
| 47 | launchTomlPath, |
| 48 | """ |
| 49 | version = 1 |
| 50 | active_profile = "Default" |
| 51 | |
| 52 | [profiles.Default] |
| 53 | project = "src/App/App.csproj" |
| 54 | configuration = "Debug" |
| 55 | """); |
| 56 | |
| 57 | var snapshot = LaunchProfileProjectResolveUnit.Default.Compose(sln, null, root); |
| 58 | Assert.True(snapshot.HasProfile); |
| 59 | Assert.NotNull(snapshot.Profile); |
| 60 | Assert.Equal("Default", snapshot.Profile!.Value.ProfileId); |
| 61 | Assert.Equal(CanonicalFilePath.Normalize(csproj), snapshot.ProjectCsprojFullPath); |
| 62 | } |
| 63 | finally |
| 64 | { |
| 65 | try { Directory.Delete(root, true); } catch { } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | [Fact] |
| 70 | public void LaunchProfileProjectResolveUnit_default_and_snapshot_implement_ccu_contracts() |
| 71 | { |
| 72 | ICockpitComputeUnit unit = LaunchProfileProjectResolveUnit.Default; |
| 73 | Assert.NotNull(unit); |
| 74 | |
| 75 | ICockpitComputeUnitPayload payload = LaunchProfileProjectResolveSnapshot.Empty; |
| 76 | Assert.NotNull(payload); |
| 77 | } |
| 78 | } |
| 79 | |