Exemplo n.º 1
0
            public void Should_throw_ArgumentException_for_invalid_orderitem()
            {
                var subject            = new BuyXItemsGetYFree("item-1", 2, 1);
                var incorrectOrderItem = new OrderItem {
                    Identifier = "item-2", ItemCost = 10m, Quantity = 3
                };

                Assert.Throws <ArgumentException>(() => subject.CalculateItemPrice(incorrectOrderItem));
            }
Exemplo n.º 2
0
            public void Should_return_false_for_less_than_x_items()
            {
                var subject   = new BuyXItemsGetYFree("item-1", 2, 1);
                var orderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 1
                };

                Assert.IsFalse(subject.MatchesItem(orderItem));
            }
Exemplo n.º 3
0
            public void Should_return_false_for_non_matched_items()
            {
                var subject            = new BuyXItemsGetYFree("item-1", 2, 1);
                var incorrectOrderItem = new OrderItem {
                    Identifier = "item-2", ItemCost = 10m, Quantity = 3
                };

                Assert.IsFalse(subject.MatchesItem(incorrectOrderItem));
            }
Exemplo n.º 4
0
            public void Should_calculate_set_price_for_exact_sets()
            {
                var subject        = new BuyXItemsGetYFree("item-1", 3, 2);
                var firstOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 5
                };
                var secondOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 10
                };

                Assert.That(subject.CalculateItemPrice(firstOrderItem), Is.EqualTo(30m));
                Assert.That(subject.CalculateItemPrice(secondOrderItem), Is.EqualTo(60m));
            }
Exemplo n.º 5
0
            public void Should_return_true_for_at_least_x_items()
            {
                var subject   = new BuyXItemsGetYFree("item-1", 2, 1);
                var firstItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 2
                };
                var secondItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 3
                };
                var thirdItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 4
                };

                Assert.IsTrue(subject.MatchesItem(firstItem));
                Assert.IsTrue(subject.MatchesItem(secondItem));
                Assert.IsTrue(subject.MatchesItem(thirdItem));
            }
Exemplo n.º 6
0
            public void Should_calculate_full_price_for_items_not_in_set()
            {
                var subject        = new BuyXItemsGetYFree("item-1", 3, 2);
                var firstOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 5
                };
                var secondOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 6
                };
                var thirdOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 7
                };

                Assert.That(subject.CalculateItemPrice(firstOrderItem), Is.EqualTo(30m));
                Assert.That(subject.CalculateItemPrice(secondOrderItem), Is.EqualTo(40m));
                Assert.That(subject.CalculateItemPrice(thirdOrderItem), Is.EqualTo(50m));
            }
Exemplo n.º 7
0
            public void Should_calculate_set_price_when_ordered_quantity_is_more_than_X_but_free_items_are_less_than_Y()
            {
                var subject        = new BuyXItemsGetYFree("item-1", 3, 2);
                var firstOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 3
                };
                var secondOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 4
                };
                var thirdOrderItem = new OrderItem {
                    Identifier = subject.ItemId, ItemCost = 10m, Quantity = 5
                };

                Assert.That(subject.CalculateItemPrice(firstOrderItem), Is.EqualTo(30m));
                Assert.That(subject.CalculateItemPrice(secondOrderItem), Is.EqualTo(30m));
                Assert.That(subject.CalculateItemPrice(thirdOrderItem), Is.EqualTo(30m));
            }