Skip to content

Commit c588d43

Browse files
authored
Merge pull request #30 from hasanpeal/develop
Fixes migration issue
2 parents b0725ba + 474a43d commit c588d43

File tree

4 files changed

+1539
-9
lines changed

4 files changed

+1539
-9
lines changed

README.md

Lines changed: 181 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,175 @@ Comprehensive audit trail:
490490

491491
---
492492

493+
## 🧪 Testing
494+
495+
### Test Setup
496+
497+
The project includes comprehensive backend testing using **xUnit** and **Moq** for .NET 9.0.
498+
499+
#### Prerequisites
500+
501+
- **.NET 9 SDK** (required for running tests)
502+
- **PostgreSQL** (for integration tests, can use in-memory database for unit tests)
503+
504+
#### Test Project Structure
505+
506+
```
507+
server/
508+
├── Tests/
509+
│ ├── Controllers/ # Controller integration tests
510+
│ │ ├── AccountControllerTests.cs
511+
│ │ ├── VaultControllerTests.cs
512+
│ │ ├── VaultItemControllerTests.cs
513+
│ │ ├── NotificationControllerTests.cs
514+
│ │ ├── ContactControllerTests.cs
515+
│ │ └── HealthControllerTests.cs
516+
│ ├── Services/ # Service layer unit tests
517+
│ │ ├── TokenServiceTests.cs
518+
│ │ ├── VaultServiceTests.cs
519+
│ │ ├── VaultItemServiceTests.cs
520+
│ │ ├── NotificationServiceTests.cs
521+
│ │ ├── EncryptionServiceTests.cs
522+
│ │ ├── DeviceServiceTests.cs
523+
│ │ └── VaultServiceExtendedTests.cs
524+
│ ├── Helpers/ # Test utilities and helpers
525+
│ │ └── TestHelpers.cs
526+
│ └── server.Tests.csproj # Test project file
527+
```
528+
529+
### Running Tests
530+
531+
#### Run All Tests
532+
533+
```bash
534+
cd server
535+
dotnet test Tests/server.Tests.csproj --configuration Release --verbosity normal
536+
```
537+
538+
#### Run Tests with Coverage
539+
540+
```bash
541+
cd server
542+
dotnet test Tests/server.Tests.csproj \
543+
--configuration Release \
544+
--collect:"XPlat Code Coverage" \
545+
--results-directory:./coverage
546+
```
547+
548+
#### Run Specific Test Class
549+
550+
```bash
551+
dotnet test Tests/server.Tests.csproj --filter "FullyQualifiedName~AccountControllerTests"
552+
```
553+
554+
#### Run Specific Test Method
555+
556+
```bash
557+
dotnet test Tests/server.Tests.csproj --filter "FullyQualifiedName~AccountControllerTests.Register_WithValidData_CreatesUser"
558+
```
559+
560+
### Test Results
561+
562+
#### Current Test Status
563+
564+
**All Tests Passing**: 117 tests, 0 failures
565+
566+
#### Test Coverage by Category
567+
568+
**Controller Tests (6 test classes, ~40 tests)**
569+
570+
-`AccountControllerTests` - Authentication, registration, profile management
571+
-`VaultControllerTests` - Vault CRUD, member management, invites, policies
572+
-`VaultItemControllerTests` - Item CRUD, permissions, restore operations
573+
-`NotificationControllerTests` - Notification retrieval, marking as read, deletion
574+
-`ContactControllerTests` - Contact form submission
575+
-`HealthControllerTests` - Health check endpoints
576+
577+
**Service Tests (8 test classes, ~77 tests)**
578+
579+
-`TokenServiceTests` - JWT token generation, validation, refresh tokens
580+
-`VaultServiceTests` - Vault business logic, permissions, CRUD operations
581+
-`VaultServiceExtendedTests` - Advanced vault operations (invites, transfers, policies)
582+
-`VaultItemServiceTests` - Item operations, permissions, encryption
583+
-`VaultItemServiceExtendedTests` - Advanced item operations (restore, permissions)
584+
-`NotificationServiceTests` - Notification creation, retrieval, updates
585+
-`EncryptionServiceTests` - AES-256 encryption/decryption, Unicode support
586+
-`DeviceServiceTests` - Device fingerprinting, verification, management
587+
588+
### CI/CD Integration
589+
590+
Tests are automatically run in **GitHub Actions** on every push and pull request:
591+
592+
```yaml
593+
# .github/workflows/ci.yml
594+
- name: Run tests
595+
run: dotnet test server/Tests/server.Tests.csproj --no-restore --configuration Release --verbosity normal
596+
```
597+
598+
#### Test Execution in CI
599+
600+
- **Trigger**: Push to `main`, `develop`, `master` branches or pull requests
601+
- **Environment**: Ubuntu Latest with .NET 9.0.x
602+
- **Test Results**: Uploaded as artifacts for review
603+
- **Status**: All tests must pass for CI to succeed
604+
605+
### Test Architecture
606+
607+
#### Test Patterns Used
608+
609+
1. **Arrange-Act-Assert (AAA)**: Standard test structure
610+
2. **Mocking**: Moq framework for dependencies (database, external services)
611+
3. **In-Memory Database**: EF Core InMemory provider for fast unit tests
612+
4. **Test Fixtures**: Reusable test data and setup helpers
613+
5. **Integration Tests**: Full controller tests with mocked services
614+
615+
#### Example Test Structure
616+
617+
```csharp
618+
[Fact]
619+
public async Task Register_WithValidData_CreatesUser()
620+
{
621+
// Arrange
622+
var registerDto = new RegisterDTO { /* ... */ };
623+
624+
// Act
625+
var result = await _controller.Register(registerDto);
626+
627+
// Assert
628+
Assert.NotNull(result);
629+
Assert.Equal(200, ((ObjectResult)result).StatusCode);
630+
}
631+
```
632+
633+
### Test Data Management
634+
635+
- **Test Helpers**: `TestHelpers.cs` provides utilities for creating test data
636+
- **Isolated Tests**: Each test is independent with its own database context
637+
- **Cleanup**: Automatic cleanup after each test execution
638+
- **Test Data**: Realistic test scenarios covering edge cases
639+
640+
### Coverage Goals
641+
642+
- ✅ **Controllers**: 100% endpoint coverage
643+
- ✅ **Services**: Core business logic fully tested
644+
- ✅ **Critical Paths**: Authentication, authorization, encryption
645+
- 🔄 **Integration Tests**: API endpoint integration testing
646+
- 🔄 **E2E Tests**: Full user workflow testing (planned)
647+
648+
### Running Tests Locally Before Push
649+
650+
Always run tests locally before pushing to ensure CI passes:
651+
652+
```bash
653+
# Run all tests
654+
cd server
655+
dotnet test Tests/server.Tests.csproj --configuration Release
656+
657+
# Expected output: All 117 tests passing ✅
658+
```
659+
660+
---
661+
493662
## 📦 Project Structure
494663

