[CLAUDE] Tests Phase 2: Code generator format + sequence tests (SQLite in-memory)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m16s

Phase 2 — chống regression code generator. 17 test mới integration với
DB thật (SQLite in-memory) tổng cộng 71 test pass < 3 giây.

Test project:
- tests/SolutionErp.Infrastructure.Tests/ (xUnit + FluentAssertions + EF SQLite 10)
- ProjectReference SolutionErp.Infrastructure (transitively get Application + Domain)
- Added vào SolutionErp.slnx

Test fixtures:
- Common/SqliteDbFixture.cs:
  - SQLite ":memory:" + shared connection + EnsureCreated() từ DbContext model
  - TestApplicationDbContext subclass — override OnModelCreating replace
    'nvarchar(max)' → 'TEXT' (SQLite không support max keyword)
  - FixedDateTime stub IDateTime cho deterministic year boundary test

Test files:
- Services/ContractCodeGeneratorTests.cs (10 test):
  - Format per ContractType (5 type × Project scope) — RG-001 spec
  - Framework HĐ (NguyenTacNCC + NguyenTacDV) → year scope thay vì project
  - Sequence increment per prefix (3 calls → /01, /02, /03)
  - Different prefixes (project / supplier) → independent sequences
  - Year change (2026 → 2027) → reset sequence vì prefix khác
  - PersistsSequenceRow LastSeq verification
- Services/PurchaseEvaluationCodeGeneratorTests.cs (7 test):
  - Format A/B (DuyetNcc → 'A', DuyetNccPhuongAn → 'B')
  - Seq là 3-digit padded (001..012)
  - Type A và B sequence độc lập trong cùng năm
  - Year boundary reset cả A và B

CI gate update (.gitea/workflows/deploy.yml):
- Step "Run integration tests (Infrastructure)" thêm sau Domain tests
- TRX log saved riêng (infra-tests.trx)
- Cả 2 step đều exit non-zero → no deploy

Verify local:
- dotnet test SolutionErp.slnx → Total tests: 71 (54 Domain + 17 Infra) / Passed: 71 / 2.1s
- dotnet build SolutionErp.slnx → 0 error

Phase 3+ pending:
- Application handler tests (CQRS) với EF InMemory hoặc SQLite (~1 ngày)
- API smoke tests qua WebApplicationFactory (~0.5 ngày)
- FE Vitest cho lib utility (~0.5 ngày)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-04-29 13:29:06 +07:00
parent d3f9346840
commit df5988b7a9
6 changed files with 381 additions and 4 deletions

View File

@ -30,10 +30,9 @@ jobs:
& 'C:\Program Files\nodejs\npm.cmd' --version
# ============== TEST GATE ==============
# Run unit tests TRƯỚC build/publish/deploy. Test fail → exit non-zero
# → toàn bộ job stop, KHÔNG deploy. Phase 1 chỉ Domain layer (~54 test
# phase machine + policy registry). Mở rộng Application/Infra/Api
# khi có nhu cầu (xem docs/changelog/migration-todos.md).
# Run tests TRƯỚC build/publish/deploy. Fail → exit non-zero → no deploy.
# Phase 1: Domain (54 test policy state machine).
# Phase 2: Infrastructure (17 test code generators format/sequence/year scope).
- name: Run unit tests (Domain)
shell: powershell
run: |
@ -43,6 +42,15 @@ jobs:
--results-directory test-results
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Run integration tests (Infrastructure - SQLite in-memory)
shell: powershell
run: |
& 'C:\Program Files\dotnet\dotnet.exe' test tests/SolutionErp.Infrastructure.Tests/SolutionErp.Infrastructure.Tests.csproj `
--configuration Release `
--logger "trx;LogFileName=infra-tests.trx" `
--results-directory test-results
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Upload test results
if: always()
continue-on-error: true # nếu Gitea runner chưa có upload-artifact action, skip không block deploy