Skip to content

REFACTOR: Refactor integration tests to use Refit API interfaces#104

Open
CesarD wants to merge 5 commits into
mainfrom
refactor/flurlhttp_to_refit
Open

REFACTOR: Refactor integration tests to use Refit API interfaces#104
CesarD wants to merge 5 commits into
mainfrom
refactor/flurlhttp_to_refit

Conversation

@CesarD
Copy link
Copy Markdown
Collaborator

@CesarD CesarD commented Apr 30, 2026

Description

Replaced Flurl.Http with strongly-typed Refit interfaces (ICompaniesApi, ICountriesApi, IFilesApi, IProductsApi) for all integration test HTTP calls. Removed Flurl.Http and ApiRoutes helper, updated test code to use Refit, and added a DelegatingHandler for bearer token authentication. Updated project files to include Refit dependency. This improves type safety, maintainability, and extensibility of the test suite.

Motivation and Context

The current implementation of the Integration Tests with Flurl.Http was resulting more convoluted than needed for creating the clients for calling the API endpoints. Replacing it with Refit results in a much leaner approach to implement any other additional route for the APIs.

How Has This Been Tested?

The Integration Tests have continue to run successfully.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Replaced Flurl.Http with strongly-typed Refit interfaces (ICompaniesApi, ICountriesApi, IFilesApi, IProductsApi) for all integration test HTTP calls. Removed Flurl.Http and ApiRoutes helper, updated test code to use Refit, and added a DelegatingHandler for bearer token authentication. Updated project files to include Refit dependency. This improves type safety, maintainability, and extensibility of the test suite.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 30, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedrefit@​10.1.610010090100100

View full report

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the backend integration test suite to replace Flurl-based HTTP calls and the ApiRoutes helper with strongly-typed Refit interfaces, improving type-safety and reducing boilerplate in test API interactions.

Changes:

  • Replaced Flurl HTTP calls in integration tests with Refit IApiResponse-based API interfaces.
  • Added Refit API interfaces (Companies/Countries/Files/Products) and updated test setup to create Refit clients (with optional bearer token handler).
  • Removed ApiRoutes.cs, removed Flurl package usage from central package versions, and added Refit package version/reference.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
.../IntegrationTests/Tests/ProductsTests.cs Switches product-related integration tests from Flurl to Refit APIs and adjusts header/content assertions.
.../IntegrationTests/Tests/FilesTests.cs Switches file upload test from Flurl multipart to Refit multipart (StreamPart).
.../IntegrationTests/Tests/CountriesTests.cs Switches country tests from Flurl to Refit APIs and uses response.Content.
.../IntegrationTests/Tests/CompaniesTests.cs Switches company tests from Flurl to Refit APIs and updates Location assertions.
.../IntegrationTests/IntegrationTest.cs Replaces Flurl client factory with GetApi<T>() Refit client creation + optional bearer token handler.
.../IntegrationTests/Apis/IProductsApi.cs Adds Refit contract for Products endpoints (query/get/create/update/delete/download).
.../IntegrationTests/Apis/IFilesApi.cs Adds Refit contract for multipart file upload.
.../IntegrationTests/Apis/ICountriesApi.cs Adds Refit contract for Countries endpoints.
.../IntegrationTests/Apis/ICompaniesApi.cs Adds Refit contract for Companies endpoints.
.../IntegrationTests/ApiRoutes.cs Removes Flurl-based route builder helper.
.../IntegrationTests/Monaco.Template.Backend.IntegrationTests.csproj Updates test project dependencies (removes Flurl reference, adds Refit).
.../Directory.Packages.props Removes centralized Flurl.Http version and adds centralized Refit version.
.../.template.config/template.json Updates template source modifiers/exclusions for newly introduced Refit API interface files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Content/Backend/Solution/Directory.Packages.props
Comment thread src/Content/Backend/Solution/.template.config/template.json
CesarD added 2 commits April 30, 2026 19:58
- Reuse a private HttpClient instance in IntegrationTest for API calls when apiService is enabled, improving resource management and cleanup.
- Refactor GetApi<T> and CreateHttpClient methods for clarity and efficiency.
- Update DisposeAsync to properly dispose of the HttpClient.
- Change template.json to exclude all Apis/ files in integration tests when apiService is false.
- Refine Content-Disposition assertions in ProductsTests for more precise validation.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the backend integration test suite to replace Flurl-based HTTP calls and the ApiRoutes helper with strongly-typed Refit interfaces, centralizing client creation in IntegrationTest (including optional bearer-token auth).

