示例#1
0
        public void InsertMoney_GivenUnacceptableMoney_ThrowsException()
        {
            // Arrange
            IVMLogic vml = new VMLogic();

            // Act & Assert
            Assert.Throws <ArgumentException>(() => vml.InsertMoney(-1));
        }
示例#2
0
        public void Purchase_InsufficientMoney_ReturnsNull()
        {
            // Arrange
            IVMLogic vml = new VMLogic();


            // Act & Assert
            Assert.Throws <ArgumentException>(() => vml.Purchase(1));
        }
示例#3
0
        public void Restock_BadStuff_ThrowsException()
        {
            // Arrange
            IVMLogic vml = new VMLogic();


            // Act & Assert
            Assert.Throws <ArgumentException>(() => vml.Restock(0, new Cookie()));
            Assert.Throws <ArgumentException>(() => vml.Restock(vml.GetAvailableProducts().Length + 1, new Cookie()));
            Assert.Throws <ArgumentException>(() => vml.Restock(1, null));
        }
示例#4
0
        public void GetCreditInMoneyDenominators()
        {
            // Arrange
            IVMLogic vml = new VMLogic();

            // Act & Assert
            //1
            Assert.Equal("", vml.GetCreditInMoneyDenominators()); //No money, no string

            //2
            int biggest = vml.GetAcceptableMoneyDenominators()[^ 1];
示例#5
0
        public void Restock_GoodStuff_ItsAddedInTheSystem()
        {
            // Arrange
            IVMLogic vml        = new VMLogic();
            IProduct newProduct = new Cookie();
            int      bignumber  = 999;

            while (bignumber-- > 0)
            {
                vml.InsertMoney(vml.GetAcceptableMoneyDenominators()[0]); //Add tons of acceptable money to the system
            }
            // Act
            vml.Restock(2, newProduct);

            // Assert
            Assert.Equal(newProduct, vml.Purchase(2));
        }
示例#6
0
        public void Purchase_SufficientMoney_ReturnsTheProduct()
        {
            // Arrange
            IVMLogic vml = new VMLogic();

            // Act
            int bignumber = 999;

            while (bignumber-- > 0)
            {
                vml.InsertMoney(vml.GetAcceptableMoneyDenominators()[0]); //Add tons of acceptable money to the system
            }
            ProductInfo pinfo  = vml.GetAvailableProducts()[0];
            IProduct    result = vml.Purchase(1);

            // Assert
            Assert.Equal(pinfo.Id, result.Examine().Id);
        }
示例#7
0
        public void InsertMoney_GivenAcceptableMoney_StoresMyMoney()
        {
            // Arrange
            IVMLogic vml = new VMLogic();

            // Act
            int[] okMoney = vml.GetAcceptableMoneyDenominators();
            int   sum     = 0;

            foreach (var item in okMoney)
            {
                vml.InsertMoney(item);
                sum += item;
            }

            // Assert
            Assert.Equal(sum, vml.RetrieveChange());
            Assert.Equal(0, vml.RetrieveChange()); //Retrieving the change should remove money from system
        }