Exemple #1
0
		public void Test_ReadingProducsFile_Length_ShouldFail()
		{
			ReadingFiles readingFiles = new ReadingFiles();

            Assert.AreNotEqual
                  (133, readingFiles.ReadProductsFile().Count);
		}
        // Making a product (and puts them into a list) from every line in the file products.csv
        public void GetAllProducts()
        {
            ReadingFiles    productsFile = new ReadingFiles();
            List <string[]> products     = productsFile.ReadProductsFile();

            foreach (string[] productLine in products)
            {
                int  intTemp;
                int  iD;
                bool active;

                if (int.TryParse(productLine[0], out intTemp))
                {
                    iD = intTemp;
                }
                else
                {
                    throw new ParseFailedException("Could not parse string to int");
                }

                string name = productsFile.RemoveHTMLCode(productLine[1]).Trim();

                // Dividing with 100 because the input was not in whole KR, but in ØRE
                decimal price = (decimal.Parse(productLine[2], NumberStyles.Any, CultureInfo.InvariantCulture) / 100);

                if (productLine[3] == "1")
                {
                    active = true;
                }
                else
                {
                    active = false;
                }

                // Making the list of products
                _listOfProducts.Add(new Product(iD, name, price, active));
            }
        }