private void InsertNewResult(ProductsCollection graberResult) { var data = graberResult.Items; foreach (var dataItem in data) { ICollection <Models.ProductPriceHistory> priceHistory = new List <Models.ProductPriceHistory>(); priceHistory.Add(new Models.ProductPriceHistory() { Price = dataItem.Price, UpdateDate = DateTime.Now }); productModel.Add(new Models.Product() { Name = dataItem.Name, Description = dataItem.Description, Price = dataItem.Price, ProductImageURL = dataItem.ProductImageURL, ProductPageUrl = dataItem.ProductPageUrl, PriceHistory = priceHistory }); } db.Products.AddRange(productModel); db.SaveChanges(); }
private void BindingData() { try { ProductsCollection col = null; col = this.LoadProduct(-1); if (col == null) { col = new ProductsCollection(); lblCount.Text = "Có 0" + " record"; rptData.DataSource = col; rptData.DataBind(); } else { lblCount.Text = "Có " + col.Count.ToString() + " record"; lblCount.ForeColor = System.Drawing.Color.Blue; anpPager.RecordCount = col.Count; anpPager.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); anpPager.ShowFirstLast = false; col = this.GetSubData(col, anpPager.StartRecordIndex - 1, anpPager.EndRecordIndex); rptData.DataSource = col; rptData.DataBind(); } } catch (Exception ex) { Global.WriteLogError("BindingData()" + ex); } }
public void FindProductsBySupplierAndPrice_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List <Product>(); decimal price = 5.0m; for (int i = 99; i >= 0; i--) { if (i % 5 == 0) { var product = new Product(i, "magnit", "Bai Tosho", price); expectedProducts.Add(product); products.Add(i, "magnit", "Bai Tosho", price); continue; } products.Add(i, "magnit", "Bai Tosho" + i, i + 20.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products .FindProductsBySupplierAndPrice("Bai Tosho", 5) .ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
public async Task TestGetNonFantasticProductsAsync() { var mockProducts = new List <Product> { new Product { Id = 1, Attribute = new Models.Attribute { Fantastic = new Fantastic { Value = false } } }, new Product { Id = 2, Attribute = new Models.Attribute { Fantastic = new Fantastic { Value = true } } } }; var dataCollection = new Mock <IDataCollection <Product> >(); dataCollection.Setup(p => p.FindAsync(ItIsMockProductFilterDefinition("{ \"attribute.fantastic.value\" : false }"), It.IsAny <CancellationToken>())) .ReturnsAsync(new[] { mockProducts[0] }); var productsCollection = new ProductsCollection(dataCollection.Object); Assert.Collection(await productsCollection.GetNonFantasticProductsAsync(), product => Assert.Equal(1, product.Id)); }
private ProductsCollection LoadProductleast() { Data objdata = new Data(Global.ConnectionSql); ProductsCollection col = null; try { Products obj = new Products(); obj.DataObject = objdata; col = obj.GetListTopleast(); if (col != null) { rptdataleast.DataSource = col; rptdataleast.DataBind(); } } catch (Exception ex) { Global.WriteLogError("LoadProductleast()" + ex); } finally { objdata.DeConnect(); } return(col); }
public void FindByTitleAndPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List<Product>(); decimal price = 1.0m; for (int i = 99; i >= 0; i--) { string title = string.Empty; if (i % 5 == 0 && price <= 15) { title = "magnit"; var product = new Product(i, title, "Bai Tosho" + i, price); expectedProducts.Add(product); products.Add(i, title, "Bai Tosho" + i, price); price++; } else { title = "magnit" + i; products.Add(i, title, "Bai Tosho" + i, 0.5m); } } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products .FindProductsTitleAndPriceRange("magnit", 1.0m, 15.0m) .ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
private void Delete() { Product p = SelectedProduct1.GetProduct1; Task.Run(() => Controller.DeleteProduct(p)); ProductsCollection.Remove(SelectedProduct1); }
public void FindProductsByTittle_AddMultipleProducts_ShouldReturnSameProductsOrderedById() { var products = new ProductsCollection(); var expectedProducts = new List <Product>(); for (int i = 99; i >= 0; i--) { string title = string.Empty; if (i % 5 == 0) { title = "magnit"; var product = new Product(i, title, "Bai Tosho" + i, i + 2.5m); expectedProducts.Add(product); } else { title = "magnit" + i; } products.Add(i, title, "Bai Tosho" + i, i + 2.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products.FindProductsByTitle("magnit").ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
public async Task TestGetProductsByPriceAsync() { var mockProducts = new List <Product> { new Product { Id = 1, Price = 124.2 }, new Product { Id = 2, Price = 262 }, new Product { Id = 3, Price = 328.5 }, new Product { Id = 4, Price = 689 } }; var dataCollection = new Mock <IDataCollection <Product> >(); dataCollection.Setup(p => p.FindAsync(ItIsMockProductFilterDefinition("{ \"price\" : { \"$gte\" : 260.0, \"$lte\" : 328.5 } }"), It.IsAny <CancellationToken>())) .ReturnsAsync(new[] { mockProducts[1], mockProducts[2] }); var productsCollection = new ProductsCollection(dataCollection.Object); Assert.Collection(await productsCollection.GetProductsByPriceAsync(260, 328.5), product => Assert.Equal(2, product.Id), product => Assert.Equal(3, product.Id)); }
public ActionResult RunGraber() { if (graberState == 1) { return(PartialView("GraberWorkingMessage")); } graberState = 1; db = new Models.ProductContext(); graber = new Graber("https://cnc.prom.ua"); productModel = new List <Models.Product>(); graber.Strategy = new PopulateModelStrategy(); graber.RunGrabber(); ProductsCollection result = (ProductsCollection)graber.Result; InsertNewResult(result); ViewBag.Count = productModel.Count; graberState = 0; return(PartialView("RunGraberResult")); }
public void FindByTitleAndPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List <Product>(); decimal price = 1.0m; for (int i = 99; i >= 0; i--) { string title = string.Empty; if (i % 5 == 0 && price <= 15) { title = "magnit"; var product = new Product(i, title, "Bai Tosho" + i, price); expectedProducts.Add(product); products.Add(i, title, "Bai Tosho" + i, price); price++; } else { title = "magnit" + i; products.Add(i, title, "Bai Tosho" + i, 0.5m); } } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products .FindProductsTitleAndPriceRange("magnit", 1.0m, 15.0m) .ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
public void FindProductsByPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List <Product>(); decimal price = 5.0m; for (int i = 99; i >= 0; i--) { if (price <= 15 && i % 5 == 0) { var product = new Product(i, "magnit", "Bai Tosho", price); expectedProducts.Add(product); products.Add(i, "magnit", "Bai Tosho", price); price++; continue; } products.Add(i, "magnit", "Bai Tosho", i + 20.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products.FindProductsByPriceRange(5, 15).ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts, "Returned products are not in the given price range."); }
public ProductsCollection Products_LoadAll() { ProductsCollection coll = new ProductsCollection(); coll.es.IsLazyLoadDisabled = true; coll.LoadAll(); return(coll); }
public void SaveCollectionToFile(ProductsCollection<Product> productsCollection, string path) { XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(productsCollection.GetType()); TextWriter txtW = new StreamWriter(path); serializer.Serialize(txtW, productsCollection); txtW.Close(); }
public void Add_SingleProduct_CountShouldBe1() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); Assert.AreEqual(1, products.Count, "Count is not 1"); }
public void Add_SingleProduct_CountShouldBe1() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); Assert.AreEqual(1, products.Count, "Count is not 1"); }
public void Remove_AddAndRemoveSingleProduct_CountShouldBe0() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); products.Remove(1); Assert.AreEqual(0, products.Count, "Count is not 0"); }
public void Add_TwoProductsWithSameId_ProductShouldBeOverriden() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); products.Add(1, "nov magnit", "Bai Tosho", 3.5m); Assert.AreEqual(1, products.Count, "Count is not 1"); }
public void Add_TwoProductsWithSameId_ProductShouldBeOverriden() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); products.Add(1, "nov magnit", "Bai Tosho", 3.5m); Assert.AreEqual(1, products.Count, "Count is not 1"); }
public void Initialize(ProductsCollection productsCollection) { foreach (var product in productsCollection.ProductsList) { var productPreview = Instantiate(_productPreviewPrefab, _productContainer); productPreview.Initialize(product); productPreview.OnProductSelect += OnProductSelectHandler; } }
private void Add() { Product p = _displayed.GetProduct1; Task.Run(() => Controller.AddProduct(p)); ProductsCollection.Add(_displayed); _displayed = new ProductVM(); SelectedProduct = null; }
private void GetAll() { ProductsCollection.Clear(); List <Product> products = Controller.GetAllProducts(); foreach (var product in products) { ProductsCollection.Add(new ProductVM(product)); } }
public void Add_100Products_CountShouldBe100() { var products = new ProductsCollection(); for (int i = 0; i < 100; i++) { products.Add(i, "magnit" + i, "Bai Tosho" + i, i + 2.5m); } Assert.AreEqual(100, products.Count, "Count is not 100"); }
public ProductsCollection.ProductsCollectionWCFPacket Products_LoadAll() { ProductsCollection coll = new ProductsCollection(); if (coll.LoadAll()) { return(coll); } return(null); }
public ProductsCollection Products_LoadByDynamic(string serializedQuery) { ProductsQuery query = ProductsQuery.SerializeHelper.FromXml( serializedQuery, typeof(ProductsQuery), AllKnownTypes) as ProductsQuery; ProductsCollection coll = new ProductsCollection(); coll.es.IsLazyLoadDisabled = true; coll.Load(query); return(coll); }
public void FindSingleProductByTittle_ShouldReturnCorrectProduct() { var products = new ProductsCollection(); var expected = new Product(1, "magnit", "Bai Tosho", 2.5m); products.Add(1, "magnit", "Bai Tosho", 2.5m); var actualProduct = products.FindProductsByTitle("magnit").First(); Assert.AreEqual(expected, actualProduct, "Returned product is not the same."); }
public void Add_100Products_CountShouldBe100() { var products = new ProductsCollection(); for (int i = 0; i < 100; i++) { products.Add(i, "magnit" + i, "Bai Tosho" + i, i + 2.5m); } Assert.AreEqual(100, products.Count, "Count is not 100"); }
public ProductsCollectionProxyStub Products_LoadAll() { ProductsCollection coll = new ProductsCollection(); if (coll.LoadAll()) { return(coll); } return(null); }
public ProductsCollectionProxyStub Products_SaveCollection(ProductsCollectionProxyStub collection) { if (collection != null) { ProductsCollection c = collection.GetCollection(); c.Save(); return(c); } return(null); }
public void RemoveSelectedItem(Product item) { if (item != null) { ProductsCollection.Remove(item); } else { return; } }
private void EditProduct(object obj) { mIngredientKey = (int)SelectedIngredient.Row["IngredientKey"]; mProductKey = (int)SelectedIngredient.Row["ProductKey"]; ProductName = (string)SelectedIngredient.Row["ProductName"]; IngredientQuantity = (double)SelectedIngredient.Row["Quantity"]; LoadProducts(); SelectedProduct = ProductsCollection.FirstOrDefault(x => x.nKey == mProductKey); SelectedIngMeasure = AvailableMeasuresCollection.FirstOrDefault( x => x.nKey == (int)SelectedIngredient.Row["MeasureKey"]); }
private void button_discountProducts_Click(object sender, RoutedEventArgs e) { //changing price for even 5-th product var collection = new ProductsCollection(productsList, 5); foreach (var element in collection) { //changing price here var product = (Product)element; product.Price = Math.Round(product.Price * 95 / 100, 2); database.UpdateProduct(product); } }
public void FindProductsByTittle_SearchNonExistingTitle_ShouldReturnEmptyCollection() { var products = new ProductsCollection(); for (int i = 0; i < 100; i++) { products.Add(i, "magnit" + i, "Bai Tosho" + i, i + 2.5m); } var actualProducts = products.FindProductsByTitle("magnit").ToList(); Assert.AreEqual(0, actualProducts.Count, "Returned products count is not 0."); }
public MainWindow() { InitializeComponent(); client = new HttpClient() { BaseAddress = new Uri(ConfigurationManager.AppSettings["BaseApiUrl"]), }; client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _products = new ProductsCollection(); this.ProductsList.ItemsSource = _products; }
public ProductsCollectionProxyStub Products_QueryForCollection(string serializedQuery) { ProductsQuery query = ProductsQuery.SerializeHelper.FromXml( serializedQuery, typeof(ProductsQuery), AllKnownTypes) as ProductsQuery; ProductsCollection coll = new ProductsCollection(); if (coll.Load(query)) { return(coll); } return(null); }
private ProductsCollection GetSubData(ProductsCollection Source, int start, int end) { int iTotalRecord = Source.Count; ProductsCollection subSource = new ProductsCollection(); if (Source != null) { for (int i = start; i < end; i++) { subSource.Add(Source[i]); } } return(subSource); }
public void FindSingleProductByTittle_ShouldReturnCorrectProduct() { var products = new ProductsCollection(); var expected = new Product(1, "magnit", "Bai Tosho", 2.5m); products.Add(1, "magnit", "Bai Tosho", 2.5m); var actualProduct = products.FindProductsByTitle("magnit").First(); Assert.AreEqual(expected, actualProduct, "Returned product is not the same."); }
public void FindProductsByTittle_SearchNonExistingTitle_ShouldReturnEmptyCollection() { var products = new ProductsCollection(); for (int i = 0; i < 100; i++) { products.Add(i, "magnit" + i, "Bai Tosho" + i, i + 2.5m); } var actualProducts = products.FindProductsByTitle("magnit").ToList(); Assert.AreEqual(0, actualProducts.Count, "Returned products count is not 0."); }
public void FindProductsByTittle_AddMultipleProducts_ShouldReturnSameProductsOrderedById() { var products = new ProductsCollection(); var expectedProducts = new List<Product>(); for (int i = 99; i >= 0; i--) { string title = string.Empty; if (i % 5 == 0) { title = "magnit"; var product = new Product(i, title, "Bai Tosho" + i, i + 2.5m); expectedProducts.Add(product); } else { title = "magnit" + i; } products.Add(i, title, "Bai Tosho" + i, i + 2.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products.FindProductsByTitle("magnit").ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
public void FindProductsBySupplierAndPrice_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List<Product>(); decimal price = 5.0m; for (int i = 99; i >= 0; i--) { if (i % 5 == 0) { var product = new Product(i, "magnit", "Bai Tosho", price); expectedProducts.Add(product); products.Add(i, "magnit", "Bai Tosho", price); continue; } products.Add(i, "magnit", "Bai Tosho" + i, i + 20.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products .FindProductsBySupplierAndPrice("Bai Tosho", 5) .ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts); }
public void FindProductsByPriceRange_AddMultipleProducts_ShouldReturnCorrectOnes() { var products = new ProductsCollection(); var expectedProducts = new List<Product>(); decimal price = 5.0m; for (int i = 99; i >= 0; i--) { if (price <= 15 && i % 5 == 0) { var product = new Product(i, "magnit", "Bai Tosho", price); expectedProducts.Add(product); products.Add(i, "magnit", "Bai Tosho", price); price++; continue; } products.Add(i, "magnit", "Bai Tosho", i + 20.5m); } expectedProducts = expectedProducts.OrderBy(p => p.Id).ToList(); var actualProducts = products.FindProductsByPriceRange(5, 15).ToList(); CollectionAssert.AreEqual(expectedProducts, actualProducts, "Returned products are not in the given price range."); }
public void Remove_AddAndRemoveSingleProduct_CountShouldBe0() { var products = new ProductsCollection(); products.Add(1, "magnit", "Bai Tosho", 2.5m); products.Remove(1); Assert.AreEqual(0, products.Count, "Count is not 0"); }