using System.Reflection; using Microsoft.AspNetCore.Mvc; using PlotLine.Controllers; using PlotLine.Data; using PlotLine.Models; using PlotLine.Services; using PlotLine.ViewModels; internal static class WriterDashboardTests { public static async Task Run() { void Check(bool value,string message){if(!value)throw new Exception(message);Console.WriteLine("PASS Writer dashboard "+message);} int? scheduledBook=null;var allowed=true; var workspace=Proxy((method,args)=>method=="GetDashboardAsync"?Task.FromResult(new WriterDashboardViewModel{ProjectID=1,WriteNext=[new(){BookID=2,SceneID=20},new(){BookID=3,SceneID=30}]}):throw new Exception(method)); var schedule=Proxy((method,args)=>{if(method=="GetScheduleSetupAsync")return Task.FromResult(new WritingScheduleSetupViewModel{ProjectID=(int?)args![0]});if(method=="PopulateScheduleSetupOptionsAsync")return Task.CompletedTask;if(method!="GetTodayDashboardAsync")throw new Exception(method);scheduledBook=(int?)args![1];return Task.FromResult(new WritingScheduleDashboardViewModel{TodayTasks=[new(){BookID=2,SceneID=20},new(){BookID=3,SceneID=30}]});}); var books=Proxy((method,args)=>method switch{"ListByProjectAsync"=>Task.FromResult>([new(){BookID=2,ProjectID=1},new(){BookID=3,ProjectID=1}]),"GetAsync"=>Task.FromResult(new(){BookID=(int)args![0]!,ProjectID=1}),_=>throw new Exception(method)}); var access=Proxy((method,args)=>Task.FromResult(allowed)); var controller=new WriterController(workspace,schedule,books,access); var result=(ViewResult)await controller.Workspaces(1,3,"Revision");var model=(WriterDashboardViewModel)result.Model!; Check(model.BookID==3&&model.WriteNext.Single().SceneID==30&&model.WritingSchedule.TodayTasks.Single().SceneID==30,"book selection filters queues and tasks consistently"); Check(scheduledBook==3&&model.Workspace=="Revision","book scope reaches schedule service before selection and active workspace persists"); Check(await controller.Index(1,999) is NotFoundResult,"unknown book cannot fall back to another book"); var setup = (ViewResult)await controller.ScheduleSetup(1, 3); Check(((WritingScheduleSetupViewModel)setup.Model!).BookID == 3, "plan setup retains selected book instead of All Books"); Check(await controller.ScheduleSetup(99, 3) is NotFoundResult, "plan setup refuses conflicting project and book"); allowed=false;Check(await controller.Index(null,3) is NotFoundResult,"book-only deep link checks access before metadata"); Check(controller.LegacyWrite(1,3) is RedirectToActionResult redirect&&(int?)redirect.RouteValues!["bookId"]==3,"legacy Write redirect preserves book scope"); var commands=WriterNavigation.RibbonGroups("Reflect").SelectMany(g=>g.Commands);Check(WriterNavigation.RibbonGroups("Write").SelectMany(g=>g.Commands).Any(c=>c.Action=="Workspaces"&&c.Label=="Scene queues")&&commands.Any(c=>c.Controller=="WritingActivity"),"Writer contextual commands target implemented workspaces and evidence"); } private static T Proxy(Func action)where T:class {var value=DispatchProxy.Create();((WriterProxy)(object)value).Action=action;return value;} public class WriterProxy:DispatchProxy { public Func Action {get;set;}=null!; protected override object? Invoke(MethodInfo? targetMethod,object?[]? args)=>Action(targetMethod!.Name,args); } }