Example #1
0
        public void AddProduct(Product product)
        {
            Contract.Requires(Stock != null);
            Contract.Requires(product != null);
            Contract.Requires(product.Ammount > 0, "PRE: Added ammount must be > 0");
            Contract.Ensures(Contract.Exists(Stock, p => (string)p.Element("Name") == product.Name && (int)p.Element("Price") == product.Price), "POST: The added item must be in Stock");
            Contract.Ensures(Contract.OldValue((int)Stock.Where(el => (string)el.Element("Name") == product.Name).Single().Element("Ammount")) + product.Ammount ==
                   (int)Stock.Where(el => (string)el.Element("Name") == product.Name).Single().Element("Ammount"),
                   "POST: The ammount of items has to be added");

            if (CheckAvailability(product))
            {
                XElement node = Stock.Where(el => (string)el.Element("Name") == product.Name).Single();

                node.Element("Ammount").Value = ((int)node.Element("Ammount") + product.Ammount).ToString();
                node.Element("Price").Value = product.Price.ToString();
            }
            else
            {
                Stock.Last().AddAfterSelf(new XElement("Product", new XElement("Name", product.Name), new XElement("Price", product.Price), new XElement("Ammount", product.Ammount)));

            }

            Database.Save("StockDatabase.xml");
        }
Example #2
0
        public bool CheckAvailability(Product product)
        {
            Contract.Requires(Stock != null);
            Contract.Requires(product != null);

            return Stock.Any(p => (string)p.Element("Name") == product.Name && (int)p.Element("Ammount") > 0);
        }
Example #3
0
 private void faxeB_Click(object sender, EventArgs e)
 {
     Product prod = new Product("faxe");
     machine.SelectProduct(prod);
     // update disp
     decimal valueToBeInserted = machine.SelectedProduct.Price - machine.InsertedValue;
     dispL.Text = prepareDisp(valueToBeInserted);
     purchaseB.Enabled = true;
 }
Example #4
0
        public void EjectProduct(Product product, LinkedList<Product> productCase)
        {
            Contract.Requires(CheckAvailability(product), "PRE: Sought item must be in stock");
            Contract.Requires(Stock != null);
            Contract.Requires(productCase != null);
            Contract.Requires(product != null);
            Contract.Ensures(productCase.Contains(product), "POST: Sought item must be ejected");
            Contract.Ensures(Contract.OldValue((int)Stock.Where(el => (string)el.Element("Name") == product.Name).Single().Element("Ammount")) - 1 ==
                   (int)Stock.Where(el => (string)el.Element("Name") == product.Name).Single().Element("Ammount"));

            XElement node = Stock.Where(el => (string)el.Element("Name") == product.Name).Single();
            node.Element("Ammount").Value = ((int)node.Element("Ammount") - 1).ToString();

            productCase.AddLast(new Product(product.Name,1,product.Price));

            Database.Save("StockDatabase.xml");
        }
Example #5
0
        public decimal GetPrice(Product product)
        {
            Contract.Requires(Contract.Exists(Stock, p => (string)p.Element("Name") == product.Name), "PRE: Sought item must be known");
            Contract.Requires(Stock != null);
            Contract.Requires(product != null);

            return (decimal)Stock.Where(p => (string)p.Element("Name") == product.Name).Select(p => p.Element("Price")).First();
        }
Example #6
0
 internal void AddProduct([PexAssumeUnderTest]StockManager target, Product product)
 {
     target.AddProduct(product);
 }
Example #7
0
        public static Product Create(string name, int amm, decimal price)
        {
            Product prod = new Product(name, amm, price);

            return prod;
        }
Example #8
0
        public TransactionResult SelectProduct(Product product)
        {
            Contract.Requires(state == State.Idle || state == State.ProductChosen);

            if(StockMan.CheckAvailability(product))
            {
                SelectedProduct = product;
                SelectedProduct.Price = StockMan.GetPrice(SelectedProduct);
                state = State.ProductChosen;

                return TransactionResult.Success;
            }

            return TransactionResult.OutOfStock;
        }
Example #9
0
 public TransactionResult CheckProduct(Product product)
 {
     if (StockMan.CheckAvailability(product))
     {
         return TransactionResult.Success;
     }
     return TransactionResult.OutOfStock;
 }