| 1 | using Xunit; |
| 2 | |
| 3 | namespace CascadeIDE.Tests; |
| 4 | |
| 5 | public sealed class McpSolutionTreeTests |
| 6 | { |
| 7 | [Theory] |
| 8 | [InlineData(@"D:\repo\proj\obj\Debug\net10.0\Foo.cs", true)] |
| 9 | [InlineData(@"D:/repo/proj/obj/x/Foo.cs", true)] |
| 10 | [InlineData(@"D:\repo\proj\bin\Debug\a.dll", true)] |
| 11 | [InlineData(@"D:\repo\proj\Services\Foo.cs", false)] |
| 12 | [InlineData(@"D:\repo\proj\objections\Note.cs", false)] |
| 13 | public void IsBuildArtifactPath_Classifies_Obj_Bin_Segments(string path, bool expected) |
| 14 | { |
| 15 | Assert.Equal(expected, McpSolutionTree.IsBuildArtifactPath(path)); |
| 16 | } |
| 17 | |
| 18 | [Fact] |
| 19 | public void ResolveOwningProjectPath_Picks_Nearest_Csproj_On_Disk() |
| 20 | { |
| 21 | var root = FindCascadeIdeRoot(); |
| 22 | var mainCsproj = Path.Combine(root, "CascadeIDE.csproj"); |
| 23 | var testsCsproj = Path.Combine(root, "CascadeIDE.Tests", "CascadeIDE.Tests.csproj"); |
| 24 | var contractsCsproj = Path.Combine(root, "CascadeIDE.Contracts", "CascadeIDE.Contracts.csproj"); |
| 25 | |
| 26 | var mainFile = Path.Combine(root, "Features", "Workspace", "Application", "McpSolutionTree.cs"); |
| 27 | var testFile = Path.Combine(root, "CascadeIDE.Tests", "McpSolutionTreeTests.cs"); |
| 28 | var contractsFile = Path.Combine(root, "CascadeIDE.Contracts", "ApiStability.cs"); |
| 29 | |
| 30 | Assert.True(File.Exists(mainFile), mainFile); |
| 31 | Assert.True(File.Exists(testFile), testFile); |
| 32 | Assert.True(File.Exists(contractsFile), contractsFile); |
| 33 | |
| 34 | Assert.Equal(CanonicalFilePath.Normalize(mainCsproj), CanonicalFilePath.Normalize(McpSolutionTree.ResolveOwningProjectPath(mainFile)!)); |
| 35 | Assert.Equal(CanonicalFilePath.Normalize(testsCsproj), CanonicalFilePath.Normalize(McpSolutionTree.ResolveOwningProjectPath(testFile)!)); |
| 36 | Assert.Equal(CanonicalFilePath.Normalize(contractsCsproj), CanonicalFilePath.Normalize(McpSolutionTree.ResolveOwningProjectPath(contractsFile)!)); |
| 37 | } |
| 38 | |
| 39 | private static string FindCascadeIdeRoot() |
| 40 | { |
| 41 | var dir = new DirectoryInfo(AppContext.BaseDirectory); |
| 42 | while (dir is not null) |
| 43 | { |
| 44 | var csproj = Path.Combine(dir.FullName, "CascadeIDE.csproj"); |
| 45 | if (File.Exists(csproj)) |
| 46 | return dir.FullName; |
| 47 | dir = dir.Parent; |
| 48 | } |
| 49 | |
| 50 | throw new InvalidOperationException("CascadeIDE.csproj not found above test output directory."); |
| 51 | } |
| 52 | } |
| 53 | |