diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs index 8e0760d1..aa56abcb 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Buyers/EfCoreBuyerRepository.cs @@ -1,5 +1,9 @@ using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -11,4 +15,18 @@ public class EfCoreBuyerRepository : EfCoreRepository InsertAsync(Buyer entity, bool autoSave = false, + CancellationToken cancellationToken = new CancellationToken()) + { + var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); + await EnsurePropertyLoadedAsync(newEntity, query => query.PaymentType, cancellationToken); + return newEntity; + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()) + .Include(q => q.PaymentType); + } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs index a1b3ec37..d63ef3cd 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.EntityFrameworkCore/Orders/EfCoreOrderRepository.cs @@ -1,5 +1,9 @@ using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using EShopOnAbp.OrderingService.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -7,7 +11,22 @@ namespace EShopOnAbp.OrderingService.Orders; public class EfCoreOrderRepository : EfCoreRepository, IOrderRepository { - public EfCoreOrderRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + public EfCoreOrderRepository(IDbContextProvider dbContextProvider) : base( + dbContextProvider) { } + + public override async Task InsertAsync(Order entity, bool autoSave = false, + CancellationToken cancellationToken = new CancellationToken()) + { + var newEntity = await base.InsertAsync(entity, autoSave, cancellationToken); + await EnsurePropertyLoadedAsync(newEntity, o => o.OrderStatus, cancellationToken); + return newEntity; + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()) + .Include(q => q.OrderStatus); + } } \ No newline at end of file diff --git a/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs new file mode 100644 index 00000000..0b55ed8f --- /dev/null +++ b/services/ordering/test/EShopOnAbp.OrderingService.Domain.Tests/Orders/OrderManager_Tests.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace EShopOnAbp.OrderingService.Orders; + +public class OrderManagerUnitTests : OrderingServiceDomainTestBase +{ + private readonly OrderManager _orderManager; + + public OrderManagerUnitTests() + { + _orderManager = GetRequiredService(); + } + + [Fact] + public async Task Should_CreateOrderAsync() + { + var orderItems = + new List<(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, + string pictureUrl, int + units)>(); + orderItems.Add((Guid.NewGuid(), "Test product", "Code:001", 15, 0, "", 1)); + var createdOrder = await _orderManager.CreateOrderAsync( + 1, + "gterdem", + "gterdem@volosoft.com", + orderItems, + "Test Street", + "Test City", + "Test Country", + "Test zipCode"); + createdOrder.ShouldNotBeNull(); + } +} \ No newline at end of file