Пример #1
0
        public void IfTheCardValueIsGreaterThanTheTotalOnlyTheTotalAmountShouldBeApplied()
        {
            var order = new Order {Total = 50};
            var giftCard1 = new GiftCard {Value = 100};
            var giftCards = new List<GiftCard> {giftCard1};
            GiftCardApplier giftCardApplier = new GiftCardApplierBuilder().Build();

            order = giftCardApplier.Apply(giftCards, order);

            order.GiftCardUsages.Should().HaveCount(1);
            order.GiftCardUsages[0].Amount.Should().Be(50);
        }
Пример #2
0
        public void IfAGiftCardWithLessValueThanTheTotalIsAddedItShouldBeUsedInFull()
        {
            var order = new Order {Total = 50};
            var giftCard = new GiftCard {Value = 25};
            var giftCards = new List<GiftCard> {giftCard};
            GiftCardApplier giftCardApplier = new GiftCardApplierBuilder().Build();

            order = giftCardApplier.Apply(giftCards, order);

            order.GiftCardUsages.Should().HaveCount(1);
            order.GiftCardUsages[0].Amount.Should().Be(25);
            giftCard.GiftCardUsages.Should().HaveCount(1);
            giftCard.GiftCardUsages[0].Should().Be(order.GiftCardUsages[0]);
        }
Пример #3
0
        public void IfASecondCardTakesItOverTheThresholdTheFullAmountShouldBeDrawnFromTheFirstThenTheRemainerFromTheSecond()
        {
            var order = new Order {Total = 50};
            var giftCard1 = new GiftCard {Value = 10};
            var giftCard2 = new GiftCard {Value = 100};
            var giftCards = new List<GiftCard> {giftCard1,giftCard2};
            GiftCardApplier giftCardApplier = new GiftCardApplierBuilder().Build();

            order = giftCardApplier.Apply(giftCards, order);

            order.GiftCardUsages.Should().HaveCount(2);
            order.GiftCardUsages[0].Amount.Should().Be(10);
            order.GiftCardUsages[1].Amount.Should().Be(40);
            giftCard1.AvailableAmount.Should().Be(0);
            giftCard2.AvailableAmount.Should().Be(60);
        }
Пример #4
0
        public void MultipleCardsShouldBeAppliedInFullIfTotalIsLessThanTheTotal()
        {
            var order = new Order {Total = 50};
            var giftCard1 = new GiftCard {Value = 12};
            var giftCard2 = new GiftCard {Value = 13};
            var giftCards = new List<GiftCard> {giftCard1, giftCard2};
            GiftCardApplier giftCardApplier = new GiftCardApplierBuilder().Build();

            order = giftCardApplier.Apply(giftCards, order);

            order.GiftCardUsages.Should().HaveCount(2);
            order.GiftCardUsages[0].Amount.Should().Be(12);
            order.GiftCardUsages[1].Amount.Should().Be(13);
            giftCard1.GiftCardUsages.Should().HaveCount(1);
            giftCard2.GiftCardUsages.Should().HaveCount(1);
        }
Пример #5
0
 public void Delete(GiftCard giftCard)
 {
     _session.Transact(session => session.Delete(giftCard));
 }
Пример #6
0
 public void Update(GiftCard giftCard)
 {
     _session.Transact(session => session.Update(giftCard));
 }
Пример #7
0
 public void Add(GiftCard giftCard)
 {
     _session.Transact(session => session.Save(giftCard));
 }