Files
monorepo/LCU.API.Internal.Document/LCU.API.Internal.Document.PerformanceTest/API/DirectInMemoryDocumentApi.cs
T
2026-03-13 09:11:35 -05:00

49 lines
2.0 KiB
C#

using LCU.API.Internal.Document.Configurations;
using LCU.API.Internal.Document.Controllers;
using LCU.API.Internal.Document.PerformanceTest.DB;
using LCU.API.Internal.DocumentLib.Configurations;
using LCU.API.Internal.DocumentLib.DataAccess;
using LCU.Library.Internal.DocumentModels.Requests.Search;
using LCU.Library.Internal.DocumentModels.Responses;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Newtonsoft.Json;
namespace LCU.API.Internal.Document.PerformanceTest.API;
public class DirectInMemoryDocumentApi : IDocumentApi
{
private IServiceProvider? _services;
public Task SpinUp(DatabaseConfiguration databaseConfiguration)
{
if (_services is not null) return Task.CompletedTask;
var services = new ServiceCollection();
ServiceRegistrations.AddDocumentServices(services);
ServiceRegistrations.AddDocumentDataAccesses(services);
ServiceRegistrations.AddDocumentRepositories(services);
services.AddTransient<DocumentController>();
services.TryAddSingleton(databaseConfiguration);
services.AddSingleton<IBlobStorageClient, NullBlobStorageClient>();
services.AddSingleton<ApiConfiguration>();
services.AddSingleton<NotificationApiConfiguration>();
_services = services.BuildServiceProvider();
return Task.CompletedTask;
}
public async Task<IList<DocumentInformationResponse>> GetDocumentInformationByFilter(DocumentInformationFilter filter)
{
var controller = _services?.GetRequiredService<DocumentController>() ?? throw new InvalidOperationException();
var response = await controller.PostDocumentInformationByFilter(new DocumentInformationFilteredSearch{ Filter = filter });
return (response as OkObjectResult)?.Value as IList<DocumentInformationResponse> ?? throw new InvalidOperationException();
}
public Task TearDown()
{
return Task.CompletedTask;
}
}