Maintained in timewarp-architecture · Canonical file: SKILL.md

Install

npx skills add TimeWarpEngineering/timewarp-architecture --skill mock-response-factory

Or copy the SKILL.md into your agent's skills directory.


Mock Response Factory

Enables Blazor SPA development without a live backend. Every API contract exposes a factory; the SPA mock service dispatches requests to it.

Detection — find patterns in the current repo

rg -l 'GetMockResponseFactory' --glob '**/*.cs' | head -5
rg -l 'Mock.*ApiService' --glob '**/*.cs'
rg 'delegate.*MockResponseFactory' --glob '**/*.cs'

Read an existing contract + its registration before adding a new one.

Step 1 — Implement on the contract

Add to the operation's public static partial class:

public static MockResponseFactory<Response> GetMockResponseFactory()
{
  return _ => new Response(/* realistic sample data */);
}

Rules:

ListResponse example

public static MockResponseFactory<Response> GetMockResponseFactory()
{
  AnnouncementDto[] items =
  [
    new() { Text = "Maintenance tonight", Link = "/announcements/1" },
    new() { Text = "New feature available", Link = "/announcements/2" },
  ];
  return _ => new Response(totalCount: items.Length, items);
}

Command example

public static MockResponseFactory<Response> GetMockResponseFactory()
{
  return _ => new Response { SecurityRoleId = 1, B2CGroupId = Guid.NewGuid() };
}

Step 2 — Register in the SPA mock service

Mirror the registration pattern already in the repo. Common variants:

Dictionary on mock service:

{ typeof(GetProfile.Query), GetProfile.GetMockResponseFactory() },
{ typeof(CreateSecurityRole.Command), CreateSecurityRole.GetMockResponseFactory() },

Wrapper class per endpoint (MockFactories/ folder):

internal sealed class GetProfileMockFactory : IMockResponseFactory
{
  public object Create(IApiRequest request) =>
    GetProfile.GetMockResponseFactory()((GetProfile.Query)request);
}

Then register the wrapper class in the mock service's factory dictionary.

Step 3 — Verify

Checklist