namespace TaxBaik.Application.Tests; using TaxBaik.Application.Services; using TaxBaik.Domain.Entities; using TaxBaik.Domain.Interfaces; using Xunit; public class CommonCodeServiceTests { [Fact] public async Task UpsertAsync_TrimsAndRejectsWhitespaceInCodeValue() { var repository = new FakeCommonCodeRepository(); var service = new CommonCodeService(repository); await Assert.ThrowsAsync(() => service.UpsertAsync(new CommonCode { CodeGroup = " CLIENT_STATUS ", CodeValue = "active code", CodeName = " 활성 " })); } [Fact] public async Task UpsertAsync_TrimsAndPersistsNormalizedValues() { var repository = new FakeCommonCodeRepository(); var service = new CommonCodeService(repository); await service.UpsertAsync(new CommonCode { CodeGroup = " CLIENT_STATUS ", CodeValue = "active", CodeName = " 활성 ", SortOrder = 10 }); var saved = Assert.Single(repository.SavedCodes); Assert.Equal("CLIENT_STATUS", saved.CodeGroup); Assert.Equal("active", saved.CodeValue); Assert.Equal("활성", saved.CodeName); } private sealed class FakeCommonCodeRepository : ICommonCodeRepository { public List SavedCodes { get; } = []; public Task> GetAllGroupsAsync(CancellationToken ct = default) => Task.FromResult>([]); public Task> GetByGroupAsync(string codeGroup, CancellationToken ct = default) => Task.FromResult>([]); public Task> GetAllActiveAsync(CancellationToken ct = default) => Task.FromResult>([]); public Task GetAsync(string codeGroup, string codeValue, CancellationToken ct = default) => Task.FromResult(null); public Task UpsertAsync(CommonCode code, CancellationToken ct = default) { SavedCodes.Add(new CommonCode { CodeGroup = code.CodeGroup, CodeValue = code.CodeValue, CodeName = code.CodeName, SortOrder = code.SortOrder, IsActive = code.IsActive }); return Task.CompletedTask; } public Task DeleteAsync(string codeGroup, string codeValue, CancellationToken ct = default) => Task.CompletedTask; } }