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(); services.TryAddSingleton(databaseConfiguration); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); _services = services.BuildServiceProvider(); return Task.CompletedTask; } public async Task> GetDocumentInformationByFilter(DocumentInformationFilter filter) { var controller = _services?.GetRequiredService() ?? throw new InvalidOperationException(); var response = await controller.PostDocumentInformationByFilter(new DocumentInformationFilteredSearch{ Filter = filter }); return (response as OkObjectResult)?.Value as IList ?? throw new InvalidOperationException(); } public Task TearDown() { return Task.CompletedTask; } }