Esempio n. 1
0
        public StockReportModel GetIncomingStockReport()
        {
            RestaurantStock stock = null;

            var path = "c:\\temp\\stockshipped.json";

            if (File.Exists(path))
            {
                using (StreamReader r = new StreamReader(path))
                {
                    string json  = r.ReadToEnd();
                    var    items = JsonConvert.DeserializeObject <RestaurantStock>(json);
                    stock = items;
                }
            }


            var reportModel = new StockReportModel
            {
                ReportTitle = "Incoming Stock Being Delivered This Month",
                Stock       = stock
            };

            return(reportModel);
        }
        public RestaurantStock GetStockItems(IList <Order> orders)
        {
            var stock = new RestaurantStock();

            var tiramisuTotal = GetTotalNumberOfTiramisuOrdered(orders);

            stock.Eggs = tiramisuTotal * 3;

            return(stock);
        }
Esempio n. 3
0
        public void SetStockQuantity(RestaurantStock stock)
        {
            var path = "c:\\temp\\stockshipped.json";

            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, stock);
            }
        }
Esempio n. 4
0
        public void PlaceStockOrder(RestaurantStock stock)
        {
            var path = "c:\\temp\\stockorder.json";

            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, stock);
            }
        }
 public void InitializeReadingTest()
 {
     RedoFiles();
     /// Read Stock file elements
     stock = fileInterface.ReadStockFile(TestStockCsv);
     Assert.AreEqual(5, stock.GetElementCount());
     /// Read Menu file elements
     menu = fileInterface.ReadMenuFile(TestMenuCsv);
     Assert.AreEqual(3, menu.GetElementCount());
     orders = fileInterface.ReadOrdersFile(TestOrdersCsv, menu);
     Assert.AreEqual(5, orders.GetElementCount());
 }
        public void RemoveStockItem()
        {
            /// Read elements from list
            InitializeReadingTest();
            StockItem removableItem = stock.GetItemByID(2);
            int       removableId   = removableItem.GetId();

            /// Remove item from list
            Program.RemoveElement(TestStockCsv, stock, removableId);
            Assert.IsFalse(stock.DoesItemExistsByID(removableId));
            RestaurantStock newStock = fileInterface.ReadStockFile(TestStockCsv);

            Assert.IsFalse(newStock.DoesItemExistsByID(removableId));
        }
        public void UpdateStockItem()
        {
            /// Read elements from list
            InitializeReadingTest();
            StockItem updatedItem = new StockItem(3, "Ketchup", 2000, "ml", 50);

            /// Update stock items proportion
            Program.UpdateElement(stock, updatedItem, TestStockCsv);
            Assert.AreEqual(2000, stock.GetItemByID(3).GetPortionCount());
            /// Check if writing is successful to file
            RestaurantStock newStock = fileInterface.ReadStockFile(TestStockCsv);

            Assert.AreEqual(2000, newStock.GetItemByID(3).GetPortionCount());
        }
        public void AddNewStockItem()
        {
            /// Read elements from list
            InitializeReadingTest();
            /// Addable elements
            StockItem addableStockItem = new StockItem(6, "Chicken Wings", 2.0, "kg", 0.4);

            /// Check if items are added in array
            Program.AddElement(stock, addableStockItem, TestStockCsv);
            Assert.AreEqual(6, stock.GetElementCount());
            /// Check if items are stored in csv file
            RestaurantStock newStock = fileInterface.ReadStockFile(TestStockCsv);

            Assert.AreEqual(6, newStock.GetElementCount());
        }
        public void CreateNewOrder_Successful()
        {
            /// Read elements from list
            InitializeReadingTest();
            OrderItem newOrder = new OrderItem(6, DateTime.Now,
                                               new List <MenuItem> {
                menu.GetItemByID(1)
            });

            /// Check if items are added to array
            Program.AddElement(newOrder, TestOrdersCsv, TestStockCsv, stock, orders);
            Assert.AreEqual(6, orders.GetElementCount());
            /// Check if order is existing in file
            RestaurantOrders newOrders = fileInterface.ReadOrdersFile(TestOrdersCsv, menu);
            RestaurantStock  newStock  = fileInterface.ReadStockFile(TestStockCsv);

            Assert.AreEqual(4.7, newStock.GetItemByID(2).GetPortionCount());
            Assert.AreEqual(6, newOrders.GetElementCount());
        }
        /// <summary>
        /// Method for reading restaurant stock file from given path
        /// </summary>
        /// <param name="path">String Path to file</param>
        /// <returns>Returns RestaurantStock object with read data from file</returns>
        public RestaurantStock ReadStockFile(string path)
        {
            RestaurantStock stock = new RestaurantStock();

            /// Check if stock item file exists
            /// If not, create it with headers
            if (!File.Exists(path))
            {
                using (StreamWriter wr = new StreamWriter(path))
                {
                    wr.WriteLine("Id,Name,Portion Count,Unit,Portion Size");
                    wr.Close();
                }
            }
            /// Else read the file
            else
            {
                using (StreamReader rd = new StreamReader(path))
                {
                    /// Read header
                    string line = rd.ReadLine();
                    while ((line = rd.ReadLine()) != null)
                    {
                        string[]  data         = line.Split(',');
                        int       id           = int.Parse(data[0]);
                        string    name         = data[1];
                        double    portionCount = double.Parse(data[2]);
                        string    unit         = data[3];
                        double    portionSize  = double.Parse(data[4]);
                        StockItem item         = new StockItem(id, name, portionCount, unit, portionSize);
                        stock.AddNewEntry(item);
                    }
                    rd.Close();
                }
            }
            return(stock);
        }
Esempio n. 11
0
        public StockReportModel GetStockItemToOrder()
        {
            RestaurantStock stock = null;

            var path = "c:\\temp\\stockorder.json";

            if (File.Exists(path))
            {
                using (StreamReader r = new StreamReader(path))
                {
                    string json  = r.ReadToEnd();
                    var    items = JsonConvert.DeserializeObject <RestaurantStock>(json);
                    stock = items;
                }
            }

            var reportModel = new StockReportModel
            {
                ReportTitle = "Items of Stock that Require Ordering",
                Stock       = stock
            };

            return(reportModel);
        }