void Check(bool value,string message){if(!value)throw new Exception(message);} foreach(var scenario in new[]{"normal","destroyed","replaced"}){ GContext.container=new Container();Awaiters.Gate=new();var old=GContext.container;var panel=new Subject(); var pending=panel.LastShowPanel();Check(!pending.IsCompleted,"expected delay"); if(scenario=="destroyed")panel.Destroyed=true; if(scenario=="replaced")GContext.container=new Container(); Awaiters.Gate.SetResult(true);await pending; Check(old.Face.Shows==(scenario=="normal"?1:0),"old flow applied after exit"); if(scenario=="replaced")Check(GContext.container.Face.Shows==0,"old callback opened new account UI"); Check(Debug.Errors==0,"callback logged an error"); Console.WriteLine("PASS real LastShowPanel body: "+scenario); } public partial class Subject{ public bool Destroyed; public static bool operator ==(Subject a,Subject b)=>ReferenceEquals(b,null)?ReferenceEquals(a,null)||a.Destroyed:ReferenceEquals(a,b); public static bool operator !=(Subject a,Subject b)=>!(a==b); public override bool Equals(object other)=>ReferenceEquals(this,other); public override int GetHashCode()=>base.GetHashCode(); } public static class GContext{public static Container container=new();} public class Container{ public Face Face=new();public BuffDataCenter Buff=new(); public T Resolve()=>(T)(object)(typeof(T)==typeof(BuffDataCenter)?(object)Buff:Face); } public class BuffDataCenter{public List showFishBuffIds=new();} public interface IFaceUIService{void ShowPostFaceUI();} public class Face:IFaceUIService{public int Shows;public void ShowPostFaceUI()=>Shows++;} public static class Awaiters{public static TaskCompletionSource Gate;public static Task Seconds(float n)=>Gate.Task;} public static class Debug{public static int Errors;public static void LogError(object e)=>Errors++;}