Ejemplo n.º 1
0
        public void AcceptCoins_04_Pos_InvalidMetal_Returns_Metal()
        {
            // Arrange
            IContext context      = new DefaultContext();
            var      machine      = new Machine();
            var      invalidMetal = new Metal(0, 0, 0);
            var      result       = new Result();

            // Act
            machine.Insert(invalidMetal, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            // Assert
            Assert.AreEqual(1, context.CoinReturn.Items.Count());
        }
Ejemplo n.º 2
0
        public void Select_Product_Incorrect_Amount_Updates_Display()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.Price));
            Assert.IsTrue(context.DisplayAmount.MessageStack.Contains("$1.00"));
        }
Ejemplo n.º 3
0
        public void SelectProduct_02_Neg_Dispense_Moves_To_Start_Status()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();
            Thread.Sleep(50);

            // Arrange
            Assert.IsFalse(context.ProductReturn.Items.Any());
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.InsertCoin));
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.Price));
            Assert.IsTrue(context.DisplayAmount.MessageStack.Contains("$0.00"));
        }
Ejemplo n.º 4
0
        public void AcceptCoins_02_Neg_ValidMetal_Displays_Total_By_Running_Total()
        {
            // Arrange
            IContext context      = new DefaultContext();
            var      machine      = new Machine();
            var      metal        = Metal.Quarter;
            var      invalidMetal = new Metal(0, 0, 0);
            var      result       = new Result();

            // Act
            machine.Insert(invalidMetal, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            // Assert
            Assert.AreEqual(new decimal(0.0), context.TotalDeposit);
            Assert.AreEqual("$0.00", context.DisplayAmount.Current);
        }
Ejemplo n.º 5
0
        public void SelectProduct_Product_Dispense_Shows_Valid_Message()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(context.ProductReturn.Items.Any());
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains("THANK YOU"));
        }
Ejemplo n.º 6
0
        public void SelectProduct_01_Pos_Valid_Products()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "D", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsFalse(context.ProductReturn.Items.Any());
            Assert.IsFalse(context.DisplayAmount.MessageStack.Contains("$0.00"));
        }
Ejemplo n.º 7
0
        public void Select_Product_Correct_Amount_Inserted_Dispences()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(result.Success());
            Assert.IsTrue(context.ProductReturn.Items.Any());
        }
Ejemplo n.º 8
0
        public void ReturnCoins_01_Pos_Returns_Inserted_Coins()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Return(context, (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.AreEqual(4, context.CoinReturn.Items.Count());
            Assert.AreEqual(Tags.InsertCoin, context.DisplayMessage.Current);
        }
Ejemplo n.º 9
0
        public void SelectProduct_03_Neg_Not_Enough_Money_Deposited()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      result  = new Result();

            // Act
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(context.ProductReturn.Items.Any());
            Assert.IsFalse(context.DisplayMessage.MessageStack.Contains(Tags.Price));
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.InsertCoin));
            Assert.IsTrue(context.DisplayAmount.MessageStack.Contains("$1.00"));
        }
Ejemplo n.º 10
0
        public void SelectProduct_02_Pos_Dispense_Moves_To_Start_Status()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(context.ProductReturn.Items.Any());
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.ThankYou));
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.InsertCoin));
        }
Ejemplo n.º 11
0
        public void AcceptCoins_02_Pos_ValidMetal_Displays_Total_By_Value()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Success());
            Assert.AreEqual(new decimal(0.25), context.TotalDeposit);
            Assert.AreEqual("$0.25", context.DisplayAmount.Current);
        }
Ejemplo n.º 12
0
        public void SelectProduct_Inventory_Has_Items_Returns_Success()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(result.Success());
            Assert.AreEqual(1, context.ProductReturn.Items.Count());
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains("THANK YOU"));
            Assert.IsTrue(context.ProductReturn.Items.Any());
        }
Ejemplo n.º 13
0
        public void Select_Product_Amount_Too_Much_Makes_Change()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      metal   = Metal.Quarter;
            var      result  = new Result();

            // Act
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(metal, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "A", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.IsTrue(context.ProductReturn.Items.Any());
            Assert.IsTrue(context.CoinReturn.Items.Any());
        }
Ejemplo n.º 14
0
        public void MakeChange_01_Pos_Returns_Change()
        {
            // Arrange
            IContext context = new DefaultContext();
            var      machine = new Machine();
            var      result  = new Result();

            // Act
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Insert(Metal.Quarter, context, (r) => { result.Push(r); }).Wait();
            machine.Select(context, "B", (r) => { result.Push(r); }).Wait();

            // Arrange
            Assert.AreEqual(new decimal(1.50), context.CoinReturn.TotalValue());
            Assert.IsTrue(context.DisplayMessage.MessageStack.Contains(Tags.InsertCoin));
        }
Ejemplo n.º 15
0
        public void AcceptCoins_01_Pos_InvalidMetal_After_Valid_Returns_Metal()
        {
            // Arrange
            IContext context      = new DefaultContext();
            var      machine      = new Machine();
            var      invalidMetal = new Metal(0, 0, 0);
            var      result       = new Result();

            // Act
            machine.Insert(Metal.Quarter, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            machine.Insert(invalidMetal, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            // Assert
            Assert.IsTrue(context.CoinReturn.Items.Any());
            Assert.AreEqual("$0.25", context.DisplayAmount.Current);
        }
Ejemplo n.º 16
0
        public void AcceptCoins_02_Pos_ValidMetal_Updates_Display()
        {
            // Arrange
            var      result  = new Result();
            IContext context = new DefaultContext();
            var      machine = new Machine();

            // Act
            machine.Insert(Metal.Quarter, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            machine.Insert(Metal.Dime, context, (r) =>
            {
                result.Push(r);
            }).Wait();

            // Assert
            Assert.IsTrue(context.DisplayAmount.MessageStack.Contains("$0.25"));
            Assert.IsTrue(context.DisplayAmount.MessageStack.Contains("$0.35"));
            Assert.AreEqual(Tags.InsertCoin, context.DisplayMessage.Current);
        }