public void GetProductAndVendor() { using (ProductionDataContext productionDataContext = new ProductionDataContext()) { List <Product> products = productionDataContext.GetTable <Product>().ToList(); List <ProductVendor> vendors = productionDataContext.GetTable <ProductVendor>().ToList(); string result = products.DeclarativeGetProductAndVendor(vendors); string result2 = products.ImperativeGetProductAndVendor(vendors); Assert.AreEqual(result, result2); Assert.AreEqual(result.Length, 17058); Assert.IsTrue(result.Contains("Hex Nut 14-Norstan Bike Hut")); } }
public void ListPGetVendorProductListLambdaTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <ProductVendor> vendors = dataContext.GetTable <ProductVendor>().ToList(); string answer = products.GetVendorProductListLambda(vendors); string[] lines = answer.Split('\n'); Assert.IsTrue(lines.Contains("Bearing Ball - Wood Fitness")); Assert.IsTrue(lines.Contains("LL Crankarm - Proseware, Inc.")); Assert.AreEqual(460, lines.Length); } }
public void ProductsAndVendorsToString_Imperative_Test() { using (ProductionDataContext db = new ProductionDataContext()) { List <Product> products = db.GetTable <Product>().ToList(); List <ProductVendor> vendors = db.GetTable <ProductVendor>().ToList(); string output = products.ProductsAndVendorsToString_Imperative(vendors); string firstline = output.Substring(0, output.IndexOf(Environment.NewLine)); Assert.AreEqual("Adjustable Race-Litware, Inc.", firstline); } }
public static void UpdateProduct(int id, Product product) { using (ProductionDataContext productionDataContext = new ProductionDataContext()) { Product original = productionDataContext.GetTable <Product>().Single(p => p.ProductID == product.ProductID); original.Name = product.Name; original.ProductNumber = product.ProductNumber; original.MakeFlag = product.MakeFlag; original.FinishedGoodsFlag = product.FinishedGoodsFlag; original.Color = product.Color; original.SafetyStockLevel = product.SafetyStockLevel; original.ReorderPoint = product.ReorderPoint; original.StandardCost = product.StandardCost; original.ListPrice = product.ListPrice; original.Size = product.Size; original.SizeUnitMeasureCode = product.SizeUnitMeasureCode; original.WeightUnitMeasureCode = product.WeightUnitMeasureCode; original.Weight = product.Weight; original.DaysToManufacture = product.DaysToManufacture; original.ProductLine = product.ProductLine; original.Class = product.Class; original.Style = product.Style; original.ProductSubcategoryID = product.ProductSubcategoryID; original.ProductModelID = product.ProductModelID; original.SellStartDate = product.SellStartDate; original.SellEndDate = product.SellEndDate; original.DiscontinuedDate = product.DiscontinuedDate; original.ModifiedDate = DateTime.Today; productionDataContext.SubmitChanges(); } }
public void GetProductsWithoutCategoryQueryTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <Product> answer = products.GetProductsWithoutCategoryQuery(); Assert.AreEqual(answer[0].ProductSubcategory, null); } }
private List <MyProduct> insertProductsFromBase() { ProductionDataContext db = new ProductionDataContext(); Table <Product> products = db.GetTable <Product>(); List <Product> result = (from product in products select product).ToList(); return((from product in result select new MyProduct(product)).ToList()); }
public static List <Product> GetAllProducts() { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); List <Product> result = (from product in products select product).ToList(); return(result); } }
public static List <Product> GetNRecentlyReviewedProducts(int howManyProducts) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <ProductReview> reviews = dataContext.GetTable <ProductReview>(); List <Product> result = (from review in reviews orderby review.ReviewDate descending select review.Product).Take(howManyProducts).ToList(); return(result); } }
public void pageQueryTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <Product> result = products.GetProductsAsPage(2, 25); Assert.AreEqual <int>(25, result.Count); result = products.GetProductsAsPage(3, 50); Assert.AreEqual <int>(50, result.Count); } }
public static List <Product> GetNProductsFromCategory(string categoryName, int n) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); List <Product> result = (from product in products where product.ProductSubcategory.ProductCategory.Name.Equals(categoryName) select product).Take(n).ToList(); return(result); } }
public static List <Product> GetProductsWithNRecentReviews(int howManyReviews) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); List <Product> result = (from product in products where product.ProductReview.Count == howManyReviews select product).ToList(); return(result); } }
public static List <Product> GetProductsByName(string namePart) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); List <Product> result = (from product in products where product.Name.Contains(namePart) select product).ToList(); return(result); } }
public void SplitToPages_Imperative_Test() { using (ProductionDataContext db = new ProductionDataContext()) { List <Product> products = db.GetTable <Product>().ToList(); List <Product> productPages = products.SplitToPages_Imperative(5, 3); Assert.AreEqual(5, productPages.Count); Assert.AreEqual(products[10].ProductID, productPages[0].ProductID); } }
public static string GetProductVendorByProductName(string productName) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <ProductVendor> vendors = dataContext.GetTable <ProductVendor>(); string result = (from product in vendors where product.Product.Name == productName select product.Vendor.Name).First(); return(result); } }
public void GetProductsWithoutCategory() { using (ProductionDataContext productionDataContext = new ProductionDataContext()) { List <Product> products = productionDataContext.GetTable <Product>().ToList(); List <Product> ImperativeResult = products.ImperativeGetProductsWithoutCategory(); List <Product> DeclarativeResult = products.DeclarativeGetProductsWithoutCategory(); Assert.AreEqual(ImperativeResult.Count, DeclarativeResult.Count); Assert.AreEqual(ImperativeResult.Count, 209); } }
public static decimal GetTotalStandardCostByCategory(ProductCategory category) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); decimal totalCost = (from product in products where product.ProductSubcategory.ProductCategory.Name.Equals(category.Name) select product.StandardCost).ToList().Sum(); return(totalCost); } }
public static Product GetProduct(int productId) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <Product> products = dataContext.GetTable <Product>(); Product result = (from product in products where product.ProductID == productId select product).Single(); return(result); } }
public static List <string> GetProductNamesByVendorName(string vendorName) { using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <ProductVendor> vendors = dataContext.GetTable <ProductVendor>(); List <string> result = (from product in vendors where product.Vendor.Name == vendorName select product.Product.Name).ToList(); return(result); } }
public void GetProductsPagination() { using (ProductionDataContext productionDataContext = new ProductionDataContext()) { List <Product> products = productionDataContext.GetTable <Product>().ToList(); List <Product> ImperativeResult = products.ImperativeGetProductsPagination(2, 5); List <Product> DeclarativeResult = products.DeclarativeGetProductsPagination(2, 5); Assert.AreEqual(ImperativeResult.Count, DeclarativeResult.Count); Assert.AreEqual(ImperativeResult.Count, 5); Assert.IsTrue(products.Contains(DeclarativeResult[0])); } }
public void GetProductsWithNoCategoryTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <Product> resultsD = products.GetProductsWithoutCategoryDeclarative(); List <Product> resultsI = products.GetProductsWithoutCategoryImperative(); Assert.AreSame(resultsD.First(), resultsI.First()); Assert.AreEqual(resultsD.First().ProductNumber, resultsI.First().ProductNumber); Assert.AreEqual(resultsD.First().ProductNumber, "AR-5381"); } }
public void GetProductsWithoutCategory_Imperative_Test() { using (ProductionDataContext db = new ProductionDataContext()) { List <Product> products = db.GetTable <Product>().ToList(); List <Product> productListWithoutCategory = products.GetProductsWithoutCategory_Imperative(); foreach (Product product in productListWithoutCategory) { Assert.IsNull(product.ProductSubcategory); } } }
public void GetProductVendorPairDeclarativeTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); string result = products.GetProductVendorPairDeclarative(); string pair = result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[10]; Assert.AreEqual(pair, "Chainring Bolts - Training Systems"); Assert.IsTrue(result.Contains("Hex Nut 16 - Mountain Works")); Assert.IsTrue(result.Contains("Thin-Jam Lock Nut 2 - Australia Bike Retailer")); } }
public static int GetModelIDByName(string name) { if (name == null) { return(0); } using (ProductionDataContext productionDataContext = new ProductionDataContext()) { Table <Product> products = productionDataContext.GetTable <Product>(); return((from product in products where product.ProductModel.Name == name select product.ProductModel.ProductModelID).First()); }; }
public void GetProductsWithNoCategoryImperativeTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <Product> results = products.GetProductsWithoutCategoryImperative(); Assert.AreEqual(results.Count, 209); foreach (Product product in results) { Assert.IsNull(product.ProductSubcategory); } } }
public static string GetModelNameByID(int id) { if (id == 0) { return(""); } using (ProductionDataContext productionDataContext = new ProductionDataContext()) { Table <Product> products = productionDataContext.GetTable <Product>(); return((from product in products where product.ProductModelID == id select product.ProductModel.Name).First()); }; }
public void PaginateImperativeTest() { using (ProductionDataContext dataContext = new ProductionDataContext()) { List <Product> products = dataContext.GetTable <Product>().ToList(); List <Product> results = products.PaginateImperative(5, 5); Assert.AreEqual(results.Count, 5); for (int i = 0; i < 5; i++) { Assert.AreEqual(products[i + 20].Name, results[i].Name); } Assert.ThrowsException <ArgumentOutOfRangeException>(() => results[5]); } }
public static string GetProductVendorPairDeclarative(this IEnumerable <Product> products) { string result = ""; using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <ProductVendor> productVendors = dataContext.GetTable <ProductVendor>(); var answer = (from product in products join productVendor in productVendors on product.ProductID equals productVendor.ProductID where productVendor.ProductID.Equals(product.ProductID) select new { ProductName = product.Name, VendorName = productVendor.Vendor.Name }).ToList(); result = answer.Aggregate(result, (current, p) => current + p.ProductName + " - " + p.VendorName + Environment.NewLine); } return(result); }
public static string GetProductVendorPairImperative(this IEnumerable <Product> products) { string result = ""; using (ProductionDataContext dataContext = new ProductionDataContext()) { Table <ProductVendor> productVendors = dataContext.GetTable <ProductVendor>(); var answer = products.Join(productVendors, product => product.ProductID, productVendor => productVendor.ProductID, (product, productVendor) => new { ProductName = product.Name, VendorName = productVendor.Vendor.Name }).ToList(); result = answer.Aggregate(result, (current, p) => current + p.ProductName + " - " + p.VendorName + Environment.NewLine); } return(result); }
public MyProductDataContext(ProductionDataContext productionDataContext) { MyProducts = productionDataContext.GetTable <Product>().Select(product => new MyProduct(product)).ToList(); }
public IQueryable <Product> GetItems() { return(production.GetTable <Product>()); }