public void Can_calculate_giftCard_remainingAmount() { var gc = new GiftCard() { Amount = 100 }; gc.GiftCardUsageHistory.Add ( new GiftCardUsageHistory() { UsedValue = 30 } ); gc.GiftCardUsageHistory.Add ( new GiftCardUsageHistory() { UsedValue = 20 } ); gc.GiftCardUsageHistory.Add ( new GiftCardUsageHistory() { UsedValue = 5 } ); gc.GetGiftCardRemainingAmount().ShouldEqual(45); }
public virtual void AddGiftCardTokens(IList<Token> tokens, GiftCard giftCard) { var order = (giftCard.PurchasedWithOrderItem != null ? giftCard.PurchasedWithOrderItem.Order : null); if (order != null) { var remainingAmount = _currencyService.ConvertCurrency(giftCard.GetGiftCardRemainingAmount(), order.CurrencyRate); tokens.Add(new Token("GiftCard.RemainingAmount", _priceFormatter.FormatPrice(remainingAmount, true, false))); } else { tokens.Add(new Token("GiftCard.RemainingAmount", "")); } tokens.Add(new Token("GiftCard.SenderName", giftCard.SenderName)); tokens.Add(new Token("GiftCard.SenderEmail", giftCard.SenderEmail)); tokens.Add(new Token("GiftCard.RecipientName", giftCard.RecipientName)); tokens.Add(new Token("GiftCard.RecipientEmail", giftCard.RecipientEmail)); tokens.Add(new Token("GiftCard.Amount", _priceFormatter.FormatPrice(giftCard.Amount, true, false))); tokens.Add(new Token("GiftCard.CouponCode", giftCard.GiftCardCouponCode)); var giftCardMesage = !String.IsNullOrWhiteSpace(giftCard.Message) ? HtmlUtils.FormatText(giftCard.Message, false, true, false, false, false, false) : ""; tokens.Add(new Token("GiftCard.Message", giftCardMesage, true)); //event notification _eventPublisher.EntityTokensAdded(giftCard, tokens); }