Implemented order service tests
This commit is contained in:
@@ -4,7 +4,7 @@ public sealed record CreateOrder(decimal TotalPrice, string? Notes);
|
||||
|
||||
public sealed record CreateOrderItem(long AuthorBookId, long ProductPriceId, int Quantity);
|
||||
|
||||
public sealed record CreateShipping(long OrderId, long AddressId, long ShippingProviderId, string? TrackingNumber);
|
||||
public sealed record CreateShipping(long AddressId, long ShippingProviderId, string? TrackingNumber = null);
|
||||
|
||||
public sealed record CreateShippingProvider(ShippingProviderTypes Type, string Name, decimal Price, string TrackingUrl);
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<Result> AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default)
|
||||
public async ValueTask<Result<long>> AddShippingToOrderAsync(long orderId, CreateShipping request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -371,7 +371,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<Result> CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default)
|
||||
public async ValueTask<Result<long>> CreateShippingProviderAsync(CreateShippingProvider request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -382,6 +382,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
|
||||
|
||||
var shippingProvider = context.ShippingProviders.Add(new Entities.ShippingProvider
|
||||
{
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
Name = request.Name,
|
||||
Type = request.Type,
|
||||
Price = request.Price,
|
||||
@@ -389,7 +390,7 @@ public sealed class OrderService(IDbContextFactory<MidrandBooksDbContext> contex
|
||||
});
|
||||
|
||||
return await context.SaveChangesAsync(cancellationToken) > 0
|
||||
? Result.Ok()
|
||||
? Result.Ok(shippingProvider.Entity.Id)
|
||||
: Result.Fail("Failed to create shipping provider.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user