Refactored database registration to allow postgres to use internal representations for afster performance
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using LiteCharms.Features.Extensions;
|
||||
using LiteCharms.Features.MidrandBooks.Abstractions;
|
||||
using LiteCharms.Features.MidrandBooks.Extensions;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Tests;
|
||||
@@ -11,6 +12,10 @@ public class Fixture : IDisposable
|
||||
|
||||
public IMediator Mediator { get; set; }
|
||||
|
||||
private readonly CancellationTokenSource cancellationTokenSource = new();
|
||||
|
||||
public CancellationToken CancellationToken => cancellationTokenSource.Token;
|
||||
|
||||
public Fixture()
|
||||
{
|
||||
Configuration = new ConfigurationBuilder()
|
||||
@@ -23,12 +28,12 @@ public class Fixture : IDisposable
|
||||
Services = new ServiceCollection()
|
||||
.AddMediator()
|
||||
.AddLogging()
|
||||
//.AddMidrandShopServices()
|
||||
.AddEmailServiceBus()
|
||||
.AddGarageS3(Configuration)
|
||||
.AddMidrandShopDatabase(Configuration)
|
||||
.AddEmailServices(Configuration)
|
||||
.AddSingleton(Configuration)
|
||||
.AddShopServices()
|
||||
.BuildServiceProvider();
|
||||
|
||||
Mediator = Services.GetRequiredService<IMediator>();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace LiteCharms.Features.MidrandBooks.Tests;
|
||||
|
||||
public class IntegrationFactAttribute : FactAttribute
|
||||
{
|
||||
public IntegrationFactAttribute()
|
||||
{
|
||||
if(!Debugger.IsAttached)
|
||||
Skip = "This test requires the debugger to be attached.";
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Diagnostics" />
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using LiteCharms.Features.MidrandBooks.Products;
|
||||
using LiteCharms.Features.MidrandBooks.Products.Models;
|
||||
using LiteCharms.Features.Models;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LiteCharms.Features.MidrandBooks.Tests;
|
||||
|
||||
public class ProductServiceFeatureTest(Fixture fixture, ITestOutputHelper output) : IClassFixture<Fixture>
|
||||
{
|
||||
private readonly ProductService productService = fixture.Services.GetRequiredService<ProductService>();
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task GetProductsAsync_ShouldReturn_RetultProducts()
|
||||
{
|
||||
var range = new DateRange
|
||||
{
|
||||
From = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(-7)),
|
||||
To = DateOnly.FromDateTime(DateTime.UtcNow),
|
||||
MaxRecords = 1000
|
||||
};
|
||||
|
||||
var result = await productService.GetProductsAsync(0, range, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.NotEmpty(result.Value);
|
||||
|
||||
output.WriteLine(JsonSerializer.Serialize(result.Value));
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateProductStatusAsync_ShouldReturn_ResultTrue()
|
||||
{
|
||||
var result = await productService.UpdateProductStatusAsync(2, true, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task UpdateProductPriceStatusAsync_ShouldReturn_ResultTrue()
|
||||
{
|
||||
var result = await productService.UpdateProductPriceStatusAsync(2, true, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CreateProductPriceAsync_Should_Return_NewProductPriceId()
|
||||
{
|
||||
var request = new CreateProductPrice
|
||||
{
|
||||
Amount = 29.99m,
|
||||
Discount = 0.00m
|
||||
};
|
||||
|
||||
var result = await productService.CreateProductPriceAsync(2, request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess, "Product price creation should be successful.");
|
||||
Assert.True(result.Value > 0, "New ProductPriceId should be greater than 0.");
|
||||
|
||||
output.WriteLine($"Created ProductPriceId: {result.Value}");
|
||||
}
|
||||
|
||||
[IntegrationFact]
|
||||
public async Task CreateProductAsync_Result_Returns_ProductId()
|
||||
{
|
||||
var request = new CreateProduct
|
||||
{
|
||||
Name = "Systems Rewired",
|
||||
Description = "[Design], <Code>, AND /CHAORS/ IN ***SYNC***",
|
||||
Summary = "A comprehensive guide to systems thinking and design.",
|
||||
ImageUrl = "https://bookshop.cdn.khongisa.co.za/design/2bf1f9a2-7b25-4fcf-9aa7-08941ea21e6c_1764838499686.webp",
|
||||
Type = ProductTypes.Book,
|
||||
Categories = ["Systems Thinking", "Design", "Programming"],
|
||||
Metadata = new ProductMetadata
|
||||
{
|
||||
CopyrightInfo = "© 2024 John Doe. All rights reserved.",
|
||||
ManufactureDate = "2024-06-01",
|
||||
Manufacturer = "TechWave Publishing",
|
||||
SerialNumber = "SR-2024-0001"
|
||||
}
|
||||
};
|
||||
|
||||
var result = await productService.CreateProductAsync(request, fixture.CancellationToken);
|
||||
|
||||
Assert.True(result.IsSuccess, "Product creation should be successful.");
|
||||
Assert.True(result.Value > 0, "ProductId should be greater than 0.");
|
||||
|
||||
output.WriteLine($"Created ProductId: {result.Value}");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,6 @@
|
||||
"BucketName": "bookshop",
|
||||
"CdnBaseUrl": "https://bookshop.cdn.khongisa.co.za"
|
||||
},
|
||||
"BookshopQuotesS3Settings": {
|
||||
"ServiceUrl": "http://192.168.1.177:30900",
|
||||
"Region": "garage",
|
||||
"BucketName": "bookshop.quotes",
|
||||
"CdnBaseUrl": "https://bookshop.quotes.cdn.khongisa.co.za"
|
||||
},
|
||||
"Email": {
|
||||
"Credentials": {
|
||||
"Username": "shop@litecharms.co.za"
|
||||
|
||||
Reference in New Issue
Block a user