495664
```
@@ -628,12 +797,14 @@ npm run dev
628797

629798
**GitHub Actions Workflow:**
630799

631-
1. **Build**: Compile .NET backend, build Next.js frontend
632-
2. **Test**: Run unit tests (when implemented)
633-
3. **Docker**: Build container images
634-
4. **Deploy**: Automated deployment to staging/production
635-
5. **Migrations**: Automatic database migrations on startup
636-
6. **Smoke Tests**: Post-deployment health checks
800+
1. **Backend Tests**: Run 117 unit and integration tests
801+
- Controller tests (Account, Vault, VaultItem, Notification, Contact, Health)
802+
- Service tests (Token, Vault, VaultItem, Notification, Encryption, Device)
803+
- Test results uploaded as artifacts
804+
2. **Frontend Build & Lint**: Build Next.js app and run ESLint
805+
3. **Build**: Compile .NET backend, build Next.js frontend
806+
4. **Migrations**: Automatic database migrations on startup (Railway)
807+
5. **Deploy**: Automated deployment via Railway and Vercel (connected via GitHub)
637808

638809
---
639810

@@ -660,8 +831,8 @@ npm run dev
660831

661832
### Technical Debt & Improvements
662833

663-
- [ ] Unit test coverage (backend services)
664-
- [ ] Integration tests (API endpoints)
834+
- [x] Unit test coverage (backend services) - ✅ 117 tests implemented
835+
- [x] Integration tests (API endpoints) - ✅ Controller tests implemented
665836
- [ ] E2E tests (Playwright/Cypress)
666837
- [ ] Performance monitoring (Application Insights)
667838
- [ ] Rate limiting (API throttling)
@@ -700,7 +871,8 @@ Proprietary - All rights reserved
700871
**API Design**: RESTful, well-documented, type-safe
701872
**Database Design**: Normalized schema, proper relationships, migrations, triggers
702873
**Notification System**: Comprehensive in-app and email notifications
703-
**Change Tracking**: Detailed field-level change tracking for audit trails
874+
**Change Tracking**: Detailed field-level change tracking for audit trails
875+
**Test Coverage**: 117 comprehensive unit and integration tests
704876

705877
### Skills Demonstrated
706878

0 commit comments

Comments
 (0)