Path: redb/redb.Tests.Integration/Tests/Base/UserConfigurationServiceTestsBase.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Base/UserConfigurationServiceTestsBase.cs ---- #pragma warning disable CS0618 // implements or uses the deprecated object permissions and roles (RedbDeprecation) using Microsoft.Extensions.DependencyInjection; using redb.Core; using redb.Core.Configuration; using redb.Core.Models.Configuration; using redb.Core.Models.Roles; using redb.Core.Models.Users; namespace redb.Tests.Integration.Tests.Base; /// /// The user configuration service is the core class on every provider and takes its statements from the dialect. /// PostgreSQL and SQLite registered copies of it with the SQL written into them. /// public abstract class UserConfigurationServiceTestsBase { protected readonly IRedbService Redb; private readonly IServiceProvider _services; protected UserConfigurationServiceTestsBase(IRedbService redb, IServiceProvider services) { Redb = redb; _services = services; } [Fact] public void TheRegisteredService_IsTheCoreClass() { using var scope = _services.CreateScope(); scope.ServiceProvider.GetRequiredService().Should().BeOfType(); } /// /// A role configuration and a user configuration merge, the user's over the role's; clearing the user's falls back /// to the role's, clearing the role's falls back further. Writes a configuration id and NULL for both, and reads /// the roles of the user and the users of a role. /// [Fact] public async Task RoleAndUserConfigurations_Merge_AndClearingFallsBack() { using var scope = _services.CreateScope(); var service = scope.ServiceProvider.GetRequiredService(); var tag = Guid.NewGuid().ToString("N")[..10]; var user = await Redb.UserProvider.CreateUserAsync(new CreateUserRequest { Login = "ucfg_" + tag, Name = "ucfg_" + tag, Password = "p-" + tag }); var role = await Redb.RoleProvider.CreateRoleAsync(new CreateRoleRequest { Name = "ucfg-role-" + tag }); (await Redb.RoleProvider.AssignUserToRoleAsync(user, role)).Should().BeTrue(); var roleConfig = await service.CreateConfigurationAsync("ucfg-role-" + tag, new UserConfigurationProps { MaxBatchSize = 111, MaxLoadDepth = 7 }); var userConfig = await service.CreateConfigurationAsync("ucfg-user-" + tag, new UserConfigurationProps { MaxBatchSize = 222 }); await service.SetRoleConfigurationAsync(role.Id, roleConfig.id); await service.SetUserConfigurationAsync(user.Id, userConfig.id); var both = await service.GetEffectiveConfigurationAsync(user.Id); both.MaxBatchSize.Should().Be(222, "the user's configuration wins over the role's"); both.MaxLoadDepth.Should().Be(7, "the role's configuration fills what the user's leaves out"); await service.SetUserConfigurationAsync(user.Id, null); var roleOnly = await service.GetEffectiveConfigurationAsync(user.Id); roleOnly.MaxBatchSize.Should().Be(111, "with the user's cleared, the role's applies"); await service.SetRoleConfigurationAsync(role.Id, null); var neither = await service.GetEffectiveConfigurationAsync(user.Id); neither.MaxLoadDepth.Should().NotBe(7, "the role's configuration is cleared and the cache of its users dropped"); } [Fact] public async Task SetConfiguration_OfAnUnknownUserOrRole_Throws() { using var scope = _services.CreateScope(); var service = scope.ServiceProvider.GetRequiredService(); await service.Invoking(s => s.SetUserConfigurationAsync(long.MaxValue - 7, null)).Should().ThrowAsync(); await service.Invoking(s => s.SetRoleConfigurationAsync(long.MaxValue - 7, null)).Should().ThrowAsync(); } }