예제 #1
0
        public void TestImplementsInterface()
        {
            CoinReturnDisplayController coinReturnDisplayController = new CoinReturnDisplayController(new TextBox(),
                                                                                                      new MockCoinReturn());

            Assert.IsInstanceOf(typeof(IDisplayController), coinReturnDisplayController);
            Assert.IsInstanceOf(typeof(ICoinReturnObserver), coinReturnDisplayController);
        }
예제 #2
0
        public void TestRegistersSelfAsObserverWithCoinReturn()
        {
            MockCoinReturn mockCoinReturn = new MockCoinReturn();
            CoinReturnDisplayController coinReturnDisplayController = new CoinReturnDisplayController(new TextBox(),
                                                                                                      mockCoinReturn);

            Assert.AreEqual(1, mockCoinReturn.NumberOfTimesRegisterObserverWasCalled);
            Assert.AreSame(coinReturnDisplayController, mockCoinReturn.ObserversPassedToRegisterObserver[0]);
        }
예제 #3
0
        public void TestProperties()
        {
            MockCoinReturn expectedCoinReturn = new MockCoinReturn();
            TextBox        expectedTextBox    = new TextBox();

            CoinReturnDisplayController coinReturnDisplayController = new CoinReturnDisplayController(expectedTextBox,
                                                                                                      expectedCoinReturn);

            Assert.AreEqual(expectedCoinReturn, coinReturnDisplayController.CoinReturn);
            Assert.AreEqual(expectedTextBox, coinReturnDisplayController.Display);
        }
        public void TestCorrectlyBuildsCoinReturnDisplayController()
        {
            Form    mainForm        = new Form();
            TextBox expectedTextBox = new TextBox()
            {
                Name = "CoinReturnDisplayTextBox"
            };

            mainForm.Controls.Add(expectedTextBox);

            MainFormController mainFormController = new MainFormController(mainForm);

            CoinReturnDisplayController coinReturnDisplayController = mainFormController.CoinReturnDisplayController;

            Assert.IsInstanceOf(typeof(CoinReturnDisplayController), coinReturnDisplayController);
            Assert.AreEqual(expectedTextBox, coinReturnDisplayController.Display);
            Assert.AreEqual(mainFormController.CoinReturn, coinReturnDisplayController.CoinReturn);
        }
예제 #5
0
        public void TestUpdatesDisplayTextWithCoinReturnValueWhenCoinReturnUpdatedIsCalled(
            decimal valueToReturnFromCoinReturn, string expectedUpdatedText)
        {
            MockCoinReturn mockCoinReturn = new MockCoinReturn();
            TextBox        displayTextBox = new TextBox();

            CoinReturnDisplayController coinReturnDisplayController = new CoinReturnDisplayController(displayTextBox,
                                                                                                      mockCoinReturn);

            const string expectedStartingAmountBecauseTheMockReturnsAnAmoutOfZeroByDefualt = "$0.00";

            Assert.AreEqual(expectedStartingAmountBecauseTheMockReturnsAnAmoutOfZeroByDefualt, displayTextBox.Text);

            mockCoinReturn.ValueToReturnFromAmountAvailable = valueToReturnFromCoinReturn;

            coinReturnDisplayController.CoinReturnUpdated();

            Assert.AreEqual(expectedUpdatedText, 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());
        }