using PlotLine.Data;using PlotLine.Models;using PlotLine.Services;using PlotLine.Services.Context;using PlotLine.ViewModels; internal static class ContextNamesTests { public static async Task Run(){void Check(bool p,string m){if(!p)throw new Exception(m);Console.WriteLine("PASS Context Names Library: "+m);} NameSearchFilter? observed=null;var results=new List{new(){GivenNameID=8,DisplayName="Candidate",UsedCount=2,TotalRows=90}}; var service=NativeWorkflowTests.Proxy((n,a)=>{if(n!="BuildLibraryAsync")throw new Exception(n);observed=(NameSearchFilter)a![0]!;return Task.FromResult(new(){Filter=observed,Results=results});}); var projectRole="Owner";var personProject=7;var normalised="";var scope=""; var panel=new ContextNames(NativeWorkflowTests.Proxy((n,a)=>n switch{"GetCharacterAsync"=>Task.FromResult(new(){CharacterID=5,ProjectID=personProject,CharacterName="Canonical"}),"ListAliasesAsync"=>Task.FromResult>([new(){CharacterID=5,CharacterAliasID=1,Alias="Variant"}]),_=>throw new Exception("Unbounded catalogue read: "+n)}),NativeWorkflowTests.Proxy((_,_)=>Task.FromResult(new(){ProjectID=7,AccessRole=projectRole})),NativeWorkflowTests.Proxy((_,_)=>4),service,NativeWorkflowTests.Proxy((n,a)=>{normalised=(string)a![3]!;scope=(string)a[4]!;return Task.FromResult>([]);})); var filter=new NameSearchFilter{ProjectID=999,BookID=12,Search="Jo",LocaleCode="en-GB",BirthYear=1850,GenderPreference="Female",GenderThreshold=.7m,NameType="Variant",MinimumUsage=.05m,UsedScope="Book",UsedOnly=false,Page=2,PageSize=50};var value=await panel.Build(7,12,filter); Check(ReferenceEquals(observed,filter)&&observed.ProjectID==7&&observed.LocaleCode=="en-GB"&&observed.BirthYear==1850&&observed.GenderThreshold==.7m&&observed.MinimumUsage==.05m&&observed.UsedOnly==false&&observed.Page==2&&observed.PageSize==50,"all library criteria pass directly to the existing query service; project is authorised"); Check(ReferenceEquals(value.Library!.Results,results)&&value.Entries.Count==0,"candidate rows/counts/usage are unchanged and no identity catalogue is loaded"); await panel.Build(7,12);Check(observed!.BookID==12&&observed.UsedScope=="Project"&&observed.PageSize==25,"discovery retains book profile defaults with bounded series-wide usage"); await panel.Usage(7,12,"e\u0301va","Book");Check(normalised=="ÉVA"&&scope=="Project","exact identity/alias usage reuses existing normalisation across the series"); var identity=await panel.Identity(7,12,5);Check(identity.Entries.Single().Aliases.Single().Alias=="Variant"&&identity.CanEdit,"only explicitly selected canonical identity and aliases are loaded"); projectRole="Viewer";Check(!(await panel.Identity(7,12,5)).CanEdit,"read-only identity references expose no corrections");personProject=8;try{await panel.Identity(7,12,5);throw new Exception("Foreign identity accepted");}catch(UnauthorizedAccessException){Check(true,"foreign-project identity cannot be inspected for correction");} } }