using LiteCharms.Features.MidrandBooks.Products; using LiteCharms.Features.MidrandBooks.Products.Models; using LiteCharms.Features.Models; using LiteCharms.Features.Tests.Common; namespace LiteCharms.Features.MidrandBooks.Tests; public class ProductServiceFeatureTests(Fixture fixture, ITestOutputHelper output) : IClassFixture { private readonly ProductService productService = fixture.Services.GetRequiredService(); [IntegrationFact] public async Task CheckProductStockAvailabilityAsync_ShouldReturn_ResultWithProductInventory() { var result = await productService.CheckProductStockAvailabilityAsync(1, 1, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotNull(result.Value); } [IntegrationFact] public async Task ReserveProductInventoryAsync_ShouldReturn_ResultWithSuccess() { var request = new ReserveStock { ProductId = 1, ProductPriceId = 1, Reservation = 100, }; var result = await productService.ReserveProductInventoryAsync(request, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.True(result.Value > 0); } [IntegrationFact] public async Task AllocateProductInventoryAsync_ShouldReturn_ResultWithSuccess() { var request = new AllocateStock { ProductId = 1, ProductPriceId = 1, Allocation = 500, }; var result = await productService.AllocateProductInventoryAsync(request, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.True(result.Value > 0); } [IntegrationFact] public async Task AddProductCategoryAsync_ShouldReturn_ResultWithId() { var result = await productService.AddProductCategoryAsync(1, 2, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task GetProductCategoriesAsync_ShouldReturn_ResultWithCategoryList() { var result = await productService.GetProductCategoriesAsync(1, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotEmpty(result.Value); } [IntegrationFact] public async Task DeleteProductCategoryAsync_ShouldReturn_ResultWithSuccess() { var result = await productService.DeleteProductCategoryAsync(1, 1, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task DeleteAllProductCategoriesAsync_ShouldReturn_ResultWithSuccess() { var result = await productService.DeleteAllProductCategoriesAsync(1, fixture.CancellationToken); Assert.True(result.IsSuccess); } [IntegrationFact] public async Task GetProductPriceAsync_ShouldReturn_ResultOneProductPrice() { var result = await productService.GetProductPriceAsync(2, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotNull(result.Value); output.WriteLine(JsonSerializer.Serialize(result.Value)); } [IntegrationFact] public async Task GetProductPricesAsync_ShouldReturn_ResultProductPriceList() { var result = await productService.GetProductPricesAsync(2, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotEmpty(result.Value); output.WriteLine(JsonSerializer.Serialize(result.Value)); } [IntegrationFact] public async Task SearchProductsAsync_ShouldReturn_ResultMatchingProducts() { var filter = new ProductFilter { Name = "system", Manufacturer = "techwave", SerialNumber = "2024", MinPrice = 10, MaxPrice = 30 }; var result = await productService.SearchProductsAsync(filter, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotEmpty(result.Value); output.WriteLine(JsonSerializer.Serialize(result.Value)); } [IntegrationFact] public async Task GetProductAsync_ShouldReturn_ResultOneProduct() { var result = await productService.GetProductAsync(2, fixture.CancellationToken); Assert.True(result.IsSuccess); Assert.NotNull(result.Value); output.WriteLine(JsonSerializer.Serialize(result.Value)); } [IntegrationFact] public async Task GetProductsAsync_ShouldReturn_ResultProducts() { 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_ShouldResurn_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], , 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}"); } }