Example #1
0
        public void PayTest()
        {
            LibraryLogic logic = new LibraryLogic(new Library());

            DateTime pastDate = new DateTime(2020, 10, 30);
            TimeSpan diff     = DateTime.Today - pastDate;

            AbstCustomer c  = new Customer("Paul", 1, 10000);
            AbstBook     b1 = new Book("Dune", "Herbert", BType.SciFi, 1, 1);
            AbstBook     b2 = new Book("Dune's Childer", "Herbert", BType.SciFi, 1, 2);

            logic.AddCustomer(c);
            logic.AddToCatalog(b1);
            logic.AddToCatalog(b2);
            logic.AddToStock(b1);
            logic.AddToStock(b2);

            Assert.AreEqual(logic.GetLibrary.Stock.Count(), 2);
            Assert.AreEqual(logic.GetLibrary.Customers.Count(), 1);

            logic.AddToBasket(logic.GetLibrary.Customers[0], logic.GetLibrary.Stock[1]);
            logic.AddToBasket(logic.GetLibrary.Customers[0], logic.GetLibrary.Stock[0]);
            logic.Borrow(logic.GetLibrary.Customers[0]);

            Assert.AreEqual(logic.GetLibrary.Customers[0].Borrowed.Count(), 2);

            logic.GetLibrary.Customers[0].Borrowed[0].ReturnDate = pastDate;
            logic.GetLibrary.Customers[0].Borrowed[1].ReturnDate = pastDate;
            Assert.AreEqual(logic.TotalPenalty(logic.GetLibrary.Customers[0]), diff.Days * 2);
            logic.Pay(logic.GetLibrary.Customers[0]);
            Assert.AreEqual(logic.GetLibrary.Customers[0].MoneyInCents, 10000 - diff.Days * 2);

            AbstCustomer c2 = new Customer("Chani", 2, 10000);

            logic.AddCustomer(c2);
            logic.AddToStock(b1);
            logic.AddToStock(b2);

            logic.AddToBasket(logic.GetLibrary.Customers[1], logic.GetLibrary.Stock[1]);
            logic.AddToBasket(logic.GetLibrary.Customers[1], logic.GetLibrary.Stock[0]);
            logic.Borrow(logic.GetLibrary.Customers[1]);

            Assert.AreEqual(logic.GetLibrary.Customers[1].Borrowed.Count(), 2);

            Assert.AreEqual(logic.TotalPenalty(logic.GetLibrary.Customers[1]), 0);
            logic.Pay(logic.GetLibrary.Customers[1]);
            Assert.AreEqual(logic.GetLibrary.Customers[1].MoneyInCents, 10000);
        }