Trial - boosting prospect grid loading performance

This commit is contained in:
troogs
2026-09-20 11:09:44 +02:00
parent 8b298b37c7
commit b33f9f6c52
15 changed files with 688 additions and 73 deletions
@@ -0,0 +1,74 @@
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Contracts.Enums;
using FoodsharingSiegen.Contracts.Model;
using FoodsharingSiegen.Server.Auth;
using FoodsharingSiegen.Server.Data;
using FoodsharingSiegen.Server.Data.Service;
using FoodsharingSiegen.Server.Service;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.JSInterop;
using Moq;
using Xunit;
namespace FoodsharingSiegen.Tests;
public class ProspectServiceTests
{
private static FsContext CreateInMemoryContext(string dbName)
{
var options = new DbContextOptionsBuilder<FsContext>()
.UseInMemoryDatabase(databaseName: dbName)
.Options;
return new FsContext(options);
}
private static AuthService CreateAuthService(FsContext context)
{
var mockJsRuntime = new Mock<IJSRuntime>();
var localStorageService = new LocalStorageService(mockJsRuntime.Object);
var authStateProvider = new Mock<AuthenticationStateProvider>();
var mailService = new Mock<IMailService>();
var appSettings = new Mock<IOptions<AppSettings>>();
appSettings.Setup(x => x.Value).Returns(new AppSettings());
return new AuthService(context, localStorageService, authStateProvider.Object, mailService.Object, appSettings.Object);
}
[Fact]
public async Task GetProspectsAsync_RespectsSkipAndTake()
{
var dbName = Guid.NewGuid().ToString();
using var context = CreateInMemoryContext(dbName);
var authService = CreateAuthService(context);
var auditService = new AuditService(context, authService);
var prospectService = new ProspectService(context, authService, auditService);
for (var i = 0; i < 5; i++)
{
context.Prospects!.Add(new Prospect
{
Id = Guid.NewGuid(),
Name = $"Prospect {i}",
Modified = DateTime.UtcNow.AddDays(-i),
Interactions = new List<Interaction>()
});
}
await context.SaveChangesAsync();
var result = await prospectService.GetProspectsAsync(new GetProspectsParameter
{
Skip = 1,
Take = 2,
IncludeDeleted = true
});
Assert.True(result.Success);
Assert.Equal(2, result.Data.Count);
Assert.Equal("Prospect 1", result.Data[0].Name);
Assert.Equal("Prospect 2", result.Data[1].Name);
}
}