Skip to content

sikebe-demo/dotnet-test-demo

Repository files navigation

.NET Test Demo

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.

πŸš€ Project Overview

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

πŸ“ Project Structure

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

πŸ› οΈ Technologies & Frameworks

  • .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

πŸƒβ€β™‚οΈ Getting Started

Prerequisites

Installation & Setup

  1. Clone the repository

    git clone https://github.com/sikebe-demo/dotnet-test-demo.git
    cd dotnet-test-demo
  2. Restore dependencies

    dotnet restore
  3. Build the solution

    dotnet build

Running the Applications

PrimeService Library

The PrimeService is a class library that can be referenced by other projects or tested independently.

RazorPagesProject Web Application

cd src/RazorPagesProject
dotnet run

The application will be available at:

Available Pages:

πŸ§ͺ Testing

This project demonstrates multiple testing strategies following the testing pyramid approach:

Unit Tests

Test individual components in isolation:

dotnet test src/PrimeService.Tests/

Integration Tests

Test the web application with in-memory database:

dotnet test src/RazorPagesProject.IntegrationTests/

End-to-End Tests

Test complete user scenarios with browser automation:

dotnet test src/RazorPagesProject.E2ETests/

Run All Tests

dotnet test

Code Coverage

Generate code coverage reports:

dotnet test --collect:"XPlat Code Coverage"

πŸ—οΈ Key Features

PrimeService Library

  • Efficient prime number validation algorithm
  • Handles edge cases (negative numbers, 0, 1)
  • Optimized performance using square root optimization
  • Comprehensive unit test coverage

RazorPagesProject Web Application

  • 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

Testing Architecture

  • 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

πŸ”§ Development Guidelines

Code Quality Standards

  • 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

Testing Best Practices

  • 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

πŸ“Š CI/CD Integration

The project is configured for continuous integration with:

  • Automated testing on pull requests
  • Code coverage reporting
  • Multi-platform testing support

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes following the coding guidelines
  4. Add or update tests as necessary
  5. Ensure all tests pass (dotnet test)
  6. Commit your changes (git commit -m 'Add some amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5