Wrote tests for most services, applied EF core optimisations
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
using LiteCharms.Features.MidrandBooks.Orders;
|
||||
using LiteCharms.Features.MidrandBooks.Orders.Models;
|
||||
using LiteCharms.Features.MidrandBooks.Tests.Common;
|
||||
using LiteCharms.Features.Models;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Tests;
|
||||
|
||||
public class OrderServiceFeatureTests(Fixture fixture) : IClassFixture<Fixture>
|
||||
{
|
||||
private readonly OrderService orderService = fixture.Services.GetRequiredService<OrderService>();
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CreateOrderAsync_ShouldReturn_ResultWithOrderId()
|
||||
{
|
||||
var request = new CreateOrder(250, "At the intercomm, dial 1 then option 2");
|
||||
|
||||
var result = await orderService.CreateOrderAsync(1, request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task AddItemToOrderAsync_ShouldReturn_ResultWithOrderItemId()
|
||||
{
|
||||
var request = new CreateOrderItem(1, 1, 2);
|
||||
|
||||
var result = await orderService.AddItemToOrderAsync(1, request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.True(result.Value > 0);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task AddItemsToOrderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var requests = new List<CreateOrderItem>
|
||||
{
|
||||
new(1, 1, 1),
|
||||
new(1, 1, 3)
|
||||
};
|
||||
|
||||
var result = await orderService.AddItemsToOrderAsync(1, [.. requests], fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task RemoveItemFromOrderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var result = await orderService.RemoveItemFromOrderAsync(1, 5, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task ClearOrderItemsAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var result = await orderService.ClearOrderItemsAsync(1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CancelOrderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var result = await orderService.CancelOrderAsync(1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetOrderAsync_ShouldReturn_ResultWithOrder()
|
||||
{
|
||||
var result = await orderService.GetOrderAsync(1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotNull(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetOrdersByCustomerAsync_ShouldReturn_ResultWithOrderList()
|
||||
{
|
||||
var result = await orderService.GetOrdersByCustomerAsync(1, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotEmpty(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetOrdersAsync_ShouldReturn_ResultWithOrderList()
|
||||
{
|
||||
var range = new DateRange
|
||||
{
|
||||
From = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-7)),
|
||||
To = DateOnly.FromDateTime(DateTime.UtcNow),
|
||||
MaxRecords = 1000
|
||||
};
|
||||
|
||||
var result = await orderService.GetOrdersAsync(range, 0, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotEmpty(result.Value);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateOrderStatusAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
var result = await orderService.UpdateOrderStatusAsync(1, OrderStatus.Pending, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task AddShippingToOrderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateShippingStatusAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetShippingByOrderIdAsync_ShouldReturn_ResultWithShipping()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task RemoveShippingFromOrderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateShippingTrackingNumberAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CreateShippingProviderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetShippingProvidersAsync_ShouldReturn_ResultWithShippingProviderList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetShippingProviderAsync_ShouldReturn_ResultWithShippingProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateShippingProviderAsync_ShouldReturn_ResultWithSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user