Add unit test suite and testability interfaces - #18
Draft
tomokusaba wants to merge 1 commit into
Draft
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
IAgentFrameworkLogicandIUserChatSettingCacheinterfacesAiController,ChatController,ChatMcpTools,Index.razor,Program.cs) to depend on interfaces instead of concrete typesTest suite (
setup-tests.ps1):BlazorServerChat2.Tests/xUnit project on diskpowershell -ExecutionPolicy Bypass -File setup-tests.ps1JwtServiceTests— token generation, expiry, invalid signatures, missing claimsRoomTests— capacity, join/leave, cooldown, time-gate logic via reflectionSharedChatMessageStoreTests— add, retrieve, clear, concurrent-write safetyUtlRandomTests— character generation, length, uniquenessChatControllerTests— GetSetting/UpdateSetting happy path, not-found, authOsaifuControllerTests— balance CRUD, deposit/withdraw, ownership enforcementAiControllerTests— balance checks, AI call path, stream response, clear historyNotes
Room.CheckTimeis private and tested via reflection to avoid modifying production codesetup-tests.ps1is committed; run it once to materialize and restore dependencies