Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
Prompt: Write Tests
Purpose
Add or extend unit tests for a change, using the MSTest + Moq conventions already in src/Tests/.
Inputs Required
- Repository root.
- The type or behavior under test.
- The change or bug the tests must cover.
Steps
Read
.ai/knowledge/tests.mdfor the MSTest + Moq patterns, test structure, validator testing, and controller test setup.Locate the mirror test project. Test projects mirror source projects one-to-one:
Source Tests src/Business/Grand.Business.Catalogsrc/Tests/Grand.Business.Catalog.Testssrc/Web/Grand.Websrc/Tests/Grand.Web.Testssrc/Web/Grand.Web.Adminsrc/Tests/Grand.Web.Admin.Testssrc/Web/Grand.Web.Storesrc/Tests/Grand.Web.Store.Testssrc/Core/Grand.Infrastructuresrc/Tests/Grand.Infrastructure.Testssrc/Modules/Grand.Module.Apisrc/Tests/Grand.Module.Api.Testsother modules src/Tests/Grand.Modules.TestsRead the nearest existing test class in the target project and copy its structure — fixture setup, mock naming, assertion style.
Write tests that cover, in this order: the happy path, the boundary the change introduced, and the failure the change fixes.
For a bug fix, write the failing test first and confirm it fails for the stated reason before applying the fix.
Run only the affected test project.
Mandatory Rules
- Mock at the interface boundary (
IRepository<T>, business service interfaces,IMediator), not concrete infrastructure. - Do not hit a real database, network, or file system in a unit test.
- Each test asserts one behavior, and its name says what that behavior is.
- Do not change production code to make a test easier unless the change is an improvement on its own terms.
- Do not weaken or delete an existing assertion to make a suite pass — investigate why it now fails.
Output Format
- Under test: type and behavior.
- Tests added: name + what each one pins down.
- Bug fix proof: for fixes, confirmation that the test failed before and passes after.
- Run: the exact test command and its result.
- Not covered: behavior that remains untested and why.