Esempio n. 1
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 AddingItemCreatesBasket()
        {
            repoMock.Setup((repo) => repo.GetBasket(john))
            .Returns(() => null);
            basketFactoryMock.Setup(factory => factory.Create(john))
            .Returns(johnsBasket);

            sut.AddItem(john, lor, 1);
            repoMock.Verify((repo) => repo.Save(johnsBasket));
            Assert.Equal(1, johnsBasket.Items.Count);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void SaveShoppingBasketOnBasketRepository()
        {
            var shoppingBasketRepository = Substitute.For <IShoppingBasketRepository>();
            var shoppingBasketService    = new ShoppingBasketService(shoppingBasketRepository);

            const string userId    = "1";
            const string productId = "10002";
            const int    quantity  = 2;
            var          item      = new Item(productId, quantity);

            var shoppingBasket = new ShoppingBasket(userId, item);

            shoppingBasketService.AddItem(userId, productId, 2);

            shoppingBasketRepository.Received().Save(shoppingBasket);
        }