38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using ElectionSystem.Api.Infrastructure.Persistence;
|
|
using ElectionSystem.Api.Modules.Organization;
|
|
using ElectionSystem.Api.Modules.Organization.Domain;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ElectionSystem.Api.Tests;
|
|
|
|
public sealed class RegionScopeServiceTests
|
|
{
|
|
[Fact]
|
|
public async Task Nationwide_scope_contains_every_active_administrative_region()
|
|
{
|
|
var options = new DbContextOptionsBuilder<ElectionDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.Options;
|
|
await using var context = new ElectionDbContext(options);
|
|
var province = Region("11", "省", AdministrativeRegionLevel.Province);
|
|
var disabled = Region("12", "停用省", AdministrativeRegionLevel.Province);
|
|
disabled.IsActive = false;
|
|
context.AddRange(province, disabled);
|
|
await context.SaveChangesAsync();
|
|
|
|
var scope = new RegionScopeService(context);
|
|
|
|
Assert.True(await scope.IsInRegionSubtreeAsync(province.Id, RegionScopeService.NationwideRegionId, CancellationToken.None));
|
|
Assert.False(await scope.IsInRegionSubtreeAsync(disabled.Id, RegionScopeService.NationwideRegionId, CancellationToken.None));
|
|
}
|
|
|
|
private static AdministrativeRegion Region(string code, string name, AdministrativeRegionLevel level) => new()
|
|
{
|
|
Code = code,
|
|
Name = name,
|
|
Level = level,
|
|
Source = "test",
|
|
SourceVersion = "1"
|
|
};
|
|
}
|