This commit reorganizes namespaces from `DigitalData.Core.Abstractions` and `DigitalData.Core.DTO` to `DigitalData.Core.Application.Interfaces` and `DigitalData.Core.Application.DTO`, improving maintainability and clarity. Updated using directives across multiple files to reflect the new structure, ensuring functionality remains intact. Project references in `DigitalData.Core.API.csproj` have been consolidated to include the new Application project. Introduced new classes and interfaces such as `BaseDTO`, `CookieConsentSettings`, `DataResult`, `Notice`, and `Result` to enhance data transfer and service result handling. Updated `IRepository`, `ICRUDRepository`, and `IEntityMapper` interfaces to facilitate CRUD operations and entity mapping. Added extension methods in `Extensions.cs` to improve repository usability. New interfaces for HTTP client services have been added, enhancing external API call handling. Overall, these changes reflect a significant restructuring aimed at improving organization and preparing for future development.
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using DigitalData.Core.Client;
|
|
using DigitalData.Core.Client.Interface;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DigitalData.Core.Tests.Client
|
|
{
|
|
[TestFixture]
|
|
public class BaseHttpClientServiceTests
|
|
{
|
|
private IServiceProvider _serviceProvider;
|
|
private IBaseHttpClientService _service;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
//_serviceProvider = new ServiceCollection()
|
|
// .AddHttpClientService("https://jsonplaceholder.typicode.com", "todos")
|
|
// .BuildServiceProvider();
|
|
|
|
_service = _serviceProvider.GetRequiredService<IBaseHttpClientService>();
|
|
}
|
|
|
|
[Test]
|
|
public async Task FetchJsonAsync_ShouldReturnJsonResponse_WithCorrectWithPath()
|
|
{
|
|
// Act
|
|
var expectedUserId = (int) await _service.FetchAsync(path: "/1", sendWithCookie: false, saveCookie: false)
|
|
.ThenAsync(res => res.Json())
|
|
.ThenAsync(todo => todo.userId);
|
|
|
|
// Assert
|
|
Assert.That(expectedUserId, Is.EqualTo(1), "The userId of the fetched JSON object should be 1.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task FetchJsonAsync_ShouldReturnJsonResponse_WithQueryParams()
|
|
{
|
|
var queryParams = new Dictionary<string, object?>
|
|
{
|
|
{ "id", "1" }
|
|
};
|
|
|
|
// Act
|
|
var dyn_id = await _service.FetchAsync(queryParams: queryParams, sendWithCookie: false, saveCookie: false)
|
|
.ThenAsync(res => res.JsonList())
|
|
.ThenAsync(todo => todo.FirstOrDefault()?.userId);
|
|
|
|
try
|
|
{
|
|
Assert.That((int)dyn_id, Is.EqualTo(1), "The userId of the fetched JSON object should be 1.");
|
|
}
|
|
catch (InvalidCastException)
|
|
{
|
|
// Handle the case where the cast is not possible
|
|
Assert.Fail("The id could not be cast to an integer.");
|
|
}
|
|
}
|
|
}
|
|
} |