Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            machine = new VendMachine();
            prepareOutOfStockLights();

            CoinManager coins = new CoinManager();
            coins.EjectCoin(Coin.Ore50, 1, new LinkedList<Coin>());
        }
Esempio n. 2
0
        public void VendMachineOutOfStock()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>1</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";
            string doc1 =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
                <Product>
                <Name>coke</Name>
                <Price>5</Price>
                <Ammount>0</Ammount>
              </Product>
              <Product>
                <Name>faxe</Name>
                <Price>12</Price>
                <Ammount>10</Ammount>
              </Product>
              <Product>
                <Name>daim</Name>
                <Price>7</Price>
                <Ammount>1</Ammount>
              </Product>
              </Root>";

            VendMachine cos = new VendMachine(XDocument.Parse(doc1), XDocument.Parse(doc));
            TransactionResult result = cos.SelectProduct(new Product("coke"));
            Assert.AreEqual(TransactionResult.OutOfStock, result);
            try
            {
                result = cos.InsertCoin(Coin.Kr5);
                result = cos.Finalize();
                Assert.Fail();
            }
            catch (Exception) { }
        }
Esempio n. 3
0
        public void VendMachineProductAvailable()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>1</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";
            string doc1 =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
                <Product>
                <Name>coke</Name>
                <Price>10</Price>
                <Ammount>5</Ammount>
              </Product>
              <Product>
                <Name>faxe</Name>
                <Price>12</Price>
                <Ammount>0</Ammount>
              </Product>
              <Product>
                <Name>daim</Name>
                <Price>7</Price>
                <Ammount>1</Ammount>
              </Product>
              </Root>";

            VendMachine cos = new VendMachine(XDocument.Parse(doc1), XDocument.Parse(doc));
            TransactionResult result = cos.CheckProduct(new Product("daim"));

            Assert.AreEqual(TransactionResult.Success, result);
            result = cos.CheckProduct(new Product("faxe"));

            Assert.AreEqual(TransactionResult.OutOfStock, result);
        }
Esempio n. 4
0
        public void VendMachineCancel()
        {
            string doc =
               @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
              <Coin>
                <Type>0.5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>1</Type>
                <Ammount>1</Ammount>
              </Coin>
              <Coin>
                <Type>2</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>5</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>10</Type>
                <Ammount>0</Ammount>
              </Coin>
              <Coin>
                <Type>20</Type>
                <Ammount>0</Ammount>
              </Coin>
              </Root>";
            string doc1 =
            @"<?xml version=""1.0"" encoding=""utf-8"" ?>
            <Root>
                <Product>
                <Name>coke</Name>
                <Price>10</Price>
                <Ammount>5</Ammount>
              </Product>
              <Product>
                <Name>faxe</Name>
                <Price>12</Price>
                <Ammount>10</Ammount>
              </Product>
              <Product>
                <Name>daim</Name>
                <Price>7</Price>
                <Ammount>1</Ammount>
              </Product>
              </Root>";

            VendMachine cos = new VendMachine(XDocument.Parse(doc1), XDocument.Parse(doc));
            TransactionResult result = cos.SelectProduct(new Product("daim"));
            Assert.AreNotEqual(TransactionResult.Failure, result);

            cos.Cancel();
            result = cos.SelectProduct(new Product("faxe"));
            Assert.AreNotEqual(TransactionResult.Failure, result);
            cos.Cancel();
             result = cos.SelectProduct(new Product("daim"));
            Assert.AreNotEqual(TransactionResult.Failure, result);

            result = cos.InsertCoin(Coin.Kr5);
            Assert.AreNotEqual(TransactionResult.Failure, result);
            cos.Cancel();
            result = cos.SelectProduct(new Product("faxe"));
            Assert.AreNotEqual(TransactionResult.Failure, result);
            result = cos.InsertCoin(Coin.Kr2);
            Assert.AreNotEqual(TransactionResult.Failure, result);
            result = cos.InsertCoin(Coin.Kr20);
            Assert.AreNotEqual(TransactionResult.Failure, result);

            result = cos.Finalize();
            Assert.AreEqual(TransactionResult.Success, result);
        }