Skip to content

Conversation

@randelramirez
Copy link
Owner

@randelramirez randelramirez commented Aug 26, 2025

This pull request introduces several improvements to the project's CI/CD pipeline, code quality enforcement, and .NET project configuration, alongside updates and enhancements to the unit tests for the SampleService. The main changes focus on automating build, test, and validation processes, enforcing code quality and formatting standards, modernizing project settings, and improving the reliability and coverage of unit tests.

CI/CD and Code Quality Automation

  • Added a comprehensive CI workflow (.github/workflows/ci.yml) that builds and tests across Ubuntu, Windows, and macOS, validates project structure, checks for required projects, ensures compilation, and runs security/vulnerability checks.
  • Introduced a code quality workflow (.github/workflows/code-quality.yml) that enforces build warnings as errors and verifies code formatting consistency using dotnet format.

Project Configuration and Dependency Updates

  • Enabled nullable reference types for stricter type safety in API/API.csproj and Client.Test/Client.Test.csproj. [1] [2]
  • Updated test dependencies in Client.Test/Client.Test.csproj to use xunit.v3, added Newtonsoft.Json and Microsoft.Extensions.Http, and upgraded other packages for .NET 9 compatibility.

Unit Test Enhancements and Coverage

  • Refactored and expanded unit tests in Client.Test/SampleServiceTest.cs:
    • Improved test structure and assertions for better reliability and clarity.
    • Added tests for 404 responses, server errors, and request configuration verification.
    • Enhanced use of Moq for mocking HTTP responses and verifying HTTP interactions.
  • Added a stub handler for 404 Not Found responses (Client.Test/HandlersStub/Return404NotFoundResponseHandler.cs) and updated the 200 OK handler to use modern C# syntax and Newtonsoft.Json serialization for more realistic test data. [1] [2]

Codebase Modernization

  • Adopted modern C# features such as collection expressions and file-scoped namespaces in test code for improved readability and maintainability. [1] [2]
  • Added a global usings file for the test project to streamline common imports and document the migration to xUnit v3.

These changes collectively improve the automation, reliability, and maintainability of the codebase, ensuring high code quality and robust test coverage as the project moves forward with .NET 9.

- Removed closing </Project> tag in API.csproj for structural adjustment.
- Refactored Return200OkResponseHandler.cs to use C# 12/13 collection expression syntax and object initializers for better readability.
- Updated SampleServiceTest.cs to use 'using' for HttpClient instantiation and added comments for clarity in test phases.
- Upgraded `Microsoft.NET.Test.Sdk` and added `Newtonsoft.Json` to `Client.Test.csproj`.
- Added new test classes for `AuthenticationService`, `CRUDService`, `ErrorHandlingService`, and `FileUploadService`.
- Refactored `CRUDService` to use dependency injection for `HttpClient`.
- Introduced new services: `ConcurrencyService`, `CustomHeadersService`, `FileUploadService`, `GraphQLService`, and `WebhookService`.
- Enhanced `AuthenticationService` with token authentication methods.
- Updated `README.md` to include new features and usage examples.
- Updated `ci.yml` to add project validation and improve caching and artifact uploads.
- Modified `code-quality.yml` to include code analysis and format checks.
- Downgraded `Microsoft.NET.Test.Sdk` in `Client.Test.csproj` and replaced `xunit` with `xunit.v3`.
- Introduced `GlobalUsings.cs` for global using directives in tests.
- Created response handler files for specific HTTP responses in tests.
- Refactored `SampleServiceTest.cs` with new tests and improved error handling.
- Cleaned up `AuthenticationServiceTests.cs` and enhanced mock setups.
- Improved mock handler setups and assertions in `CRUDServiceTests.cs`.
- Enhanced error handling in `ErrorHandlingServiceTests.cs`.
- Verified HTTP request creation in `FileUploadServiceTests.cs`.
- Initialized `Name` and `Address` properties in `ContactViewModel.cs` to default to `string.Empty`.
- Improved dependency caching and added validation steps in `ci.yml`.
- Enhanced code quality checks in `code-quality.yml` with dependency restoration and warning treatment.
- Added CI and code quality badges to `README.md`.
- Expanded documentation on Continuous Integration features and status.
- Replaced outdated testing examples with a comprehensive overview of testing practices.
- Updated project structure details in `README.md`.
- Made minor language and formatting adjustments for clarity.
@randelramirez randelramirez changed the title Feat/upgrade to net9 upgrade to net9 Aug 27, 2025
Moved `dotnet restore` into the `Check code formatting` step, removing the separate restore step for improved efficiency.
Updated `code-quality.yml` to add a job for code formatting using `dotnet format`. Enabled the `Nullable` feature in multiple project files to improve null safety. Removed the serialization constructor from `UnauthorizedApiAccessException`, which may impact exception handling during serialization. Overall, these changes aim to improve code quality and maintainability.
Updated the codebase to include 35 unit tests with comprehensive coverage for error handling and HTTP status codes using xUnit v3.0.1 and Moq. Introduced `PollyResilienceService` for resilience patterns like retry, circuit breaker, and timeout policies at the HttpClient level.

Implemented `ProductionReadyHttpClientService` for best practices in logging, security, and monitoring. Added `PerformanceOptimizationService` to demonstrate high-throughput scenarios, including connection pooling and streaming.

Provided educational custom handlers for retry and circuit breaker patterns, emphasizing the use of Polly in production. Updated appsettings.json for flexible API configurations and revised documentation to reflect new features and usage examples.
Revised the README title to "HttpClient .NET 9 Patterns & Best Practices". Enhanced the introduction to focus on comprehensive usage patterns, highlighting five approaches and Microsoft's recommended production patterns with Polly. Streamlined content for clarity, reorganized sections, and added details about learning outcomes and project structure to improve documentation and usability.
Enhanced the README.md to provide clearer guidance on HttpClient usage in .NET 9. Key updates include:
- Expanded "What You'll Learn" section to cover various patterns.
- Reformatted "Quick Start" for better readability.
- Simplified headings and refined descriptions for each pattern.
- Updated "Switching Between Patterns" for clarity on usage.
- Reorganized "Complete Pattern Library" for better presentation.
- Added notes on testing patterns and improved configuration examples.
- Reformatted "Production Checklist" and "Anti-Patterns" for readability.
- Clarified guidance on selecting appropriate patterns for applications.
- Updated project structure section for better organization.
Updated tests across multiple service files to enhance HTTP response handling, error logging, and robustness.
Modified `GetContactAsync` to return nullable types, standardized header casing in `CustomHeadersService`, and improved logging in `HttpCustomMessageHandlerService`.
Added JSON validation in `PerformanceOptimizationService` and implemented try-catch blocks in `ProductionReadyHttpClientService` for better error management.
Refactored `StreamService` for proper `HttpClient` initialization and memory efficiency during stream processing.
…us reports after comprehensive analysis and fixes
@randelramirez randelramirez merged commit 521e5a4 into main Aug 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants