public void GetProductAndNameTests() { using (DataBaseDataContext db = new DataBaseDataContext()) { ToolsProduct toolsProduct = new ToolsProduct(); List <Product> all = (from p in db.Products select p).ToList(); List <Product> query = toolsProduct.GetProductsByName("Thin-Jam Hex Nut"); query.Sort((x, y) => x.ProductID.CompareTo(y.ProductID)); List <String> productsAndNames = query.GetProductAndName().Split('\n').ToList(); for (int i = 0; i < query.Count; i++) { Assert.AreEqual(all.Find(x => x.ProductID == 359 + i).Name + " - " + "Advanced Bicycles", productsAndNames[i]); } } }
public void GetProductsByNameTest() { using (DataBaseDataContext db = new DataBaseDataContext()) { ToolsProduct toolsProduct = new ToolsProduct(); List <Product> queryFromMethod = toolsProduct.GetProductsByName("Crankarm"); queryFromMethod.Sort((x, y) => x.ProductID.CompareTo(y.ProductID)); List <Product> queryFromDB = new List <Product>(); Product product = (from p in db.Products where p.ProductID == 317 select p).First(); queryFromDB.Add(product); product = (from p in db.Products where p.ProductID == 318 select p).First(); queryFromDB.Add(product); product = (from p in db.Products where p.ProductID == 319 select p).First(); queryFromDB.Add(product); for (int i = 0; i < queryFromMethod.Count(); i++) { Assert.AreEqual(queryFromDB[i].ProductID, queryFromMethod[i].ProductID); Assert.AreEqual(queryFromDB[i].Name, queryFromMethod[i].Name); } Assert.AreEqual(queryFromDB.Count(), queryFromMethod.Count()); } }