public void ImplementsIBasketFactory()
        {
            var clock = new ManualClock(DateTime.Parse("2020-05-10"));
            var sut   = new BasketFactory(clock, this.writer, this.inventory);

            Assert.IsAssignableFrom <IBasketFactory>(sut);
        }
        public void CreateReturnsBasketLogger()
        {
            var clock  = new ManualClock(DateTime.Parse("2019-09-21"));
            var sut    = new BasketFactory(clock, this.writer, this.inventory);
            var actual = sut.Create(new UserId("john"));

            Assert.IsType <BasketLogger>(actual);
        }
Ejemplo n.º 3
0
        public void Get_WithNullProducts_ShouldThrowArgumentNullException()
        {
            //arrange
            var basketFactory = new BasketFactory(null);

            //act
            basketFactory.Get(null);

            //assert
        }
        public void CreateReturnsWithCurrentDate(string aDate)
        {
            var    clock  = new ManualClock(DateTime.Parse(aDate));
            var    sut    = new BasketFactory(clock, this.writer, this.inventory);
            UserId userId = new UserId("john");
            var    actual = sut.Create(userId);

            Assert.Equal(DateTime.Parse(aDate), actual.CreationDate);
            Assert.Same(userId, actual.UserId);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        // GET: BasketItems/Create
        public ActionResult Create(int id)
        {
            if (Session["OrderId"] == null)
            {
                Order newOrder = OrderFactory.CreateNewOrder(db);
                Session.Add("OrderId", newOrder.Id);
            }
            int thisOrderId = Int32.Parse(Session["OrderId"].ToString());

            Product chosenProduct = db.Products.Find(id);

            BasketFactory.addBasketItem(db, thisOrderId, chosenProduct, 1);
            Order order = db.Orders.Find(thisOrderId);

            OrderFactory.UpdateOrder(db, order);

            return(RedirectToRoute(new { controller = "Orders", action = "Details", id = thisOrderId }));
        }
Ejemplo n.º 7
0
        private static void Main(string[] args)
        {
            var baskets      = BasketFactory.CreateBaskets().ToList();
            var consoleTable = new ConsoleTable(typeof(Basket).GetProperties().Select(s => s.Name).ToArray());

            foreach (var basket in baskets)
            {
                var calculateDiscount = new CalculateDiscount(basket);
                calculateDiscount.Calcutale();
                var firstOrDefault = basket.Products.First();

                consoleTable.AddRow(basket.Customer.FullName, firstOrDefault.Name, "", basket.DiscountRate, basket.TotalDiscount, basket.SubTotal, basket.TotalPrice);
            }
            //ConsoleTable.From(baskets).Write(Format.MarkDown);


            consoleTable.Write();
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        public void Get_CalledWith2Products_ShouldReturnBasketWith2Items()
        {
            //arrange
            var milk = new Product {
                Id = Guid.NewGuid(), Name = "Milk", Price = 0.40m, QuantityAvailable = 100
            };
            var soup = new Product {
                Id = Guid.NewGuid(), Name = "Soup", Price = 0.40m, QuantityAvailable = 100
            };
            var bread = new Product {
                Id = Guid.NewGuid(), Name = "Bread", Price = 0.40m, QuantityAvailable = 100
            };
            var apples = new Product {
                Id = Guid.NewGuid(), Name = "Apples", Price = 0.40m, QuantityAvailable = 100
            };

            var mockProductRepository = new Mock <IGenericRepository <Product> >();

            mockProductRepository.Setup(m => m.GetAll())
            .Returns(
                new List <Product>
            {
                milk, soup, bread, apples
            }.AsQueryable()
                );


            var basketFactory = new BasketFactory(mockProductRepository.Object);

            //act
            var basket = basketFactory.Get(new string[] { "Milk", "Soup" });

            //assert
            Assert.AreEqual(2, basket.Items.Count());
            Assert.IsNotNull(basket.Items.FirstOrDefault(i => i.Name == "Soup"));
            Assert.IsNotNull(basket.Items.FirstOrDefault(i => i.Name == "Milk"));
        }
 public BasketController(ProductRepository productRepository, BasketFactory basketFactory)
 {
     _productRepository = productRepository;
     _basketFactory     = basketFactory;
 }