예제 #1
0
        public void RandomCustomerLogicTest()
        {
            LibraryLogic logic = new LibraryLogic(new Library());

            AbstCustomer c = new RndIdCustomer("Paul", 10000);

            logic.AddCustomer(c);

            Assert.IsTrue(logic.GetLibrary.Customers.Contains(c));
            Assert.IsTrue(logic.IsCustomer(c));

            logic.AddCustomer(c);
            Assert.AreEqual(logic.GetLibrary.Customers.Count(), 1);

            logic.AddFunds(c, 10000);
            Assert.AreEqual(logic.GetLibrary.Customers[0].MoneyInCents, 20000);

            logic.RemoveCustomer(logic.GetLibrary.Customers[0]);
            Assert.AreEqual(logic.GetLibrary.Customers.Count(), 0);
        }
예제 #2
0
        public void EventGanerationTest()
        {
            LibraryLogic logic = new LibraryLogic(new Library());

            AbstCustomer c = new Customer("Paul", 1, 10000);
            AbstBook     b = new Book("Dune", "Herbert", BType.SciFi, 1, 2);

            logic.AddCustomer(c);
            Assert.AreEqual(logic.GetLibrary.Events[0].Name, "Added customer " + c.Id);

            logic.AddToCatalog(b);
            Assert.AreEqual(logic.GetLibrary.Events[1].Name, "Added to catalog book " + b.Id);

            logic.AddToStock(b);
            Assert.AreEqual(logic.GetLibrary.Events[2].Name, "Added to stock book " + b.Id);

            logic.AddToBasket(logic.GetLibrary.Customers[0], logic.GetLibrary.Stock[0]);
            Assert.AreEqual(logic.GetLibrary.Events[3].Name, "Removed from stock book " + b.Id);
            Assert.AreEqual(logic.GetLibrary.Events[4].Name, "Added to basket of " + c.Id + " book " + b.Id);

            logic.Borrow(logic.GetLibrary.Customers[0]);
            Assert.AreEqual(logic.GetLibrary.Events[5].Name, "Borrowing books by " + c.Id);
            Assert.AreEqual(logic.GetLibrary.Events[5].GetInvoice.Books[0], b);

            Console.WriteLine("Customer c. borrowed:1 " + logic.GetLibrary.Customers[0].Borrowed.Count());
            logic.Return(logic.GetLibrary.Customers[0]);
            Console.WriteLine("Customer c. borrowed:2 " + logic.GetLibrary.Customers[0].Borrowed.Count());

            Assert.AreEqual(logic.GetLibrary.Events[6].Name, "Returning books by " + c.Id);

            Console.WriteLine(logic.GetLibrary.Events[6].GetInvoice.Books.Count());
            Assert.AreEqual(logic.GetLibrary.Events[6].GetInvoice.Books.Count(), 1);

            Assert.AreEqual(logic.GetLibrary.Events[7].Name, "Added to stock book " + b.Id);

            logic.RemoveCustomer(logic.GetLibrary.Customers[0]);
            Assert.AreEqual(logic.GetLibrary.Events[8].Name, "Removed customer " + c.Id);

            logic.RemoveFromCatalog(logic.GetLibrary.Catalog[0]);
            Assert.AreEqual(logic.GetLibrary.Events[9].Name, "Removed from catalog book " + b.Id);
        }