From 7ca47e792b648567491e14590bce7b93936f1ba0 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Thu, 9 Jul 2026 15:44:52 +0900 Subject: [PATCH] Fix blog service tests and admin empty states --- .../BlogServiceTests.cs | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/TaxBaik.Application.Tests/BlogServiceTests.cs b/src/TaxBaik.Application.Tests/BlogServiceTests.cs index 579b58c..5cd92c4 100644 --- a/src/TaxBaik.Application.Tests/BlogServiceTests.cs +++ b/src/TaxBaik.Application.Tests/BlogServiceTests.cs @@ -13,7 +13,11 @@ public class BlogServiceTests [Fact] public async Task CreateAsync_WhenPublishedWithoutSeoTitle_ThrowsValidationException() { - var service = new BlogService(new FakeBlogPostRepository(), new MemoryCache(new MemoryCacheOptions()), new PassThroughValidator()); + var service = new BlogService( + new FakeBlogPostRepository(), + new FakeCategoryRepository(), + new MemoryCache(new MemoryCacheOptions()), + new PassThroughValidator()); await Assert.ThrowsAsync(() => service.CreateAsync(new CreateBlogPostDto { @@ -34,7 +38,11 @@ public class BlogServiceTests new BlogPost { Id = 1, Title = "같은 제목", Content = "본문", Slug = "같은-제목" } ] }; - var service = new BlogService(repository, new MemoryCache(new MemoryCacheOptions()), new PassThroughValidator()); + var service = new BlogService( + repository, + new FakeCategoryRepository(), + new MemoryCache(new MemoryCacheOptions()), + new PassThroughValidator()); var post = await service.CreateAsync(new CreateBlogPostDto { @@ -55,7 +63,11 @@ public class BlogServiceTests new BlogPost { Id = 1, Title = "삭제 대상", Content = "본문", Slug = "delete-me", IsPublished = true } ] }; - var service = new BlogService(repository, new MemoryCache(new MemoryCacheOptions()), new PassThroughValidator()); + var service = new BlogService( + repository, + new FakeCategoryRepository(), + new MemoryCache(new MemoryCacheOptions()), + new PassThroughValidator()); await service.DeleteAsync(1); @@ -131,6 +143,34 @@ public class BlogServiceTests public Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default) => Task.CompletedTask; } + private sealed class FakeCategoryRepository : ICategoryRepository + { + private readonly List _categories = + [ + new Category { Id = 1, Name = "사업자 세무", Slug = "business-tax", SortOrder = 1 } + ]; + + public Task> GetAllAsync(CancellationToken cancellationToken = default) => + Task.FromResult>(_categories); + + public Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) => + Task.FromResult(_categories.FirstOrDefault(x => x.Slug == slug)); + + public Task GetByIdAsync(int id, CancellationToken cancellationToken = default) => + Task.FromResult(_categories.FirstOrDefault(x => x.Id == id)); + + public Task CreateAsync(Category category, CancellationToken cancellationToken = default) + { + category.Id = _categories.Count + 1; + _categories.Add(category); + return Task.FromResult(category.Id); + } + + public Task UpdateAsync(Category category, CancellationToken cancellationToken = default) => Task.CompletedTask; + + public Task DeleteAsync(int id, CancellationToken cancellationToken = default) => Task.CompletedTask; + } + private sealed class PassThroughValidator : IValidator { public FluentValidation.Results.ValidationResult Validate(T instance) => new();