示例#1
0
        public async Task CanDeductLoyaltyPointsExtended()
        {
            var(products, purchased) = SeedProducts();

            // Given loyalty client
            var client = new LoyaltyCustomerTestClient(_factory);

            // And loyalty card
            var loyaltyCard = await client.LaunchLoyalty("Rick Richardson", "074 454-89-90");

            // And some products
            foreach (var p in products)
            {
                await client.AddProduct(p.Sku, p.Name, p.Price);
            }

            // When I process customer's purchase
            await client.ProcessPurchase(purchased.Select(p => (p.Sku, p.Qty)).ToList(), loyaltyCard);

            // And get balance
            var balance1 = await client.LoyaltyBalance(loyaltyCard);

            // And then process same purchase again with loyalty deduction=ON
            await client.ProcessPurchase(purchased.Select(p => (p.Sku, p.Qty)).ToList(), loyaltyCard, true);

            // And get balance again
            var balance2 = await client.LoyaltyBalance(loyaltyCard);

            // Then I expect balance to be 90% of previous one
            balance2.Should().BeGreaterThan(0);
            balance2.Should().Be(balance1 * 0.9m);
        }
示例#2
0
        public async Task CanRemoveSpecialOfferingsExtended()
        {
            var(products, purchased) = SeedProducts();


            // Given loyalty client
            var client = new LoyaltyCustomerTestClient(_factory);

            // And loyalty card
            var loyaltyCard = await client.LaunchLoyalty("Rick Richardson", "074 454-89-90");

            // And some products
            foreach (var p in products)
            {
                await client.AddProduct(p.Sku, p.Name, p.Price);
            }

            // When I process customer's purchase
            await client.ProcessPurchase(purchased.Select(p => (p.Sku, p.Qty)).ToList(), loyaltyCard);

            // And get balance
            var balance1 = await client.LoyaltyBalance(loyaltyCard);

            // And add X3 special offering
            foreach (var p in purchased)
            {
                await client.AddSpecialOffering(p.Sku, PromotionType.Multiplier, 3);
            }

            // And then process same purchase again
            await client.ProcessPurchase(purchased.Select(p => (p.Sku, p.Qty)).ToList(), loyaltyCard);

            // And then remove special offering
            foreach (var p in purchased)
            {
                await client.RemoveSpecialOffering(p.Sku);
            }

            // And process same purchase once more
            await client.ProcessPurchase(purchased.Select(p => (p.Sku, p.Qty)).ToList(), loyaltyCard);


            // And get balance again
            var balance2 = await client.LoyaltyBalance(loyaltyCard);

            // Then I expect balance grows 5 times
            balance2.Should().BeGreaterThan(0);
            balance2.Should().Be(balance1 * 5);
        }
示例#3
0
        public async Task BasicScenario()
        {
            // Given loyalty client
            var client = new LoyaltyCustomerTestClient(_factory);

            // And some customer
            var name        = "James Jameson";
            var phone       = "088 913-49-84";
            var loyaltyCard = string.Empty;

            // And some product
            var sku   = $"sku{DateTime.Now.Ticks}";
            var price = 100m;
            await client.AddProduct(sku, sku, price);


            // When I launch customer's loyalty program
            loyaltyCard = await client.LaunchLoyalty(name, phone);

            // Then I expect that customer's balance to be zero
            (await client.LoyaltyBalance(loyaltyCard)).Should().Be(0);

            // When I purchase some product with qty=1 and price=100
            var purchase = new List <(string, int)> {
                (sku, 1)
            };

            await client.ProcessPurchase(purchase, loyaltyCard);

            // Then I expect balance to be 10 (0 + 100 * 1 * 0.1)
            var balance1 = await client.LoyaltyBalance(loyaltyCard);

            balance1.Should().Be(10);

            // When I add special offering to make every bonus X10
            await client.AddSpecialOffering(sku, PromotionType.Multiplier, 10);

            // And make same purchase
            await client.ProcessPurchase(purchase, loyaltyCard);

            // Then I expect balance to be 110 (10 + 100 * 1 * 0.1 * 10)
            var balance2 = await client.LoyaltyBalance(loyaltyCard);

            balance2.Should().Be(110);

            // When I remove special offering
            await client.RemoveSpecialOffering(sku);

            // And make same purchase
            await client.ProcessPurchase(purchase, loyaltyCard);

            // Then I expect balance to be 120 (110 + 100 * 1 * 0.1)
            var balance3 = await client.LoyaltyBalance(loyaltyCard);

            balance3.Should().Be(120);


            // When I make same purchase and use bonus
            await client.ProcessPurchase(purchase, loyaltyCard, useLoyaltyPoints : true);

            // Then I expect balance to be 75, because 50 is spent as discount for half amount, customer pays 100-50=50 and receives 5 points for bonus
            var balance4 = await client.LoyaltyBalance(loyaltyCard);

            balance4.Should().Be(75);
        }