예제 #1
0
        private IList <Counter> SetupBankCounters(int capacity)
        {
            Counter depositCounter1     = new MonetoryTxnCounter(TokenType.Deposit, capacity);
            Counter withdrawCounter1    = new MonetoryTxnCounter(TokenType.Withdraw, capacity);
            Counter withdrawCounter2    = new MonetoryTxnCounter(TokenType.Withdraw, capacity);
            Counter nonMonetaryCounter1 = new NonMonetoryTxnCounter(TokenType.Other, capacity);
            Counter nonMonetaryCounter2 = new NonMonetoryTxnCounter(TokenType.Other, capacity);

            return(new List <Counter>
            {
                depositCounter1,
                withdrawCounter1,
                withdrawCounter2,
                nonMonetaryCounter1,
                nonMonetaryCounter2
            });
        }
예제 #2
0
        public void Assign_Invalid_Token_To_Counter_Throws_Exception_Test()
        {
            ITokenDistributor tokenDistributor = new UniformTokenDistributor();
            IBank             bank             = new Bank(tokenDistributor);

            //Create Non Monetory counters
            Counter nonMonetaryCounter1 = new NonMonetoryTxnCounter(TokenType.Other, 10);
            Counter nonMonetaryCounter2 = new NonMonetoryTxnCounter(TokenType.Other, 10);

            var counters = new List <Counter>
            {
                nonMonetaryCounter1,
                nonMonetaryCounter2
            };


            int maxCounterNumber = bank.Counters.Count;

            for (int index = maxCounterNumber + 1; index <= counters.Count; index++)
            {
                bank.Counters.Add('C' + index.ToString(), counters[index - (maxCounterNumber + 1)]);
            }

            //Assign 2 deposit tokens to each of these counters.
            VendingMachine.TokenList.Clear();

            var vendingMachine = VendingMachine.GetInstance();

            int noOfDepositTokens = 2;

            vendingMachine.GenerateTokens('D', noOfDepositTokens);

            var tokenType = VendingMachine.TokenList.Keys.ToList()[0].Type;
            //Act
            //Segregate and assign tokens to the appropriate counters.
            Action act = () => bank.AssignTokensToCounters(VendingMachine.TokenList.Keys.ToList());
            //assert
            var exception = Assert.Throws <InvalidOperationException>(act);

            //The thrown exception can be used for even more detailed assertions.

            Assert.Equal($"No appropriate counter available to process {tokenType} tokens", exception.Message);
        }