using PlotLine.Data; using PlotLine.Models; using PlotLine.Services; internal static class NamesWorkspaceTests { public static async Task Run() { void Check(bool value,string message){if(!value)throw new Exception(message);Console.WriteLine("PASS Names workspace: "+message);} bool allowed=true;int metadataCalls=0,associationCalls=0; var metadata=NativeWorkflowTests.Proxy((method,args)=>{Check(method=="RecogniseAsync","selected metadata uses the existing recognition service");metadataCalls++;return Task.FromResult(new NameRecognitionResult());}); var repository=NativeWorkflowTests.Proxy((method,args)=>{Check(method=="ListUsedDecorationsAsync","one existing association query per selected name");Check((int)args![1]! ==7&&args[2] is null&&(string)args[3]! =="GEORGE"&&(string)args[4]! =="Project","associations use exact normalisation across the authorised series, independent of book");associationCalls++;return Task.FromResult>([new(){CharacterID=1,CharacterName="George",CharacterTypeCode="animal",Species="Cat",MatchType="Character"},new(){CharacterID=2,CharacterName="Hamish",CharacterTypeCode="animal",Species="Dog",MatchType="Alias"}]);}); var projects=NativeWorkflowTests.Proxy((_,_)=>Task.FromResult(allowed?new(){ProjectID=7}:null)); var service=new NamesWorkspace(metadata,repository,projects,NativeWorkflowTests.Proxy((_,_)=>4),NativeWorkflowTests.Proxy((method,_)=>method=="Read"?Task.FromResult(null):throw new Exception("Ordinary details must not initiate AI"))); Check(metadataCalls==0&&associationCalls==0,"constructing a workspace does not eagerly load details"); var selected=await service.Details(7," George ",null,null,default); Check(selected!.Associations.Count==2&&selected.Associations.All(x=>x.CharacterTypeCode=="animal")&&selected.Associations[1].MatchType=="Alias","multiple non-human primary and alias associations retain their canonical records"); allowed=false;Check(await service.Details(8,"George",null,null,default) is null&&associationCalls==1,"foreign series access is rejected before metadata and association retrieval"); allowed=true;Check(await service.Details(7,new string('a',121),null,null,default) is null&&associationCalls==1,"invalid name scope is rejected before retrieval"); } }