Example #1
0
    public async Task HandleEventAsync_Should_Not_Remove_UserFlashSaleResultCache_When_TryRollBackInventory_Failed()
    {
        var plan = await CreateFlashSalePlanAsync();

        var pendingFlashResult = await CreatePendingResultAsync(plan.Id, plan.StoreId, CurrentUser.GetId());

        var userFlashSaleResultCacheKey = string.Format(FlashSalePlanAppService.UserFlashSaleResultCacheKeyFormat, plan.TenantId, plan.Id, CurrentUser.GetId());
        await DistributedCache.SetStringAsync(userFlashSaleResultCacheKey, pendingFlashResult.Id.ToString());

        var createFlashSaleOrderCompleteEto = new CreateFlashSaleOrderCompleteEto()
        {
            TenantId        = pendingFlashResult.TenantId,
            PendingResultId = pendingFlashResult.Id,
            Success         = false,
            StoreId         = pendingFlashResult.StoreId,
            PlanId          = pendingFlashResult.PlanId,
            OrderId         = null,
            Reason          = FlashSaleResultFailedReason.InvalidHashToken,
            UserId          = pendingFlashResult.UserId
        };

        FlashSaleInventoryManager
        .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId, 1, true)
        .Returns(Task.FromResult(false));

        await EventHandler.HandleEventAsync(createFlashSaleOrderCompleteEto);

        var userFlashSaleResultCache = await DistributedCache.GetStringAsync(userFlashSaleResultCacheKey);

        userFlashSaleResultCache.ShouldBe(pendingFlashResult.Id.ToString());

        await FlashSaleInventoryManager.Received()
        .TryRollBackInventoryAsync(plan.TenantId, Product1.InventoryProviderName, plan.StoreId, plan.ProductId, plan.ProductSkuId, 1, true);
    }
Example #2
0
    public async Task HandleEventAsync_Should_Ignore_When_Success_Is_True()
    {
        var plan = await CreateFlashSalePlanAsync();

        var pendingFlashResult = await CreatePendingResultAsync(plan.Id, plan.StoreId, CurrentUser.GetId());

        var userFlashSaleResultCacheKey = string.Format(FlashSalePlanAppService.UserFlashSaleResultCacheKeyFormat, plan.TenantId, plan.Id, CurrentUser.GetId());
        await DistributedCache.SetStringAsync(userFlashSaleResultCacheKey, pendingFlashResult.Id.ToString());

        var createFlashSaleOrderCompleteEto = new CreateFlashSaleOrderCompleteEto()
        {
            TenantId        = pendingFlashResult.TenantId,
            PendingResultId = pendingFlashResult.Id,
            Success         = true,
            StoreId         = pendingFlashResult.StoreId,
            PlanId          = pendingFlashResult.PlanId,
            OrderId         = Guid.NewGuid(),
            Reason          = null,
            UserId          = pendingFlashResult.UserId
        };

        await EventHandler.HandleEventAsync(createFlashSaleOrderCompleteEto);

        var userFlashSaleResultCache = await DistributedCache.GetStringAsync(userFlashSaleResultCacheKey);

        userFlashSaleResultCache.ShouldBe(pendingFlashResult.Id.ToString());

        await FlashSaleInventoryManager.DidNotReceiveWithAnyArgs()
        .TryRollBackInventoryAsync(default, default, Guid.Empty, Guid.Empty, Guid.Empty, default, default);
Example #3
0
    public async Task HandleEventAsync_When_Create_Order_Failed()
    {
        var existFlashResult = await CreateFlashSaleResultAsync();

        var createFlashSaleOrderCompleteEto = new CreateFlashSaleOrderCompleteEto()
        {
            TenantId        = existFlashResult.TenantId,
            PendingResultId = existFlashResult.Id,
            Success         = false,
            StoreId         = FlashSalesTestData.Store1Id,
            PlanId          = existFlashResult.PlanId,
            OrderId         = null,
            Reason          = "Failed reason",
            UserId          = existFlashResult.UserId,
        };

        await CreateFlashSaleOrderCompleteEventHandler.HandleEventAsync(createFlashSaleOrderCompleteEto);

        var flashResult = await FlashSaleResultRepository.GetAsync(existFlashResult.Id);

        flashResult.Status.ShouldBe(FlashSaleResultStatus.Failed);
        flashResult.OrderId.ShouldBe(null);
        flashResult.Reason.ShouldBe("Failed reason");
    }
Example #4
0
    public async Task HandleEventAsync_When_Create_Order_Success()
    {
        var existFlashResult = await CreateFlashSaleResultAsync();

        var createFlashSaleOrderCompleteEto = new CreateFlashSaleOrderCompleteEto()
        {
            TenantId        = existFlashResult.TenantId,
            PendingResultId = existFlashResult.Id,
            Success         = true,
            StoreId         = existFlashResult.StoreId,
            PlanId          = existFlashResult.PlanId,
            OrderId         = GuidGenerator.Create(),
            Reason          = null,
            UserId          = existFlashResult.UserId,
        };

        await CreateFlashSaleOrderCompleteEventHandler.HandleEventAsync(createFlashSaleOrderCompleteEto);

        var flashResult = await FlashSaleResultRepository.GetAsync(existFlashResult.Id);

        flashResult.Status.ShouldBe(FlashSaleResultStatus.Successful);
        flashResult.OrderId.ShouldBe(createFlashSaleOrderCompleteEto.OrderId);
        flashResult.Reason.ShouldBe(null);
    }