Fix blog service tests and admin empty states
TaxBaik CI/CD / build-and-deploy (push) Successful in 55s
TaxBaik CI/CD / build-and-deploy (push) Successful in 55s
This commit is contained in:
@@ -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<CreateBlogPostDto>());
|
||||
var service = new BlogService(
|
||||
new FakeBlogPostRepository(),
|
||||
new FakeCategoryRepository(),
|
||||
new MemoryCache(new MemoryCacheOptions()),
|
||||
new PassThroughValidator<CreateBlogPostDto>());
|
||||
|
||||
await Assert.ThrowsAsync<TaxBaik.Application.Services.ValidationException>(() => 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<CreateBlogPostDto>());
|
||||
var service = new BlogService(
|
||||
repository,
|
||||
new FakeCategoryRepository(),
|
||||
new MemoryCache(new MemoryCacheOptions()),
|
||||
new PassThroughValidator<CreateBlogPostDto>());
|
||||
|
||||
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<CreateBlogPostDto>());
|
||||
var service = new BlogService(
|
||||
repository,
|
||||
new FakeCategoryRepository(),
|
||||
new MemoryCache(new MemoryCacheOptions()),
|
||||
new PassThroughValidator<CreateBlogPostDto>());
|
||||
|
||||
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<Category> _categories =
|
||||
[
|
||||
new Category { Id = 1, Name = "사업자 세무", Slug = "business-tax", SortOrder = 1 }
|
||||
];
|
||||
|
||||
public Task<IEnumerable<Category>> GetAllAsync(CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult<IEnumerable<Category>>(_categories);
|
||||
|
||||
public Task<Category?> GetBySlugAsync(string slug, CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(_categories.FirstOrDefault(x => x.Slug == slug));
|
||||
|
||||
public Task<Category?> GetByIdAsync(int id, CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(_categories.FirstOrDefault(x => x.Id == id));
|
||||
|
||||
public Task<int> 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<T> : IValidator<T>
|
||||
{
|
||||
public FluentValidation.Results.ValidationResult Validate(T instance) => new();
|
||||
|
||||
Reference in New Issue
Block a user