public void TransferFromMachine_UnitTest()
        {
            // Init
            Database database = new Database();
            TransferManager transferManager = new TransferManager(database);
            transferManager.buyStock("Snickers", 5, .25f);
            List<Product> listProduct = database.SelectAllProduct();

            Machine machine = new Machine("Milwaukee", "", "M101");
            database.Append(machine);
            transferManager.TransferToMachine(machine, listProduct);
            Assert.AreEqual(machine.getSingleQuantity("Snickers"), 5);
            List<Product> transferList = machine.selectAllProductByType("Snickers");

            // Action
            transferManager.TransferFromMachine(machine, transferList);

            // Assert
            Assert.AreEqual(database.SelectAllProduct().Count, 5);
            Assert.AreEqual(machine.getSingleQuantity("Snickers"), 0);

            List<Transactions> listTransactions = database.SelectAllTransactions();
            Assert.AreEqual(listTransactions.Count, 5);
            Assert.AreEqual(listTransactions[4].Amount, 1.25f);
        }
        public void BuyStock_UnitTest()
        {
            // Init
            Database database = new Database();
            TransferManager transferManager = new TransferManager(database);

            // Action
            transferManager.buyStock("Snickers", 5, .25f);

            // Assert
            List<Product> listProduct = database.SelectAllProduct();
            List<Transactions> listTransactions = database.SelectAllTransactions();
            Assert.AreEqual(listProduct.Count, 5);
            Assert.AreEqual(listProduct[0].Name, "Snickers");
            Assert.AreEqual(listTransactions.Count, 1);
            Assert.AreEqual(listTransactions[0].Amount, -1.25f);
        }
        public void MachineSale_UnitTest()
        {
            // Init
            Database database = new Database();
            TransferManager transferManager = new TransferManager(database);
            Machine machine = new Machine("Milwaukee", "The Mall", "M101");
            database.Append(machine);
            transferManager.buyStock("Snickers", 5, .25f);
            List<Product> listProduct = database.SelectAllProduct();
            transferManager.TransferToMachine(machine, listProduct);
            List<Product> listProductBefore = machine.selectAllProductByType("Snickers");
            int startingCount = listProductBefore.Count;

            // Action
            transferManager.machineSale(machine, listProductBefore[0]);

            // Assert
            List<Product> listProductAfter = machine.selectAllProductByType("Snickers");
            List<Transactions> listTransactionsAfter = database.SelectAllTransactions();
            int endingCount = listProductAfter.Count;
            int transactionCount = listTransactionsAfter.Count;
            Assert.AreEqual(startingCount - 1, endingCount);
            Assert.AreEqual(5, transactionCount);
        }
Пример #4
0
        public void generateInitialMachines()
        {
            Machine machine1 = new Machine("Milwaukee", "Mayfair Mall", "M101");
            machine1.MaxCapacity = 100;
            business.Accounts.Add("M101");
            Machine machine2 = new Machine("Waukesha", "Downtown", "M102");
            machine2.MaxCapacity = 100;
            business.Accounts.Add("M102");
            Machine machine3 = new Machine("Brookfield", "Brookfield Square", "M103");
            machine3.MaxCapacity = 100;
            business.Accounts.Add("M103");
            Machine machine4 = new Machine("Milwaukee", "Downtown", "M104");
            machine4.MaxCapacity = 100;
            business.Accounts.Add("M104");
            Machine machine5 = new Machine("Brookfield", "Brookfield Square", "M105");
            machine5.MaxCapacity = 100;
            business.Accounts.Add("M105");

            // Pull inventory of warehouse
            List<Product> transferList = this.SelectAllProduct();
            TransferManager transferManager = new TransferManager(this);
            int index = 0;

            // Create Machines and transfer product into machine
            machine1.MaxCapacity = 10;
            //machine1.NeedRestock = false;
            //machine1.NeedService = true;
            machine1.DefaultMinStock = 1;

            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);

            machine3.MaxCapacity = 5;
            //machine3.NeedRestock = true;
            //machine3.NeedService = true;
            machine3.DefaultMinStock = 1;
            transferManager.TransferToMachine(machine3, transferList[++index]);
            transferManager.TransferToMachine(machine3, transferList[++index]);

            machine4.MaxCapacity = 10;
            //machine4.NeedRestock = false;
            //machine4.NeedService = false;
            machine4.DefaultMinStock = 2;
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);

            machine5.MaxCapacity = 20;
            //machine5.NeedRestock = true;
            //machine5.NeedService = true;
            machine5.DefaultMinStock = 2;
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);

            listMachine.Add(machine1);
            listMachine.Add(machine2);
            listMachine.Add(machine3);
            listMachine.Add(machine4);
            listMachine.Add(machine5);
        }
