コード例 #1
0
        public void TestImplementsInterface()
        {
            VendingDisplayController displayController = new VendingDisplayController(new TextBox(), new MockCoinPurse());

            Assert.IsInstanceOf(typeof (IDisplayController), displayController);
            Assert.IsInstanceOf(typeof (ICoinPurseObserver), displayController);
        }
コード例 #2
0
        public void TestRegistersItselfAsObserverWithCoinPurse()
        {
            MockCoinPurse mockCoinPurse = new MockCoinPurse();
            VendingDisplayController displayController = new VendingDisplayController(new TextBox(), mockCoinPurse);

            Assert.AreEqual(1, mockCoinPurse.NumberOfTimesRegisterObserverWasCalled);
            Assert.AreEqual(displayController, mockCoinPurse.RegisteredCoinPurseObservers[0]);
        }
コード例 #3
0
        public void TestProperties()
        {
            TextBox expectedTextBox = new TextBox();
            MockCoinPurse expectedCoinPurse = new MockCoinPurse();

            VendingDisplayController displayController = new VendingDisplayController(expectedTextBox, expectedCoinPurse);

            Assert.AreSame(expectedTextBox, displayController.Display);
            Assert.AreSame(expectedCoinPurse, displayController.CoinPurse);
        }
コード例 #4
0
        public void TestSetsCurrentPurseValueFormatedLikeMoneyWhenCoinPurseNotifiesAmountHasChanged(decimal purseValue,
            string expectedDisplayText)
        {
            TextBox displayTextBox = new TextBox();
            MockCoinPurse mockCoinPurse = new MockCoinPurse {AmountAvailableToReturn = purseValue};

            VendingDisplayController displayController = new VendingDisplayController(displayTextBox, mockCoinPurse);

            displayController.CoinPurseUpdated();

            Assert.AreEqual(expectedDisplayText, displayTextBox.Text);
        }
コード例 #5
0
        public void TestSetsDisplayTestBackToInitialMessageIfCoinPurseIsZero()
        {
            TextBox displayTextBox = new TextBox();
            MockCoinPurse mockCoinPurse = new MockCoinPurse {AmountAvailableToReturn = 0.99m};

            VendingDisplayController displayController = new VendingDisplayController(displayTextBox, mockCoinPurse);

            displayController.CoinPurseUpdated();

            Assert.AreNotEqual("INSERT COINS", displayTextBox.Text);

            mockCoinPurse.AmountAvailableToReturn = 0;
            displayController.CoinPurseUpdated();

            Assert.AreEqual("INSERT COINS", displayTextBox.Text);
        }
コード例 #6
0
        public MainFormController(Form form)
        {
            MainForm = form;

            CoinAccepter = new CoinAccepter(CoinFactory, CoinPurse, CoinReturn);

            DisplayController = new VendingDisplayController(GetTextBoxFromForm(DisplayTextBoxName), CoinPurse);

            ReturnChangeButtonController = new ReturnChangeButtonController(GetButtonFromForm(ChangeReturnButtonName),
                CoinPurse, CoinReturn);

            InsertCoinButtonPanel = new InsertCoinButtonPanel(GetButtonFromForm(InsertPennyButtonName),
                GetButtonFromForm(InsertNickelButtonName),
                GetButtonFromForm(InsertDimeButtonName),
                GetButtonFromForm(InsertQuarterButtonName));

            InsertCoinButtonPanelController = new InsertCoinButtonPanelController(InsertCoinButtonPanel, CoinAccepter);

            CoinReturnDisplayController =
                new CoinReturnDisplayController(GetTextBoxFromForm(CoinReturnDisplayTextBoxName), CoinReturn);

            ClearCoinReturnButtonController =
                new ClearCoinReturnButtonController(GetButtonFromForm(ClearCoinReturnButtonName), CoinReturn, new DialogService());
        }