예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }