test: replace composition source freezes

This commit is contained in:
Erik 2026-08-18 15:50:53 +02:00
parent caa5eb8b2b
commit 80c7b44457
8 changed files with 471 additions and 406 deletions

View file

@ -1,3 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using AcDream.App.Combat;
using AcDream.App.Composition;
@ -8,6 +9,7 @@ using AcDream.Content;
using AcDream.App.UI;
using AcDream.App.UI.Layout;
using AcDream.App.World;
using AcDream.App.Tests.Architecture;
using AcDream.Core.Combat;
using AcDream.Core.Items;
using AcDream.Core.Spells;
@ -190,19 +192,33 @@ public sealed class InteractionRetainedUiCompositionTests
[Fact]
public void GameWindowUsesPhaseAndContainsNoRetainedUiConstructionBody()
{
string source = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
"GameWindow.cs"));
IReadOnlyList<CompiledCall> calls =
CompiledCallGraph.ReadDeclared(typeof(GameWindow));
Assert.Contains("new InteractionRetainedUiCompositionPhase(", source);
Assert.DoesNotContain("new AcDream.App.UI.ItemInteractionController(", source);
Assert.DoesNotContain("_retailUiLease.AcquireHost(", source);
Assert.DoesNotContain("RetailUiRuntime.CreateUninitialized(", source);
Assert.DoesNotContain("private void UseItemByGuid(", source);
Assert.DoesNotContain("private uint? PickWorldGuidAtCursor(", source);
Assert.Single(
calls,
call => call.Target.DeclaringType
== typeof(InteractionRetainedUiCompositionPhase)
&& call.Target.IsConstructor);
Assert.DoesNotContain(
calls,
call => call.Target.DeclaringType
== typeof(ItemInteractionController)
&& call.Target.IsConstructor);
Assert.DoesNotContain(
calls,
call => call.Target.DeclaringType == typeof(RetailUiRuntimeLease)
&& call.Target.Name == "AcquireHost");
Assert.DoesNotContain(
calls,
call => call.Target.DeclaringType == typeof(RetailUiRuntime)
&& call.Target.Name == nameof(RetailUiRuntime.CreateUninitialized));
Assert.Null(typeof(GameWindow).GetMethod(
"UseItemByGuid",
BindingFlags.Instance | BindingFlags.NonPublic));
Assert.Null(typeof(GameWindow).GetMethod(
"PickWorldGuidAtCursor",
BindingFlags.Instance | BindingFlags.NonPublic));
}
private sealed class Fixture : IDisposable
@ -422,15 +438,4 @@ public sealed class InteractionRetainedUiCompositionTests
private static T Stub<T>() where T : class =>
(T)RuntimeHelpers.GetUninitializedObject(typeof(T));
private static string FindRepoRoot()
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
return directory.FullName;
directory = directory.Parent;
}
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
}
}