using PlotLine.Data; using PlotLine.Models; using PlotLine.Services.Context; internal static class ContextAssetsTests { public static void Run() { var scenes = new Scene[] { new(){SceneID=10}, new(){SceneID=20}, new(){SceneID=30}, new(){SceneID=40} }; var asset = new StoryAsset { StoryAssetID=1, ProjectID=7, AssetName="Parcel", CurrentLocationName="Future metadata" }; var scope = new SpatialScope { ProjectID=7, SceneID=30 }; var history = new StoryPointHistory { AssetLocations=[new(){StoryAssetID=1,SceneID=10,LocationPath="Depot"},new(){StoryAssetID=1,SceneID=20,LocationPath="Office"},new(){StoryAssetID=1,SceneID=40,LocationPath="Future"}], Custody=[new(){StoryAssetID=1,SceneID=10,AssetCustodyEventID=1},new(){StoryAssetID=1,SceneID=20,AssetCustodyEventID=2},new(){StoryAssetID=1,SceneID=40,AssetCustodyEventID=3}], Custodians=[new(){AssetCustodyEventID=1,RoleName="Has Custody",CharacterName="First"},new(){AssetCustodyEventID=2,RoleName="Transfers From",CharacterName="First"},new(){AssetCustodyEventID=2,RoleName="Transfers To",CharacterName="Second"},new(){AssetCustodyEventID=2,RoleName="Observes",CharacterName="Witness"},new(){AssetCustodyEventID=3,RoleName="Has Custody",CharacterName="Future"}] }; var mention = new AssetEvent {StoryAssetID=1, SceneID=30, AssetEventTypeName="Mentioned", ToStateName="Legacy state"}; var row = ContextAssets.Build(scope,scenes,[asset],[mention],history).Assets.Single(); Check(row.Presence=="Mentioned" && row.OpeningHolder.Value=="Second" && row.OpeningHolder.SceneID==20,"Handover uses recipient, not sender/observer or future holder"); Check(row.OpeningLocation.Value=="Office" && row.OpeningLocation.SceneID==20,"Opening uses historical location, independently of holder and metadata"); Check(!row.Changes.Any(c=>c.Contains("Legacy state")),"Mention does not present a state transition"); var moveOnly = new StoryPointHistory {AssetLocations=history.AssetLocations, Custody=[history.Custody[0]], Custodians=history.Custodians}; row=ContextAssets.Build(scope,scenes,[asset],[mention],moveOnly).Assets.Single(); Check(row.OpeningHolder.Value=="First" && row.OpeningHolder.SceneID==10 && row.OpeningLocation.SceneID==20,"Location-only move retains independent holder source"); row=ContextAssets.Build(scope,scenes,[asset],[mention],new(){AssetLocations=history.AssetLocations}).Assets.Single(); Check(row.OpeningHolder.Value=="Unknown" && row.OpeningHolder.SceneID==null && row.OpeningLocation.Value=="Office","Move with no holder evidence stays unknown"); Check(ContextAssets.Holder(new(){AssetCustodyEventID=2,CustodyEventTypeName="Lost By"},history.Custodians)=="Unknown","Explicit loss clears holder despite participants"); Check(ContextAssets.Holder(new(){AssetCustodyEventID=99},[])=="Unknown","Explicit empty custody clears holder"); Check(ContextAssets.Holder(new(){AssetCustodyEventID=4},[new(){AssetCustodyEventID=4,RoleName="Observes",CharacterName="Witness"}])==null,"Observer is not possession"); Check(ContextAssets.Holder(new(){AssetCustodyEventID=4},[new(){AssetCustodyEventID=4,RoleName="Transfers To"}])=="Unknown","Unnamed recipient clears stale known possession"); mention.AssetEventTypeName="Present"; Check(ContextAssets.Build(scope,scenes,[asset],[mention],history).Assets.Single().Presence=="Present","Explicit presence recorded"); mention.AssetEventTypeName="Used"; Check(ContextAssets.Build(scope,scenes,[asset],[mention],history).Assets.Single().Presence=="Unrecorded","Legacy action does not imply presence"); Check(ContextAssets.Build(scope,scenes,[asset],[],new()).Assets.Count==0,"Unlinked asset omitted"); Check(ContextWorkspaceNavigation.IsAllowed("/StoryAssets/Details/1"),"Asset uses permitted main-window navigation"); Check(!ContextWorkspaceNavigation.IsAllowed("/StoryAssets/Delete/1"),"No destructive destination added"); } private static void Check(bool value,string message){if(!value)throw new Exception(message);} }