Пример #1
0
        public async Task CanValidateGiftCard()
        {
            await _giftCardService.InsertGiftCardUsageHistoryAsync(
                new GiftCardUsageHistory { GiftCardId = _giftCard1.Id, UsedWithOrderId = 1, UsedValue = 30 });

            await _giftCardService.InsertGiftCardUsageHistoryAsync(
                new GiftCardUsageHistory { GiftCardId = _giftCard1.Id, UsedWithOrderId = 1, UsedValue = 20 });

            await _giftCardService.InsertGiftCardUsageHistoryAsync(
                new GiftCardUsageHistory { GiftCardId = _giftCard1.Id, UsedWithOrderId = 1, UsedValue = 5 });

            //valid
            var isValid = await _giftCardService.IsGiftCardValidAsync(_giftCard1);

            isValid.Should().BeTrue();

            //mark as not active
            _giftCard1.IsGiftCardActivated = false;
            isValid = await _giftCardService.IsGiftCardValidAsync(_giftCard1);

            isValid.Should().BeFalse();

            //again active
            _giftCard1.IsGiftCardActivated = true;
            isValid = await _giftCardService.IsGiftCardValidAsync(_giftCard1);

            isValid.Should().BeTrue();

            //add usage history record
            await _giftCardService.InsertGiftCardUsageHistoryAsync(
                new GiftCardUsageHistory { GiftCardId = _giftCard1.Id, UsedWithOrderId = 1, UsedValue = 1000 });

            isValid = await _giftCardService.IsGiftCardValidAsync(_giftCard1);

            isValid.Should().BeFalse();
        }