| 1 | using System.Collections.ObjectModel; |
| 2 | using CascadeIDE.Features.Workspace.Application; |
| 3 | using CascadeIDE.Models; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class SolutionExplorerTreeFilterTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void RebuildDisplayRoots_NoMatch_ClearsDisplay() |
| 12 | { |
| 13 | var root = SolutionItem.CreateSolution("s", @"C:\ws\app.sln"); |
| 14 | var proj = SolutionItem.CreateProject("p", @"C:\ws\p\p.csproj"); |
| 15 | proj.Children.Add(SolutionItem.CreateFile("Alpha.cs", @"C:\ws\p\Alpha.cs")); |
| 16 | root.Children.Add(proj); |
| 17 | var source = new ObservableCollection<SolutionItem> { root }; |
| 18 | var display = new ObservableCollection<SolutionItem>(); |
| 19 | |
| 20 | var index = new WorkspaceFileIndex(); |
| 21 | index.Invalidate(source, @"C:\ws\app.sln", @"C:\ws"); |
| 22 | SolutionExplorerTreeFilter.RebuildDisplayRoots(source, display, "Chain-lists", index); |
| 23 | |
| 24 | Assert.Empty(display); |
| 25 | } |
| 26 | |
| 27 | [Fact] |
| 28 | public void RebuildDisplayRoots_MatchingFile_ShowsPathToFile() |
| 29 | { |
| 30 | var root = SolutionItem.CreateSolution("s", @"C:\ws\app.sln"); |
| 31 | var proj = SolutionItem.CreateProject("p", @"C:\ws\p\p.csproj"); |
| 32 | var file = SolutionItem.CreateFile("Chain-lists.cs", @"C:\ws\p\Chain-lists.cs"); |
| 33 | proj.Children.Add(file); |
| 34 | root.Children.Add(proj); |
| 35 | var source = new ObservableCollection<SolutionItem> { root }; |
| 36 | var display = new ObservableCollection<SolutionItem>(); |
| 37 | |
| 38 | var index = new WorkspaceFileIndex(); |
| 39 | index.Invalidate(source, @"C:\ws\app.sln", @"C:\ws"); |
| 40 | SolutionExplorerTreeFilter.RebuildDisplayRoots(source, display, "Chain-lists", index); |
| 41 | |
| 42 | Assert.Single(display); |
| 43 | Assert.Equal(root.FullPath, display[0].FullPath); |
| 44 | Assert.Single(display[0].Children); |
| 45 | Assert.Single(display[0].Children[0].Children); |
| 46 | Assert.Equal(file.FullPath, display[0].Children[0].Children[0].FullPath); |
| 47 | Assert.NotSame(file, display[0].Children[0].Children[0]); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public void RebuildDisplayRoots_EmptyFilter_ReusesSourceReferences() |
| 52 | { |
| 53 | var root = SolutionItem.CreateFolder("dir"); |
| 54 | root.Children.Add(SolutionItem.CreateFile("a.cs", @"C:\ws\a.cs")); |
| 55 | var source = new ObservableCollection<SolutionItem> { root }; |
| 56 | var display = new ObservableCollection<SolutionItem>(); |
| 57 | |
| 58 | var index = new WorkspaceFileIndex(); |
| 59 | index.Invalidate(source, null, @"C:\ws"); |
| 60 | SolutionExplorerTreeFilter.RebuildDisplayRoots(source, display, "", index); |
| 61 | |
| 62 | Assert.Same(root, display[0]); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public void RebuildDisplayRoots_SubstringOnProject_ShowsProjectAndMatches() |
| 67 | { |
| 68 | var root = SolutionItem.CreateSolution("CascadeIDE", @"C:\cascade\CascadeIDE.sln"); |
| 69 | var analyzers = SolutionItem.CreateProject("CascadeIDE.ArchitectureAnalyzers", @"C:\cascade\CascadeIDE.ArchitectureAnalyzers\CascadeIDE.ArchitectureAnalyzers.csproj"); |
| 70 | var other = SolutionItem.CreateProject("CascadeIDE.Tests", @"C:\cascade\CascadeIDE.Tests\CascadeIDE.Tests.csproj"); |
| 71 | root.Children.Add(analyzers); |
| 72 | root.Children.Add(other); |
| 73 | var source = new ObservableCollection<SolutionItem> { root }; |
| 74 | var display = new ObservableCollection<SolutionItem>(); |
| 75 | |
| 76 | var index = new WorkspaceFileIndex(); |
| 77 | index.Invalidate(source, @"C:\cascade\CascadeIDE.sln", @"C:\cascade"); |
| 78 | SolutionExplorerTreeFilter.RebuildDisplayRoots(source, display, "Anal", index); |
| 79 | |
| 80 | Assert.Single(display); |
| 81 | Assert.Single(display[0].Children); |
| 82 | Assert.Equal(analyzers.FullPath, display[0].Children[0].FullPath); |
| 83 | } |
| 84 | } |
| 85 | |