投票范围修改
This commit is contained in:
1 parent
1e0652211b
commit
6d765ac8f3
9 files changed
+128
-37
No files matched your search
@@ -0,0 +1,37 @@
|
||||
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"
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user