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,38 @@
using Govor.API.Common.Extensions;
using Govor.Application.PushNotifications;
using Govor.Application.PushNotifications.Providers;
using Govor.Application.Storage;
using Govor.Domain;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Moq;
namespace Govor.API.Tests.Unit.Common;
[TestFixture]
public class ConfigurationTests
{
[TestCase(false)] [TestCase(true)]
public void DatabaseConfigurationUsesPostgresAndHonorsDetailedErrors(bool detailed)
{
var config=new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string,string?>{{"ConnectionStrings:GovorDbContext","Host=localhost;Database=configuration_tests;Username=tests"},{"Database:EnableDetailedErrors",detailed.ToString()}}).Build();
var services=new ServiceCollection();services.AddGovorDbContext(config);
using var provider=services.BuildServiceProvider();using var scope=provider.CreateScope();var db=scope.ServiceProvider.GetRequiredService<GovorDbContext>();
Assert.That(db.Database.ProviderName,Is.EqualTo("Npgsql.EntityFrameworkCore.PostgreSQL"));
Assert.That(db.Database.CreateExecutionStrategy().RetriesOnFailure,Is.True);
var options=scope.ServiceProvider.GetRequiredService<DbContextOptions<GovorDbContext>>();
Assert.That(options.FindExtension<Microsoft.EntityFrameworkCore.Infrastructure.CoreOptionsExtension>()!.DetailedErrorsEnabled,Is.EqualTo(detailed));
}
[Test]
public void DisabledFirebaseAndLocalStorageResolveThroughProductionRegistration()
{
var services=new ServiceCollection();services.AddLogging();
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string,string?>{{"Firebase:Enabled","false"}}).Build());
var environment=new Mock<IWebHostEnvironment>();environment.SetupGet(x=>x.ContentRootPath).Returns(Path.GetTempPath());services.AddSingleton(environment.Object);
services.AddServices();using var provider=services.BuildServiceProvider();using var scope=provider.CreateScope();
Assert.That(scope.ServiceProvider.GetRequiredService<IStorageService>(),Is.TypeOf<LocalStorageService>());
Assert.That(scope.ServiceProvider.GetRequiredService<IPushNotificationProvider>(),Is.TypeOf<NullPushProvider>());
}
}