Пример #5
0
 public Controller(Database database)
 {
     this.database = database;
     this.transferManager = new TransferManager(database);
 }
Пример #6
0
        public void generateInitialMachines()
        {
            Machine machine1 = new Machine("Milwaukee", "Mayfair Mall", "M101");

            machine1.MaxCapacity = 100;
            business.Accounts.Add("M101");
            Machine machine2 = new Machine("Waukesha", "Downtown", "M102");

            machine2.MaxCapacity = 100;
            business.Accounts.Add("M102");
            Machine machine3 = new Machine("Brookfield", "Brookfield Square", "M103");

            machine3.MaxCapacity = 100;
            business.Accounts.Add("M103");
            Machine machine4 = new Machine("Milwaukee", "Downtown", "M104");

            machine4.MaxCapacity = 100;
            business.Accounts.Add("M104");
            Machine machine5 = new Machine("Brookfield", "Brookfield Square", "M105");

            machine5.MaxCapacity = 100;
            business.Accounts.Add("M105");

            // Pull inventory of warehouse
            List <Product>  transferList    = this.SelectAllProduct();
            TransferManager transferManager = new TransferManager(this);
            int             index           = 0;

            // Create Machines and transfer product into machine
            machine1.MaxCapacity = 10;
            //machine1.NeedRestock = false;
            //machine1.NeedService = true;
            machine1.DefaultMinStock = 1;

            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);
            transferManager.TransferToMachine(machine1, transferList[++index]);



            machine3.MaxCapacity = 5;
            //machine3.NeedRestock = true;
            //machine3.NeedService = true;
            machine3.DefaultMinStock = 1;
            transferManager.TransferToMachine(machine3, transferList[++index]);
            transferManager.TransferToMachine(machine3, transferList[++index]);

            machine4.MaxCapacity = 10;
            //machine4.NeedRestock = false;
            //machine4.NeedService = false;
            machine4.DefaultMinStock = 2;
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);
            transferManager.TransferToMachine(machine4, transferList[++index]);

            machine5.MaxCapacity = 20;
            //machine5.NeedRestock = true;
            //machine5.NeedService = true;
            machine5.DefaultMinStock = 2;
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);
            transferManager.TransferToMachine(machine5, transferList[++index]);

            listMachine.Add(machine1);
            listMachine.Add(machine2);
            listMachine.Add(machine3);
            listMachine.Add(machine4);
            listMachine.Add(machine5);
        }
        public void TransferToMachine_UnitTest()
        {
            // Init
            Database database = new Database();
            TransferManager transferManager = new TransferManager(database);
            transferManager.buyStock("Snickers", 5, .25f);
            List<Product> listProduct = database.SelectAllProduct();

            Machine machine = new Machine("Milwaukee", "", "M101");

            // Action
            transferManager.TransferToMachine(machine, listProduct);

            // Assert
            int SnickerQuantity = machine.getSingleQuantity("Snickers");
            int AllQuantity = machine.getAllQuantity();
            listProduct = database.SelectAllProduct();
            List<Transactions> listTransactions = database.SelectAllTransactions();
            Assert.AreEqual(listProduct.Count, 0);
            Assert.AreEqual(SnickerQuantity, 5);
            Assert.AreEqual(AllQuantity, 5);
            Assert.AreEqual(listTransactions.Count, 3);
            Assert.AreEqual(listTransactions[2].Amount, -1.25);
        }
Пример #8
0
 public Controller(Database database)
 {
     this.database        = database;
     this.transferManager = new TransferManager(database);
 }