A comprehensive demonstration project showcasing modern .NET development practices, testing strategies, and ASP.NET Core Razor Pages implementation with multiple layers of testing including Unit Tests, Integration Tests, and End-to-End (E2E) Tests.
This solution demonstrates best practices for .NET development and includes the following components:
- PrimeService: A mathematical library for prime number validation
- RazorPagesProject: An ASP.NET Core Razor Pages web application with Identity framework
- Multiple Test Projects: Comprehensive testing coverage with Unit, Integration, and E2E tests
dotnet-test-demo/
βββ src/
β βββ PrimeService/ # Core library for prime number calculations
β βββ PrimeService.Tests/ # Unit tests for PrimeService
β βββ RazorPagesProject/ # ASP.NET Core Razor Pages web application
β βββ RazorPagesProject.IntegrationTests/ # Integration tests for web app
β βββ RazorPagesProject.E2ETests/ # End-to-end tests using Selenium
βββ coverage/ # Code coverage reports
βββ global.json # .NET SDK version specification
βββ dotnet-test-demo.sln # Solution file
- .NET 9 - Latest .NET framework
- ASP.NET Core - Web framework
- Razor Pages - Page-based web UI framework
- Entity Framework Core - Object-relational mapping
- ASP.NET Core Identity - Authentication and authorization
- SQLite - Database for development and testing
- xUnit - Testing framework
- Selenium WebDriver - E2E testing automation
- .NET 9 SDK (version 9.0.301 or later)
- A code editor (Visual Studio, Visual Studio Code, or JetBrains Rider)
-
Clone the repository
git clone https://github.com/sikebe-demo/dotnet-test-demo.git cd dotnet-test-demo
-
Restore dependencies
dotnet restore
-
Build the solution
dotnet build
The PrimeService is a class library that can be referenced by other projects or tested independently.
cd src/RazorPagesProject
dotnet run
The application will be available at:
- HTTP: http://localhost:5016/
- HTTPS: https://localhost:7072/
Available Pages:
- Home: http://localhost:5016/
- GitHub Profile: http://localhost:5016/GitHubProfile
- About: http://localhost:5016/About
- Contact: http://localhost:5016/Contact
- Privacy: http://localhost:5016/Privacy
This project demonstrates multiple testing strategies following the testing pyramid approach:
Test individual components in isolation:
dotnet test src/PrimeService.Tests/
Test the web application with in-memory database:
dotnet test src/RazorPagesProject.IntegrationTests/
Test complete user scenarios with browser automation:
dotnet test src/RazorPagesProject.E2ETests/
dotnet test
Generate code coverage reports:
dotnet test --collect:"XPlat Code Coverage"
- Efficient prime number validation algorithm
- Handles edge cases (negative numbers, 0, 1)
- Optimized performance using square root optimization
- Comprehensive unit test coverage
- Authentication & Authorization: ASP.NET Core Identity integration
- Responsive Design: Mobile-friendly UI
- Internationalization: Multi-language support
- Database Integration: Entity Framework Core with SQLite
- Security: HTTPS, CSRF protection, XSS prevention
- GitHub Integration: GitHub profile display functionality
- Page Object Pattern: Maintainable E2E test structure
- Custom Web Application Factory: Isolated integration testing
- Explicit Wait Strategies: Reliable E2E test execution
- Parameterized Tests: Data-driven testing with xUnit Theory
- C# Latest Features: Utilizes .NET 9 and C# preview features
- SOLID Principles: Clean architecture implementation
- Async/Await: Proper asynchronous programming patterns
- Dependency Injection: Constructor injection throughout
- Error Handling: Comprehensive exception management
- AAA Pattern: Arrange, Act, Assert structure
- Explicit Waits: No
Thread.Sleep()
in tests - Stable Selectors: ID-based element selection for E2E tests
- Test Isolation: Independent test execution
- Mock Usage: Proper isolation in unit tests
The project is configured for continuous integration with:
- Automated testing on pull requests
- Code coverage reporting
- Multi-platform testing support
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes following the coding guidelines
- Add or update tests as necessary
- Ensure all tests pass (
dotnet test
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.