Wrote tests for most services, applied EF core optimisations

This commit is contained in:
Khwezi Mngoma
2026-05-29 01:05:22 +02:00
parent 4e53ff8a37
commit 2546c34ffc
22 changed files with 793 additions and 297 deletions
@@ -0,0 +1,52 @@
using LiteCharms.Features.MidrandBooks.AuthorBooks;
using LiteCharms.Features.MidrandBooks.Tests.Common;
namespace LiteCharms.Features.MidrandBooks.Tests;
public class BooksServiceFeatureTests(Fixture fixture) : IClassFixture<Fixture>
{
private readonly BooksService bookService = fixture.Services.GetRequiredService<BooksService>();
[IntegrationFact]
public async Task CreateBookAsync_ShouldReturn_ResultWithBookId()
{
var result = await bookService.CreateBookAsync(1, 2, fixture.CancellationToken);
Assert.True(result.IsSuccess);
}
[IntegrationFact]
public async Task GetBookAsync_ShouldReturn_ResultWithBook()
{
var result = await bookService.GetBookAsync(1, fixture.CancellationToken);
Assert.True(result.IsSuccess);
Assert.NotNull(result.Value);
}
[IntegrationFact]
public async Task GetBooksByAuthorAsync_ShouldReturn_ResultWithAuthorBooks()
{
var result = await bookService.GetBooksByAuthorAsync(1, fixture.CancellationToken);
Assert.True(result.IsSuccess);
Assert.NotEmpty(result.Value);
}
[IntegrationFact]
public async Task GetPublishedBooksAsync_ShouldReturn_ResultWithBublishedBooks()
{
var result = await bookService.GetPublishedBooksAsync(0, 1000, fixture.CancellationToken);
Assert.True(result.IsSuccess);
Assert.NotEmpty(result.Value);
}
[IntegrationFact]
public async Task UpdateBookStatusAsync_ShouldReturn_ResultWithSuccess()
{
var result = await bookService.UpdateBookStatusAsync(1, true, fixture.CancellationToken);
Assert.True(result.IsSuccess);
}
}