| 1 | using Xunit; |
| 2 | |
| 3 | namespace CascadeIDE.Tests; |
| 4 | |
| 5 | public sealed class SolutionFileLocatorTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void TryFindSolutionForSourceFile_WalksUpToSln() |
| 9 | { |
| 10 | var root = Path.Combine(Path.GetTempPath(), "cascade-slnfind-" + Guid.NewGuid().ToString("n")); |
| 11 | var src = Path.Combine(root, "src", "Lib"); |
| 12 | Directory.CreateDirectory(src); |
| 13 | var sln = Path.Combine(root, "App.sln"); |
| 14 | File.WriteAllText(sln, "Microsoft Visual Studio Solution File, Format Version 12.00\n"); |
| 15 | var cs = Path.Combine(src, "F.cs"); |
| 16 | File.WriteAllText(cs, "//"); |
| 17 | try |
| 18 | { |
| 19 | var found = SolutionFileLocator.TryFindSolutionForSourceFile(cs); |
| 20 | Assert.NotNull(found); |
| 21 | Assert.Equal(CanonicalFilePath.Normalize(sln), CanonicalFilePath.Normalize(found)); |
| 22 | } |
| 23 | finally |
| 24 | { |
| 25 | try { Directory.Delete(root, recursive: true); } catch { /* temp */ } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | [Fact] |
| 30 | public void TryFindSolutionForSourceFile_NoSolution_ReturnsNull() |
| 31 | { |
| 32 | var root = Path.Combine(Path.GetTempPath(), "cascade-slnfind-none-" + Guid.NewGuid().ToString("n")); |
| 33 | Directory.CreateDirectory(root); |
| 34 | var cs = Path.Combine(root, "X.cs"); |
| 35 | File.WriteAllText(cs, "//"); |
| 36 | try |
| 37 | { |
| 38 | Assert.Null(SolutionFileLocator.TryFindSolutionForSourceFile(cs)); |
| 39 | } |
| 40 | finally |
| 41 | { |
| 42 | try { Directory.Delete(root, recursive: true); } catch { } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void NeedsLoadSolutionBeforeBreakpoint_SamePath_ReturnsFalse() |
| 48 | { |
| 49 | var sln = @"C:\repo\A.sln"; |
| 50 | Assert.False(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(sln, @"C:\repo\A.sln")); |
| 51 | } |
| 52 | |
| 53 | [Fact] |
| 54 | public void NeedsLoadSolutionBeforeBreakpoint_WhenFoundFileExists_MatchesContract() |
| 55 | { |
| 56 | var root = Path.Combine(Path.GetTempPath(), "cascade-needload-" + Guid.NewGuid().ToString("n")); |
| 57 | Directory.CreateDirectory(root); |
| 58 | var slnA = Path.Combine(root, "A.sln"); |
| 59 | var slnB = Path.Combine(root, "B.sln"); |
| 60 | File.WriteAllText(slnA, ""); |
| 61 | File.WriteAllText(slnB, ""); |
| 62 | try |
| 63 | { |
| 64 | Assert.True(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(slnA, null)); |
| 65 | Assert.True(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(slnA, "")); |
| 66 | Assert.False(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(slnA, slnA)); |
| 67 | Assert.True(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(slnA, slnB)); |
| 68 | } |
| 69 | finally |
| 70 | { |
| 71 | try { Directory.Delete(root, recursive: true); } catch { } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | [Fact] |
| 76 | public void NeedsLoadSolutionBeforeBreakpoint_MissingFile_ReturnsFalse() |
| 77 | { |
| 78 | Assert.False(SolutionFileLocator.NeedsLoadSolutionBeforeBreakpoint(@"C:\no\such\file.sln", null)); |
| 79 | } |
| 80 | } |
| 81 | |