diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Orders.Plugins.FlashSales.Application/EasyAbp/EShop/Orders/Orders/CreateFlashSaleOrderEventHandler.cs b/plugins/FlashSales/src/EasyAbp.EShop.Orders.Plugins.FlashSales.Application/EasyAbp/EShop/Orders/Orders/CreateFlashSaleOrderEventHandler.cs index be794301..9c0c7ddb 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Orders.Plugins.FlashSales.Application/EasyAbp/EShop/Orders/Orders/CreateFlashSaleOrderEventHandler.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Orders.Plugins.FlashSales.Application/EasyAbp/EShop/Orders/Orders/CreateFlashSaleOrderEventHandler.cs @@ -72,6 +72,9 @@ public class CreateFlashSaleOrderEventHandler : IDistributedEventHandler Logger { get; } protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } - protected IFlashSalePlanRepository FlashSalePlanRepository { get; } - protected IProductAppService ProductAppService { get; } protected IUnitOfWorkManager UnitOfWorkManager { get; } protected IObjectMapper ObjectMapper { get; } protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; } @@ -26,8 +23,6 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler public FlashSaleOrderCreationResultEventHandler( ILogger logger, IFlashSaleInventoryManager flashSaleInventoryManager, - IFlashSalePlanRepository flashSalePlanRepository, - IProductAppService productAppService, IUnitOfWorkManager unitOfWorkManager, IObjectMapper objectMapper, IFlashSaleCurrentResultCache flashSaleCurrentResultCache, @@ -35,8 +30,6 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler { Logger = logger; FlashSaleInventoryManager = flashSaleInventoryManager; - FlashSalePlanRepository = flashSalePlanRepository; - ProductAppService = productAppService; UnitOfWorkManager = unitOfWorkManager; ObjectMapper = objectMapper; FlashSaleCurrentResultCache = flashSaleCurrentResultCache; @@ -56,36 +49,48 @@ public class FlashSaleOrderCreationResultEventHandler : IDistributedEventHandler } else { - var plan = await FlashSalePlanRepository.GetAsync(eventData.PlanId); - var product = await ProductAppService.GetAsync(plan.ProductId); - flashSaleResult.MarkAsFailed(eventData.Reason); await FlashSaleResultRepository.UpdateAsync(flashSaleResult, autoSave: true); - - if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync(plan.TenantId, product.InventoryProviderName, - plan.StoreId, plan.ProductId, plan.ProductSkuId)) - { - Logger.LogWarning("Try roll back inventory failed."); - return; // Avoid to remove cache on the UOW completed. - } } UnitOfWorkManager.Current.OnCompleted(async () => { - if (flashSaleResult.Status is FlashSaleResultStatus.Failed && eventData.AllowToTryAgain) + if (eventData.Success) { - await FlashSaleCurrentResultCache.RemoveAsync(flashSaleResult.PlanId, flashSaleResult.UserId); + await ResetFlashSaleCurrentResultCacheAsync(flashSaleResult); } else { - await FlashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId, - new FlashSaleCurrentResultCacheItem - { - TenantId = flashSaleResult.TenantId, - ResultDto = ObjectMapper.Map(flashSaleResult) - }); + // try to roll back the inventory. + if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync( + eventData.TenantId, eventData.ProductInventoryProviderName, eventData.StoreId, + eventData.ProductId, eventData.ProductSkuId)) + { + Logger.LogWarning("Failed to roll back the flash sale inventory."); + return; // avoid to remove cache if the rollback failed. + } + + // remove the cache so the user can try to order again. + if (eventData.AllowToTryAgain) + { + await FlashSaleCurrentResultCache.RemoveAsync(flashSaleResult.PlanId, flashSaleResult.UserId); + } + else + { + await ResetFlashSaleCurrentResultCacheAsync(flashSaleResult); + } } }); } + + protected virtual async Task ResetFlashSaleCurrentResultCacheAsync(FlashSaleResult flashSaleResult) + { + await FlashSaleCurrentResultCache.SetAsync(flashSaleResult.PlanId, flashSaleResult.UserId, + new FlashSaleCurrentResultCacheItem + { + TenantId = flashSaleResult.TenantId, + ResultDto = ObjectMapper.Map(flashSaleResult) + }); + } } \ No newline at end of file diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSalePlanAppService.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSalePlanAppService.cs index 1c73d4a4..ab38c192 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSalePlanAppService.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSalePlanAppService.cs @@ -272,7 +272,7 @@ public class FlashSalePlanAppService : try { var createFlashSaleResultEto = - await PrepareCreateFlashSaleResultEtoAsync(plan, flashSalePlanInput, userId, Clock.Now, preOrderCache.HashToken); + await PrepareCreateFlashSaleResultEtoAsync(plan, flashSalePlanInput, userId, Clock.Now, preOrderCache); await FlashSaleCurrentResultCache.SetAsync(plan.Id, CurrentUser.GetId(), new FlashSaleCurrentResultCacheItem { @@ -407,8 +407,8 @@ public class FlashSalePlanAppService : } protected virtual Task PrepareCreateFlashSaleResultEtoAsync( - FlashSalePlanCacheItem plan, OrderFlashSalePlanInput flashSalePlanInput, - Guid userId, DateTime reducedInventoryTime, string hashToken) + FlashSalePlanCacheItem plan, OrderFlashSalePlanInput flashSalePlanInput, Guid userId, + DateTime reducedInventoryTime, FlashSalePlanPreOrderCacheItem preOrderCacheItem) { var planEto = ObjectMapper.Map(plan); planEto.TenantId = CurrentTenant.Id; @@ -421,7 +421,8 @@ public class FlashSalePlanAppService : ReducedInventoryTime = reducedInventoryTime, CustomerRemark = flashSalePlanInput.CustomerRemark, Plan = planEto, - HashToken = hashToken + ProductInventoryProviderName = preOrderCacheItem.InventoryProviderName, + HashToken = preOrderCacheItem.HashToken }; if (flashSalePlanInput.ExtraProperties != null) diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs index 26a05647..e691edd7 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Application/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandler.cs @@ -1,13 +1,14 @@ using System.Threading.Tasks; using EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans; using EasyAbp.EShop.Plugins.FlashSales.FlashSaleResults.Dtos; +using EasyAbp.Eshop.Products.Products; +using EasyAbp.EShop.Products.Products; using Microsoft.Extensions.Logging; using Volo.Abp; using Volo.Abp.DependencyInjection; using Volo.Abp.DistributedLocking; using Volo.Abp.Domain.Repositories; using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectMapping; @@ -19,30 +20,33 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler Logger { get; } protected IAbpDistributedLock AbpDistributedLock { get; } protected IDistributedEventBus DistributedEventBus { get; } + protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } protected IFlashSaleCurrentResultCache FlashSaleCurrentResultCache { get; } protected IFlashSaleResultRepository FlashSaleResultRepository { get; } public CreateFlashSaleResultEventHandler( IObjectMapper objectMapper, - IGuidGenerator guidGenerator, ICurrentTenant currentTenant, + IUnitOfWorkManager unitOfWorkManager, ILogger logger, IAbpDistributedLock abpDistributedLock, IDistributedEventBus distributedEventBus, + IFlashSaleInventoryManager flashSaleInventoryManager, IFlashSaleCurrentResultCache flashSaleCurrentResultCache, IFlashSaleResultRepository flashSaleResultRepository) { ObjectMapper = objectMapper; - GuidGenerator = guidGenerator; CurrentTenant = currentTenant; + UnitOfWorkManager = unitOfWorkManager; Logger = logger; AbpDistributedLock = abpDistributedLock; DistributedEventBus = distributedEventBus; + FlashSaleInventoryManager = flashSaleInventoryManager; FlashSaleCurrentResultCache = flashSaleCurrentResultCache; FlashSaleResultRepository = flashSaleResultRepository; } @@ -73,7 +77,18 @@ public class CreateFlashSaleResultEventHandler : IDistributedEventHandler(ongoingResult) }); - return; + // try to roll back the inventory. + UnitOfWorkManager.Current.OnCompleted(async () => + { + if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync(eventData.TenantId, + eventData.ProductInventoryProviderName, eventData.Plan.StoreId, + eventData.Plan.ProductId, eventData.Plan.ProductSkuId)) + { + Logger.LogWarning("Failed to roll back the flash sale inventory."); + } + }); + + return; // avoid to create a result entity and an order. } var result = new FlashSaleResult( diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEto.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEto.cs index 4c581f2a..88ce602b 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEto.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEto.cs @@ -22,5 +22,11 @@ public class FlashSaleOrderCreationResultEto : ExtensibleObject, IMultiTenant public Guid? OrderId { get; set; } + public string ProductInventoryProviderName { get; set; } + + public Guid ProductId { get; set; } + + public Guid ProductSkuId { get; set; } + public bool AllowToTryAgain { get; set; } } diff --git a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEto.cs b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEto.cs index c4558072..b37298ba 100644 --- a/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEto.cs +++ b/plugins/FlashSales/src/EasyAbp.EShop.Plugins.FlashSales.Domain.Shared/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEto.cs @@ -20,5 +20,7 @@ public class CreateFlashSaleResultEto : ExtensibleObject, IMultiTenant public FlashSalePlanEto Plan { get; set; } + public string ProductInventoryProviderName { get; set; } + public string HashToken { get; set; } } diff --git a/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandlerTests.cs b/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandlerTests.cs index bf9e63eb..75a081b2 100644 --- a/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandlerTests.cs +++ b/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSalePlans/FlashSaleOrderCreationResultEventHandlerTests.cs @@ -93,11 +93,16 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati OrderId = GuidGenerator.Create(), Reason = null, UserId = flashSaleResult.UserId, + ProductInventoryProviderName = Product1.InventoryProviderName, + ProductId = plan.ProductId, + ProductSkuId = plan.ProductSkuId, AllowToTryAgain = false }; FlashSaleInventoryManager - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId) + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId) .Returns(Task.FromResult(true)); await FlashSaleOrderCreationResultEventHandler.HandleEventAsync(flashSaleOrderCreationResultEto); @@ -113,7 +118,9 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati flashSaleCurrentResultCache.ResultDto.Status.ShouldBe(FlashSaleResultStatus.Successful); await FlashSaleInventoryManager.DidNotReceive() - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId); + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId); } [Fact] @@ -133,11 +140,16 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati OrderId = null, Reason = "Failed reason", UserId = flashSaleResult.UserId, + ProductInventoryProviderName = Product1.InventoryProviderName, + ProductId = plan.ProductId, + ProductSkuId = plan.ProductSkuId, AllowToTryAgain = false }; FlashSaleInventoryManager - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId) + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId) .Returns(Task.FromResult(true)); await FlashSaleOrderCreationResultEventHandler.HandleEventAsync(flashSaleOrderCreationResultEto); @@ -153,7 +165,9 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati flashSaleCurrentResultCache.ResultDto.Status.ShouldBe(FlashSaleResultStatus.Failed); await FlashSaleInventoryManager.Received() - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId); + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId); } [Fact] @@ -173,11 +187,16 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati OrderId = null, Reason = "Failed reason", UserId = flashSaleResult.UserId, + ProductInventoryProviderName = Product1.InventoryProviderName, + ProductId = plan.ProductId, + ProductSkuId = plan.ProductSkuId, AllowToTryAgain = true }; FlashSaleInventoryManager - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId) + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId) .Returns(Task.FromResult(true)); await FlashSaleOrderCreationResultEventHandler.HandleEventAsync(flashSaleOrderCreationResultEto); @@ -191,7 +210,9 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati flashSaleCurrentResultCache.ShouldBeNull(); await FlashSaleInventoryManager.Received() - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId); + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId); } [Fact] @@ -211,11 +232,16 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati OrderId = null, Reason = FlashSaleResultFailedReason.InvalidHashToken, UserId = flashSaleResult.UserId, + ProductInventoryProviderName = Product1.InventoryProviderName, + ProductId = plan.ProductId, + ProductSkuId = plan.ProductSkuId, AllowToTryAgain = true }; FlashSaleInventoryManager - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId) + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId) .Returns(Task.FromResult(false)); await FlashSaleOrderCreationResultEventHandler.HandleEventAsync(flashSaleOrderCreationResultEto); @@ -224,6 +250,8 @@ public class FlashSaleOrderCreationResultEventHandlerTests : FlashSalesApplicati flashSaleCurrentResultCache.ShouldNotBeNull(); await FlashSaleInventoryManager.Received() - .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId); + .TryRollBackInventoryAsync(flashSaleOrderCreationResultEto.TenantId, + flashSaleOrderCreationResultEto.ProductInventoryProviderName, flashSaleOrderCreationResultEto.StoreId, + flashSaleOrderCreationResultEto.ProductId, flashSaleOrderCreationResultEto.ProductSkuId); } } diff --git a/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandlerTests.cs b/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandlerTests.cs index a45d4c84..c3234074 100644 --- a/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandlerTests.cs +++ b/plugins/FlashSales/test/EasyAbp.EShop.Plugins.FlashSales.Application.Tests/EasyAbp/EShop/Plugins/FlashSales/FlashSaleResults/CreateFlashSaleResultEventHandlerTests.cs @@ -2,6 +2,10 @@ using System.Linq; using System.Threading.Tasks; using EasyAbp.EShop.Plugins.FlashSales.FlashSalePlans; +using EasyAbp.Eshop.Products.Products; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using NSubstitute; using Shouldly; using Volo.Abp.Users; using Xunit; @@ -12,11 +16,21 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB { protected IFlashSaleResultAppService FlashSaleResultAppService { get; } protected CreateFlashSaleResultEventHandler CreateFlashSaleResultEventHandler { get; } + protected IFlashSaleInventoryManager FlashSaleInventoryManager { get; } public CreateFlashSaleResultEventHandlerTests() { FlashSaleResultAppService = GetRequiredService(); CreateFlashSaleResultEventHandler = GetRequiredService(); + FlashSaleInventoryManager = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + var flashSaleInventoryManager = Substitute.For(); + services.Replace(ServiceDescriptor.Singleton(flashSaleInventoryManager)); + + base.AfterAddApplication(services); } [Fact] @@ -50,6 +64,11 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB await CreateFlashSaleResultEventHandler.HandleEventAsync(createFlashSaleResultEto1); + await FlashSaleInventoryManager.DidNotReceive() + .TryRollBackInventoryAsync(createFlashSaleResultEto1.TenantId, + createFlashSaleResultEto1.ProductInventoryProviderName, createFlashSaleResultEto1.Plan.StoreId, + createFlashSaleResultEto1.Plan.ProductId, createFlashSaleResultEto1.Plan.ProductSkuId); + var flashResultList = await FlashSaleResultRepository.GetListAsync(); flashResultList.Count.ShouldBe(2); flashResultList.ShouldContain(x => x.Id == existFlashResult1.Id); @@ -61,6 +80,11 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB await CreateFlashSaleResultEventHandler.HandleEventAsync(createFlashSaleResultEto2); + await FlashSaleInventoryManager.Received() + .TryRollBackInventoryAsync(createFlashSaleResultEto2.TenantId, + createFlashSaleResultEto2.ProductInventoryProviderName, createFlashSaleResultEto2.Plan.StoreId, + createFlashSaleResultEto2.Plan.ProductId, createFlashSaleResultEto2.Plan.ProductSkuId); + flashResultList = await FlashSaleResultRepository.GetListAsync(); flashResultList.Count.ShouldBe(2); flashResultList.ShouldContain(x => x.Id == existFlashResult1.Id); @@ -73,6 +97,11 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB await CreateFlashSaleResultEventHandler.HandleEventAsync(createFlashSaleResultEto2); + await FlashSaleInventoryManager.Received() + .TryRollBackInventoryAsync(createFlashSaleResultEto2.TenantId, + createFlashSaleResultEto2.ProductInventoryProviderName, createFlashSaleResultEto2.Plan.StoreId, + createFlashSaleResultEto2.Plan.ProductId, createFlashSaleResultEto2.Plan.ProductSkuId); + flashResultList = await FlashSaleResultRepository.GetListAsync(); flashResultList.Count.ShouldBe(2); flashResultList.ShouldContain(x => x.Id == existFlashResult1.Id); @@ -81,7 +110,7 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB (await FlashSaleResultAppService.GetCurrentAsync(planId)).Id.ShouldBe(existFlashResult2.Id); } - public Task CreateCreateFlashSaleResultEtoAsync(DateTime reducedInventoryTime) + protected Task CreateCreateFlashSaleResultEtoAsync(DateTime reducedInventoryTime) { return Task.FromResult(new CreateFlashSaleResultEto { @@ -103,7 +132,7 @@ public class CreateFlashSaleResultEventHandlerTests : FlashSalesApplicationTestB }); } - public async Task CreateFlashSaleResultAsync() + protected async Task CreateFlashSaleResultAsync() { return await WithUnitOfWorkAsync(async () => {