Skip to content

Add unit test suite and testability interfaces - #18

Draft
tomokusaba wants to merge 1 commit into
afrom
tomokusaba/gulflike-antone
Draft

Add unit test suite and testability interfaces#18
tomokusaba wants to merge 1 commit into
afrom
tomokusaba/gulflike-antone

Conversation

@tomokusaba

Copy link
Copy Markdown
Owner

Why

The BlazorServerChat2 project had no automated tests, and two core service classes (AgentFrameworkLogic, UserChatSettingCache) were injected as concrete types, making them impossible to mock in unit tests.

What changed

Testability interfaces (production code):

  • Extracted IAgentFrameworkLogic and IUserChatSettingCache interfaces
  • Updated all consumers (AiController, ChatController, ChatMcpTools, Index.razor, Program.cs) to depend on interfaces instead of concrete types
  • DI registrations updated accordingly

Test suite (setup-tests.ps1):

  • A self-contained PowerShell script at the repo root that materializes the full BlazorServerChat2.Tests/ xUnit project on disk
  • Run with: powershell -ExecutionPolicy Bypass -File setup-tests.ps1
  • Creates 7 test classes (~77 tests total):
    • JwtServiceTests — token generation, expiry, invalid signatures, missing claims
    • RoomTests — capacity, join/leave, cooldown, time-gate logic via reflection
    • SharedChatMessageStoreTests — add, retrieve, clear, concurrent-write safety
    • UtlRandomTests — character generation, length, uniqueness
    • ChatControllerTests — GetSetting/UpdateSetting happy path, not-found, auth
    • OsaifuControllerTests — balance CRUD, deposit/withdraw, ownership enforcement
    • AiControllerTests — balance checks, AI call path, stream response, clear history

Notes

  • Room.CheckTime is private and tested via reflection to avoid modifying production code
  • EF In-Memory databases are isolated per test class with unique GUID names
  • The test project is not committed to the repo — only setup-tests.ps1 is committed; run it once to materialize and restore dependencies

- Extract IAgentFrameworkLogic and IUserChatSettingCache interfaces
- Update all consumers to depend on interfaces
- Add setup-tests.ps1 to materialize xUnit test project (~77 tests)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant