diff --git a/DoliMiddlewareApi/Program.cs b/DoliMiddlewareApi/Program.cs index e43ad64..0b9557a 100644 --- a/DoliMiddlewareApi/Program.cs +++ b/DoliMiddlewareApi/Program.cs @@ -22,7 +22,8 @@ builder.Services.AddSwaggerGen(); // Typed Client - Inyecta HttpClient directamente en DolibarrApiClient -builder.Services.AddHttpClient(client => +// Registra la interfaz para poder hacer mock en tests +builder.Services.AddHttpClient(client => { client.BaseAddress = new Uri(builder.Configuration["Dolibarr:ApiUrl"]!); client.DefaultRequestHeaders.Add("DOLAPIKEY", builder.Configuration["Dolibarr:ApiKey"]!); diff --git a/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs b/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs index e1f23a0..f87b200 100644 --- a/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs +++ b/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs @@ -3,7 +3,7 @@ using DoliMiddlewareApi.Exceptions; namespace DoliMiddlewareApi.Services.Clients; -public class DolibarrApiClient +public class DolibarrApiClient : IDolibarrApiClient { private readonly HttpClient _httpClient; diff --git a/DoliMiddlewareApi/Services/Clients/IDolibarrApiClient.cs b/DoliMiddlewareApi/Services/Clients/IDolibarrApiClient.cs new file mode 100644 index 0000000..07c7ec1 --- /dev/null +++ b/DoliMiddlewareApi/Services/Clients/IDolibarrApiClient.cs @@ -0,0 +1,9 @@ +namespace DoliMiddlewareApi.Services.Clients; + +public interface IDolibarrApiClient +{ + Task GetResourceAsync(string endpoint) where T : class; + Task> GetCollectionAsync(string endpoint) where T : class; + Task PostAsync(string endpoint, object requestBody); + Task PutAsync(string endpoint, object requestBody); +} diff --git a/DoliMiddlewareApi/Services/InvoiceService.cs b/DoliMiddlewareApi/Services/InvoiceService.cs index f00e2dc..73a8201 100644 --- a/DoliMiddlewareApi/Services/InvoiceService.cs +++ b/DoliMiddlewareApi/Services/InvoiceService.cs @@ -10,9 +10,9 @@ namespace DoliMiddlewareApi.Services; public class InvoiceService { - private readonly DolibarrApiClient _apiClient; + private readonly IDolibarrApiClient _apiClient; - public InvoiceService(DolibarrApiClient apiClient) + public InvoiceService(IDolibarrApiClient apiClient) { _apiClient = apiClient; }