public void TestAcceptCallsBuildOnCoinFactoryWithSizeAndWeightPassed(CoinSize coinSize)
        {
            MockCoinFactory mockCoinFactory = new MockCoinFactory();
            CoinAccepter    coinAccepter    = new CoinAccepter(mockCoinFactory, new MockCoinPurse(), new MockCoinReturn());

            coinAccepter.Accept(coinSize);

            Assert.AreEqual(1, mockCoinFactory.NumberOfTimesBuildCoinCalled);
            Assert.AreEqual(coinSize, mockCoinFactory.LastSizeAndWeightPassed);
        }
        public void TestProperties()
        {
            MockCoinFactory expectedCoinFactory = new MockCoinFactory();
            MockCoinPurse   expectedCoinPurse   = new MockCoinPurse();
            MockCoinReturn  expectedCoinReturn  = new MockCoinReturn();

            CoinAccepter coinAccepter = new CoinAccepter(expectedCoinFactory, expectedCoinPurse, expectedCoinReturn);

            Assert.AreSame(expectedCoinFactory, coinAccepter.CoinFactory);
            Assert.AreSame(expectedCoinPurse, coinAccepter.CoinPurse);
            Assert.AreSame(expectedCoinReturn, coinAccepter.CoinReturn);
        }
        public void TestAcceptAddsCoinReturnedByCoinFactoryToCoinPurseIfItHasValue()
        {
            MockCoinFactory mockCoinFactory = new MockCoinFactory();
            MockCoinPurse   mockCoinPurse   = new MockCoinPurse();

            MockCoin expectedCoin = new MockCoin {
                ValueToReturn = decimal.MaxValue
            };

            mockCoinFactory.CoinToReturn = expectedCoin;

            CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, new MockCoinReturn());

            coinAccepter.Accept(CoinSize.Tiny);

            Assert.AreEqual(1, mockCoinPurse.NumberOfTimesAddCoinWasCalled);
            Assert.AreEqual(1, mockCoinPurse.CoinsPassedToAddCoin.Count);
            Assert.AreEqual(expectedCoin, mockCoinPurse.CoinsPassedToAddCoin[0]);
        }
        public void TestCoinWithNoValueIsPutIntoTheCoinReturnAndNotTheCoinPurse(decimal coinValue)
        {
            MockCoinFactory mockCoinFactory = new MockCoinFactory();
            MockCoinPurse   mockCoinPurse   = new MockCoinPurse();
            MockCoinReturn  mockCoinReturn  = new MockCoinReturn();

            MockCoin mockCoin = new MockCoin {
                ValueToReturn = coinValue
            };

            mockCoinFactory.CoinToReturn = mockCoin;

            CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, mockCoinReturn);

            coinAccepter.Accept(CoinSize.Large);

            Assert.AreSame(mockCoin, mockCoinReturn.CoinsPassedToAddCoin[0]);
            Assert.AreEqual(1, mockCoinReturn.NumberOfTimesAddCoinCalled);
            Assert.AreEqual(0, mockCoinPurse.NumberOfTimesAddCoinWasCalled);
            Assert.AreEqual(0, mockCoinPurse.Coins.Count);
        }
Пример #5
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());
        }