Changes:

  • Replace Flurl HTTP calls in integration tests with Refit IApiResponse<T>-based APIs.
  • Add Refit API interfaces (ICompaniesApi, ICountriesApi, IFilesApi, IProductsApi) and remove ApiRoutes.cs.
  • Update test infrastructure (IntegrationTest) and package references to support Refit-based clients.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/ProductsTests.cs Switch product integration tests from Flurl route calls to IProductsApi Refit interface.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/FilesTests.cs Switch upload test to IFilesApi and Refit multipart upload (StreamPart).
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/CountriesTests.cs Switch countries tests to ICountriesApi Refit interface.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/CompaniesTests.cs Switch companies tests to ICompaniesApi Refit interface.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Monaco.Template.Backend.IntegrationTests.csproj Update test project dependencies (adds Refit, changes Flurl reference).
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/IntegrationTest.cs Introduce GetApi<T>() Refit client factory and bearer-token DelegatingHandler.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/IProductsApi.cs New Refit interface for Products endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/IFilesApi.cs New Refit interface for Files endpoints (multipart).
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/ICountriesApi.cs New Refit interface for Countries endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/ICompaniesApi.cs New Refit interface for Companies endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/ApiRoutes.cs Remove Flurl-based routes helper.
src/Content/Backend/Solution/Directory.Packages.props Update centrally managed package versions (adds Refit, changes Flurl package entry).
src/Content/Backend/Solution/.template.config/template.json Update template exclusions to account for new Apis/* folder.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Content/Backend/Solution/Directory.Packages.props
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the backend integration test suite to replace ad-hoc Flurl-based HTTP calls with strongly-typed Refit interfaces, centralizing API client creation and bearer token attachment.

Changes:

  • Replaced Flurl request construction in integration tests with Refit IApiResponse calls via GetApi<T>().
  • Added Refit API interfaces (ICompaniesApi, ICountriesApi, IFilesApi, IProductsApi) and removed the ApiRoutes helper.
  • Updated integration test project/package references and template exclusions to reflect the new structure.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/ProductsTests.cs Switches product test HTTP calls from Flurl to IProductsApi Refit interface.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/FilesTests.cs Switches file upload test from Flurl multipart to Refit StreamPart.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/CountriesTests.cs Switches country queries from Flurl to ICountriesApi.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Tests/CompaniesTests.cs Switches company tests from Flurl to ICompaniesApi and tightens header assertions.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Monaco.Template.Backend.IntegrationTests.csproj Updates test project dependencies (drops Flurl.Http direct ref, adds Refit conditionally).
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/IntegrationTest.cs Introduces GetApi<T>() using Refit and a delegating handler for bearer tokens; disposes cached HttpClient.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/IProductsApi.cs Adds Refit interface for Products endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/IFilesApi.cs Adds Refit interface for Files endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/ICountriesApi.cs Adds Refit interface for Countries endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/Apis/ICompaniesApi.cs Adds Refit interface for Companies endpoints.
src/Content/Backend/Solution/Monaco.Template.Backend.IntegrationTests/ApiRoutes.cs Removes the Flurl-based route builder helper.
src/Content/Backend/Solution/Directory.Packages.props Replaces centrally managed Flurl.Http version with Flurl and adds Refit.
src/Content/Backend/Solution/.template.config/template.json Updates template exclusions to account for new Apis/ folder and removed ApiRoutes.cs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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