mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.1 KiB
84 lines
3.1 KiB
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team |
|
// |
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this |
|
// software and associated documentation files (the "Software"), to deal in the Software |
|
// without restriction, including without limitation the rights to use, copy, modify, merge, |
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
|
// to whom the Software is furnished to do so, subject to the following conditions: |
|
// |
|
// The above copyright notice and this permission notice shall be included in all copies or |
|
// substantial portions of the Software. |
|
// |
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
// DEALINGS IN THE SOFTWARE. |
|
|
|
using System.IO; |
|
using System.Threading.Tasks; |
|
|
|
using Avalonia.Headless; |
|
using Avalonia.Headless.NUnit; |
|
using Avalonia.Threading; |
|
|
|
using ILSpy; |
|
using ILSpy.AppEnv; |
|
using ILSpy.TreeNodes; |
|
using ILSpy.ViewModels; |
|
using ILSpy.Views; |
|
|
|
using NUnit.Framework; |
|
|
|
namespace ICSharpCode.ILSpy.Tests; |
|
|
|
[TestFixture] |
|
public class UseNestedNamespaceNodesScreenshot |
|
{ |
|
[AvaloniaTest] |
|
[Explicit("Visual evidence — requires ILSPY_TESTS_VISIBLE=1 so the headless platform renders.")] |
|
public async Task Capture_Before_And_After_Toggle() |
|
{ |
|
var settings = AppComposition.Current.GetExport<SettingsService>().DisplaySettings; |
|
settings.UseNestedNamespaceNodes = false; |
|
|
|
var window = AppComposition.Current.GetExport<MainWindow>(); |
|
window.Show(); |
|
var vm = (MainWindowViewModel)window.DataContext!; |
|
await vm.AssemblyTreeModel.WaitForAssembliesAsync(minimumCount: 3); |
|
|
|
var assemblyNode = vm.AssemblyTreeModel.FindNode<AssemblyTreeNode>("System.Linq"); |
|
assemblyNode.IsExpanded = true; |
|
await Waiters.WaitForAsync(() => assemblyNode.Children.Count > 0); |
|
Dispatcher.UIThread.RunJobs(); |
|
|
|
SaveFrame(window, "before-flat"); |
|
|
|
settings.UseNestedNamespaceNodes = true; |
|
await Waiters.WaitForAsync(() => |
|
assemblyNode.Children.Count > 0 |
|
&& assemblyNode.Children[assemblyNode.Children.Count - 1] is NamespaceTreeNode); |
|
// Re-expand — BindTree replaces the HierarchicalModel and resets visible expansion. |
|
assemblyNode.IsExpanded = true; |
|
Dispatcher.UIThread.RunJobs(); |
|
|
|
SaveFrame(window, "after-nested"); |
|
|
|
settings.UseNestedNamespaceNodes = false; |
|
} |
|
|
|
static void SaveFrame(global::Avalonia.Controls.Window window, string label) |
|
{ |
|
var frame = window.CaptureRenderedFrame(); |
|
if (frame is null) |
|
{ |
|
TestContext.WriteLine($"[{label}] no frame (headless drawing on)"); |
|
return; |
|
} |
|
var path = Path.Combine(Path.GetTempPath(), |
|
$"ilspy-tree-{label}-{System.DateTime.Now:yyyyMMdd-HHmmss}.png"); |
|
frame.Save(path); |
|
TestContext.WriteLine($"[{label}] saved {path}"); |
|
} |
|
}
|
|
|