feat(ministry): add Ministry entity, seed (10), and read endpoint
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using ROLAC.API.Data;
|
||||
using ROLAC.API.Data.Interceptors;
|
||||
using ROLAC.API.Entities;
|
||||
using ROLAC.API.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace ROLAC.API.Tests.Services;
|
||||
|
||||
public class MinistryServiceTests
|
||||
{
|
||||
private static AppDbContext BuildDb()
|
||||
{
|
||||
var claims = new[] { new Claim(ClaimTypes.NameIdentifier, "test-user") };
|
||||
var ctx = new DefaultHttpContext { User = new(new ClaimsIdentity(claims)) };
|
||||
var mock = new Mock<IHttpContextAccessor>();
|
||||
mock.Setup(x => x.HttpContext).Returns(ctx);
|
||||
return new AppDbContext(new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.AddInterceptors(new AuditSaveChangesInterceptor(mock.Object)).Options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_OrdersBySortOrder_AndExcludesInactive()
|
||||
{
|
||||
using var db = BuildDb();
|
||||
db.Ministries.AddRange(
|
||||
new Ministry { Name_en = "B", SortOrder = 2, IsActive = true },
|
||||
new Ministry { Name_en = "A", SortOrder = 1, IsActive = true },
|
||||
new Ministry { Name_en = "Z", SortOrder = 3, IsActive = false });
|
||||
await db.SaveChangesAsync();
|
||||
var svc = new MinistryService(db);
|
||||
|
||||
var active = await svc.GetAllAsync(includeInactive: false);
|
||||
var all = await svc.GetAllAsync(includeInactive: true);
|
||||
|
||||
Assert.Equal(2, active.Count);
|
||||
Assert.Equal("A", active[0].Name_en);
|
||||
Assert.Equal(3, all.Count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user