Пример #1
0
        static void Main(string[] args)
        {
            var productSystem = new PretendPurchaseSystem();

            var lordOfTheRings = new ProductId(10001);
            var theHobbit      = new ProductId(10002);
            var gameOfThrones  = new ProductId(20001);
            var breakingBad    = new ProductId(20110);

            var inventory = new Inventory(productSystem);

            inventory.Add(lordOfTheRings, 10, 10m);
            inventory.Add(theHobbit, 12, 5m);
            inventory.Add(gameOfThrones, 8, 9m);
            inventory.Add(breakingBad, 14, 7m);
            inventory.Print(Console.Out);

            var john = new UserId("john");
            var kim  = new UserId("kim");

            var basketRepository = new InMemoryBasketRepository();
            var basketFactory    = new BasketFactory(new SystemClock(),
                                                     Console.Out,
                                                     inventory);
            var shoppingBasketService = new ShoppingBasketService(
                basketRepository,
                basketFactory,
                inventory);

            // No discounts
            shoppingBasketService.AddItem(john, lordOfTheRings, 1);
            shoppingBasketService.AddItem(john, theHobbit, 1);

            shoppingBasketService.AddItem(kim, breakingBad, 1);

            var johnsCart = shoppingBasketService.BasketFor(john);
            var kimsCart  = shoppingBasketService.BasketFor(kim);

            Console.WriteLine($"John's basket total: {johnsCart.Total:c}");
            Console.WriteLine($"Kim's basket total: {kimsCart.Total:c}");

            var johnsPayment      = new PaymentDetails();
            var orderService      = new OrderService(new OrderIdGenerator(), basketRepository);
            var paymentGateway    = new PretendPaymentGateway();
            var orderConfirmation = new PretendOrderConfirmation();
            var paymentService    = new PaymentService(orderService,
                                                       paymentGateway,
                                                       inventory,
                                                       orderConfirmation);

            paymentService.MakePayment(john, johnsCart.Id, johnsPayment);

            inventory.Print(Console.Out);
        }
Пример #2
0
        public void ReturnShoppingBasket()
        {
            //Arrange
            const string expectedUserCart = "- 12/03/2019/n" +
                                            "- 2 x The Hobbit // 2 x 5.00 = �.00" +
                                            "- 5 x Breaking Bad // 5 x 7.00 = �.00" +
                                            "- Total: �.00";

            var shoppingBasketRepository = new ShoppingBasketRepository();

            var          shoppingBasketService = new ShoppingBasketService(shoppingBasketRepository);
            const string breakingBadProductId  = "20110";
            const string hobbitProductId       = "10002";

            //Act
            const string userId = "1";

            shoppingBasketService.AddItem(userId, hobbitProductId, 2);
            shoppingBasketService.AddItem(userId, breakingBadProductId, 5);

            var userCart = shoppingBasketService.BasketFor(userId);

            //Assert
            Assert.Equal(expectedUserCart, userCart);
        }
        public void BasketFor_ReturnsBasketFromRepository()
        {
            repoMock.Setup(repo => repo.GetBasket(ryan))
            .Returns(ryansBasket);

            var basket = sut.BasketFor(ryan);

            Assert.Equal(ryansBasket, basket);
        }