Expand server tests and enforce coverage

Consolidate server tests under tests/, upgrade them to .NET 10, and add CI coverage thresholds and reports. Expand API and application boundary coverage while fixing related issues in media handling, friend blocking, session crypto, presence, username validation, and local storage.
This commit is contained in:
Artemy
2026-10-24 15:30:32 +07:00
parent 33550d4fc9
commit 2d99c57a3b
161 changed files with 5515 additions and 8419 deletions
@@ -0,0 +1,28 @@
using Govor.Application.PingHandler;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
namespace Govor.Application.Tests.Users;
[TestFixture]
public class PingHandlerServiceTests
{
[Test]
public async Task PingUpdatesLastSeenAndThrottlesRepeatedRequests()
{
using var db = new TestDatabase();
using var cache = new MemoryCache(new MemoryCacheOptions());
var service = new PingHandlerService(db.Context, cache);
var old = DateTime.UtcNow.AddHours(-1);
await db.Context.Users.Where(u => u.Id == db.Alice).ExecuteUpdateAsync(s => s.SetProperty(u => u.WasOnline, old));
var before = DateTime.UtcNow;
await service.Ping(db.Alice);
var updated = await db.Context.Users.AsNoTracking().SingleAsync(u => u.Id == db.Alice);
Assert.That(updated.WasOnline, Is.GreaterThanOrEqualTo(before));
Assert.That(cache.TryGetValue($"LastPing_{db.Alice}", out DateTime _), Is.True);
await db.Context.Users.Where(u => u.Id == db.Alice).ExecuteUpdateAsync(s => s.SetProperty(u => u.WasOnline, old));
var storedBeforeThrottledPing = (await db.Context.Users.AsNoTracking().SingleAsync(u => u.Id == db.Alice)).WasOnline;
await service.Ping(db.Alice);
Assert.That((await db.Context.Users.AsNoTracking().SingleAsync(u => u.Id == db.Alice)).WasOnline, Is.EqualTo(storedBeforeThrottledPing));
}
}