Wrote tests for most services, applied EF core optimisations
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using LiteCharms.Features.MidrandBooks.Authors;
|
||||
using LiteCharms.Features.MidrandBooks.Authors.Models;
|
||||
using LiteCharms.Features.MidrandBooks.Tests.Common;
|
||||
using LiteCharms.Features.Models;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Tests;
|
||||
|
||||
public class AuthorServiceFeatureTests(Fixture fixture, ITestOutputHelper output) : IClassFixture<Fixture>
|
||||
{
|
||||
private readonly AuthorService authorService = fixture.Services.GetRequiredService<AuthorService>();
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CreateAuthorAsync_ShouldReturn_ResultWithAuthorId()
|
||||
{
|
||||
var request = new CreateAuthor
|
||||
{
|
||||
Name = "John",
|
||||
LastName = "Doe",
|
||||
Company = "Solo Publishers",
|
||||
Email = "solo@publishers.co.za",
|
||||
PublisherType = PublisherTypes.Independent,
|
||||
ImageUrl = ""
|
||||
};
|
||||
|
||||
var result = await authorService.CreateAuthorAsync(request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateAuthorAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var request = new UpdateAuthor
|
||||
{
|
||||
Name = "Jane",
|
||||
LastName = "Doe",
|
||||
Company = "Solo Publishers",
|
||||
Email = "solo@publishers.co.za",
|
||||
PublisherType = PublisherTypes.Independent,
|
||||
ImageUrl = ""
|
||||
};
|
||||
|
||||
var result = await authorService.UpdateAuthorAsync(1, request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetAuthors_ShouldReturn_ResultWithAuthorList()
|
||||
{
|
||||
var range = new DateRange
|
||||
{
|
||||
From = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-7)),
|
||||
To = DateOnly.FromDateTime(DateTime.UtcNow),
|
||||
MaxRecords = 1000
|
||||
};
|
||||
|
||||
var result = await authorService.GetAuthorsAsync(range, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotEmpty(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetAuthorAsync_ShouldReturn_ResultWithAuthor()
|
||||
{
|
||||
var result = await authorService.GetAuthorAsync(1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotNull(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateAuthorStatusAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var result = await authorService.UpdateAuthorStatusAsync(1, true, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user