From cb15d309803ff76864b73c327c0df972ab8a8edb Mon Sep 17 00:00:00 2001 From: Chris Chen Date: Thu, 28 May 2026 16:33:27 -0700 Subject: [PATCH] refactor(giving): drop unused accessor from category service + add deactivate-missing test --- .../Services/GivingCategoryServiceTests.cs | 16 ++++++++++++---- API/ROLAC.API/Services/GivingCategoryService.cs | 3 +-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/API/ROLAC.API.Tests/Services/GivingCategoryServiceTests.cs b/API/ROLAC.API.Tests/Services/GivingCategoryServiceTests.cs index 6abdee5..b8c8ba7 100644 --- a/API/ROLAC.API.Tests/Services/GivingCategoryServiceTests.cs +++ b/API/ROLAC.API.Tests/Services/GivingCategoryServiceTests.cs @@ -35,7 +35,7 @@ public class GivingCategoryServiceTests public async Task CreateAsync_ReturnsId_AndDefaultsActive() { using var db = BuildDb(); - var svc = new GivingCategoryService(db, BuildAccessor()); + var svc = new GivingCategoryService(db); var id = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Tithe", Name_zh = "什一" }); @@ -49,7 +49,7 @@ public class GivingCategoryServiceTests public async Task GetAllAsync_ExcludesInactive_ByDefault() { using var db = BuildDb(); - var svc = new GivingCategoryService(db, BuildAccessor()); + var svc = new GivingCategoryService(db); var id1 = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Active" }); var id2 = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Gone" }); await svc.DeactivateAsync(id2); @@ -65,7 +65,7 @@ public class GivingCategoryServiceTests public async Task DeactivateAsync_SetsIsActiveFalse() { using var db = BuildDb(); - var svc = new GivingCategoryService(db, BuildAccessor()); + var svc = new GivingCategoryService(db); var id = await svc.CreateAsync(new CreateGivingCategoryRequest { Name_en = "Temp" }); await svc.DeactivateAsync(id); @@ -78,8 +78,16 @@ public class GivingCategoryServiceTests public async Task UpdateAsync_Throws_WhenMissing() { using var db = BuildDb(); - var svc = new GivingCategoryService(db, BuildAccessor()); + var svc = new GivingCategoryService(db); await Assert.ThrowsAsync(() => svc.UpdateAsync(999, new UpdateGivingCategoryRequest { Name_en = "X" })); } + + [Fact] + public async Task DeactivateAsync_Throws_WhenMissing() + { + using var db = BuildDb(); + var svc = new GivingCategoryService(db); + await Assert.ThrowsAsync(() => svc.DeactivateAsync(999)); + } } diff --git a/API/ROLAC.API/Services/GivingCategoryService.cs b/API/ROLAC.API/Services/GivingCategoryService.cs index 4689957..8b964ee 100644 --- a/API/ROLAC.API/Services/GivingCategoryService.cs +++ b/API/ROLAC.API/Services/GivingCategoryService.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using ROLAC.API.Data; using ROLAC.API.DTOs.Giving; @@ -9,7 +8,7 @@ namespace ROLAC.API.Services; public class GivingCategoryService : IGivingCategoryService { private readonly AppDbContext _db; - public GivingCategoryService(AppDbContext db, IHttpContextAccessor http) => _db = db; + public GivingCategoryService(AppDbContext db) => _db = db; public async Task> GetAllAsync(bool includeInactive) {