Exemplo n.º 1
0
        public void TestOff()
        {
            // setup the tested class instance and dependencies with the test case initialization.
            MockDisplayPanel             displayPanel      = new MockDisplayPanel();
            MockOrderPanel               orderPanel        = new MockOrderPanel();
            MockPaymentReceiver          paymentReceiver   = new MockPaymentReceiver();
            MockVendingMessageRepository messageRepository = new MockVendingMessageRepository();
            ProductRepository            productRepository = new ProductRepository();
            WalletRepository             walletRepository  = new WalletRepository();
            SoldRecord saleRecord = new SoldRecord();
            VendingMachineController vendingMachineController = new VendingMachineController(displayPanel, paymentReceiver, orderPanel, productRepository, walletRepository, saleRecord, messageRepository);

            // Test subject Action - off
            vendingMachineController.Off();

            // verify - off
            Assert.True(orderPanel.OffCalled);
            Assert.True(paymentReceiver.OffCalled);

            Assert.Equal(VendingMachineState.TurnedOff, vendingMachineController.VendingMachineState);

            // verify the  message flow
            List <MessageCode> TestCatchedCodes = new List <MessageCode>
            {
                MessageCode.OutOfServise
            };

            Assert.Equal((IEnumerable <MessageCode>)TestCatchedCodes, (IEnumerable <MessageCode>)messageRepository.CatchedCodes);
            Assert.Equal((IEnumerable <string>)messageRepository.ReturnList, (IEnumerable <string>)displayPanel.DisplayList);
        }
Exemplo n.º 2
0
        public void TestOutOfStockFromOrderPanel()
        {
            // setup the tested class instance and dependencies with the test case initialization.
            MockDisplayPanel             displayPanel      = new MockDisplayPanel();
            MockOrderPanel               orderPanel        = new MockOrderPanel();
            MockPaymentReceiver          paymentReceiver   = new MockPaymentReceiver();
            MockVendingMessageRepository messageRepository = new MockVendingMessageRepository();
            ProductRepository            productRepository = new ProductRepository();
            WalletRepository             walletRepository  = new WalletRepository();
            SoldRecord saleRecord = new SoldRecord();
            VendingMachineController vendingMachineController = new VendingMachineController(displayPanel, paymentReceiver, orderPanel, productRepository, walletRepository, saleRecord, messageRepository);

            InitProductRepository(productRepository, 0, 0);
            // !!! setup order state
            vendingMachineController.VendingMachineState = VendingMachineState.Order;

            // Test subject Action - out of stock
            orderPanel.InvokeOrderAction(OrderCmdEvent.OutOfStock, null);

            Assert.Equal(VendingMachineState.OutOfStock, vendingMachineController.VendingMachineState);

            // verify - out of stock
            Assert.True(orderPanel.OffCalled);
            Assert.Equal(0, productRepository.CountProduct(PrdA.Code));

            // verify the  message flow
            List <MessageCode> TestCatchedCodes = new List <MessageCode>
            {
                MessageCode.OutOfStock
            };

            Assert.Equal((IEnumerable <MessageCode>)TestCatchedCodes, (IEnumerable <MessageCode>)messageRepository.CatchedCodes);
            Assert.Equal((IEnumerable <string>)messageRepository.ReturnList, (IEnumerable <string>)displayPanel.DisplayList);
        }
Exemplo n.º 3
0
        public void TestSelectOrderFromOrderPanel()
        {
            // setup the tested class instance and dependencies with the test case initialization.
            MockDisplayPanel             displayPanel      = new MockDisplayPanel();
            MockOrderPanel               orderPanel        = new MockOrderPanel();
            MockPaymentReceiver          paymentReceiver   = new MockPaymentReceiver();
            MockVendingMessageRepository messageRepository = new MockVendingMessageRepository();
            ProductRepository            productRepository = new ProductRepository();
            WalletRepository             walletRepository  = new WalletRepository();
            SoldRecord saleRecord = new SoldRecord();
            VendingMachineController vendingMachineController = new VendingMachineController(displayPanel, paymentReceiver, orderPanel, productRepository, walletRepository, saleRecord, messageRepository);

            InitProductRepository(productRepository, 1, 1);
            // !!! setup order state
            vendingMachineController.VendingMachineState = VendingMachineState.Order;

            // Test subject Action - select order as product A
            orderPanel.InvokeOrderAction(OrderCmdEvent.Select, PrdA);

            Assert.Equal(VendingMachineState.Payment, vendingMachineController.VendingMachineState);

            // verify - select order as product A
            Assert.True(orderPanel.OffCalled);
            Assert.True(paymentReceiver.OnCalled);
            Assert.Equal(0, productRepository.CountProduct(PrdA.Code));

            // verify the  message flow
            List <MessageCode> TestCatchedCodes = new List <MessageCode>
            {
                MessageCode.Checkout
            };

            Assert.Equal(TestCatchedCodes, messageRepository.CatchedCodes);
            Assert.Equal(messageRepository.ReturnList, displayPanel.DisplayList);
        }
Exemplo n.º 4
0
        public void TestOrderPaymentChangeGivenFromOrderPanel()
        {
            // setup the tested class instance and dependencies with the test case initialization.
            MockDisplayPanel             displayPanel      = new MockDisplayPanel();
            MockOrderPanel               orderPanel        = new MockOrderPanel();
            MockPaymentReceiver          paymentReceiver   = new MockPaymentReceiver();
            MockVendingMessageRepository messageRepository = new MockVendingMessageRepository();
            ProductRepository            productRepository = new ProductRepository();
            WalletRepository             walletRepository  = new WalletRepository();
            SoldRecord saleRecord = new SoldRecord();
            VendingMachineController vendingMachineController = new VendingMachineController(displayPanel, paymentReceiver, orderPanel, productRepository, walletRepository, saleRecord, messageRepository);

            InitProductRepository(productRepository, 1, 1);
            // !!! setup order state
            vendingMachineController.VendingMachineState = VendingMachineState.Order;

            // setup wallet repository
            walletRepository.AddToWallet(new Coin(5), 1);
            walletRepository.AddToWallet(new Coin(10), 1);
            walletRepository.AddToWallet(new Coin(20), 1);
            walletRepository.AddToWallet(new Coin(50), 1);
            var before = walletRepository.WalletList.Aggregate(Money.Zero, (m, p) => m + new Money(0, (int)p.Item1.Nominal * p.Item2));

            // Test subject Action - select order as product A
            orderPanel.InvokeOrderAction(OrderCmdEvent.Select, PrdA);

            Assert.Equal(VendingMachineState.Payment, vendingMachineController.VendingMachineState);

            // verify reserved product
            Assert.Equal(PrdA, vendingMachineController.OrderedProducts[0]);

            // complete payment without change
            paymentReceiver.InvokeCoinAction(PaymentCmdEvent.Payment, new Coin(100));

            // verify switch back to order state
            Assert.True(paymentReceiver.OffCalled);
            Assert.True(orderPanel.OnCalled);
            Assert.Equal(VendingMachineState.Order, vendingMachineController.VendingMachineState);

            // verify money in the wallet
            var total = walletRepository.WalletList.Aggregate(Money.Zero, (m, p) => m + new Money(0, (int)p.Item1.Nominal * p.Item2));

            Assert.Equal(before + PrdA.Price, total);

            // verify the  message flow
            List <MessageCode> TestCatchedCodes = new List <MessageCode>
            {
                MessageCode.Checkout,
                MessageCode.BalancePayment,
                MessageCode.GivenChange,
                MessageCode.GivenChange,
                MessageCode.GivenChange,
                MessageCode.CollectYourPurchase,
                MessageCode.ReadyToService,
            };

            Assert.Equal((IEnumerable <MessageCode>)TestCatchedCodes, (IEnumerable <MessageCode>)messageRepository.CatchedCodes);
            Assert.Equal((IEnumerable <string>)messageRepository.ReturnList, (IEnumerable <string>)displayPanel.DisplayList);
        }
Exemplo n.º 5
0
        public void TestFaultExceptionEvent1()
        {
            // setup the tested class instance and dependencies with the test case initialization.
            MockDisplayPanel             displayPanel      = new MockDisplayPanel();
            MockOrderPanel               orderPanel        = new MockOrderPanel();
            MockPaymentReceiver          paymentReceiver   = new MockPaymentReceiver();
            MockVendingMessageRepository messageRepository = new MockVendingMessageRepository();
            ProductRepository            productRepository = new ProductRepository();
            WalletRepository             walletRepository  = new WalletRepository();
            SoldRecord saleRecord = new SoldRecord();
            VendingMachineController vendingMachineController = new VendingMachineController(displayPanel, paymentReceiver, orderPanel, productRepository, walletRepository, saleRecord, messageRepository);

            // Test subject Action - Exception orderPanel
            orderPanel.InvokeFailtException(new Exception());

            // verify - Exception orderPanel
            Assert.True(orderPanel.OffCalled);
            Assert.True(paymentReceiver.OffCalled);
            Assert.Equal(VendingMachineState.Fault, vendingMachineController.VendingMachineState);
        }