private void CheckRange(int startPage, int endPage, Categories categories, string carrentLincOnCategory) { for (int i = startPage; i < endPage; i++) { string pageNum = string.Format("page={0}/", i); string loadedPage = _pageProvider.GetPage(carrentLincOnCategory + "filter/" + pageNum); string[] AllLinkOnPage = _pageElementParser.GatAllLinksOnGoods(loadedPage); foreach (string item in AllLinkOnPage) { RozetkaGoods goodsDescription = GetRozetkaGoods(item); AllGoods allGoods = _BD.AllGoodsWhereFirstOrDefault(goodsDescription.Id, _shopId);// dBConect.AllGoods.Where(r => r.IdOnSite == goodsDescription.Id && r.ShopId == _shopId).FirstOrDefault(); if (allGoods != null) { CompareResult result = _validator.Validate(allGoods, goodsDescription); if (result == CompareResult.NedUpdate) { _validator.Update(_BD, allGoods, goodsDescription); } } else { string description = _pageProvider.GetPageDescription(item); _photoSave.Save(goodsDescription.Images.Middle, _shopName + goodsDescription.Id); string descr = TryGetDescription(description); _goodsCreator.CreateGoods(_shopName + goodsDescription.Id + ".jpg", _BD, goodsDescription, _shopId, categories.Id, descr); } } } _BD.SaveChanges(); _BD.Dispose(); }
public bool CreateGoods(string imagePath, IDataProvider dBConect, RozetkaGoods realGoods, int shopId, int categoriesId, string description) { AllGoods newGoods = new AllGoods(); newGoods.IdOnSite = realGoods.Id; newGoods.Price = double.Parse((realGoods.Price.Value).Replace(" ", string.Empty)); newGoods.ProductName = realGoods.Title; newGoods.ReferenceToTheOriginal = realGoods.Social_url; newGoods.ShopId = shopId; newGoods.CategoriesId = categoriesId; Currency currency = dBConect.GetCurrency(realGoods.Price.Unit); if (currency == null) { currency = dBConect.AddCurrency(realGoods.Price.Unit); } newGoods.Currency = currency; GoodsDescription goodsDescription = new GoodsDescription(); goodsDescription.AllGoods = newGoods; goodsDescription.Specification = description; newGoods.ImagePath = imagePath; dBConect.AddGoods(newGoods, goodsDescription); dBConect.SaveChanges(); return(true); }
public AllGoods Update(IDataProvider dBConect, AllGoods goods, RozetkaGoods realGoods) { if (goods == null || realGoods == null || dBConect == null) { return(null); } string realPrise = (realGoods.Price.Value).Replace(" ", string.Empty); double prise; if (!double.TryParse(realPrise, out prise)) { return(null); } if (goods.Price != prise) { double oldValue = goods.Price; goods.Price = prise; ChangeDynamics changeDynamics = new ChangeDynamics(); changeDynamics.NewPrice = prise; changeDynamics.OldPrice = oldValue; changeDynamics.UpdateTime = DateTime.Now; changeDynamics.AllGoodsId = goods.Id; dBConect.AddChangeDynamics(changeDynamics); dBConect.SaveChanges(); } return(goods); }
public void CreateGoods_NonExistentCategory_Create() { string imagePath = "1"; Mock <IDataProvider> dbProvider = new Mock <IDataProvider>(); RozetkaGoods realGoods = new RozetkaGoods(); PriceElement priceElement = new PriceElement(); priceElement.Value = "100 0"; priceElement.Unit = "2"; realGoods.Price = priceElement; realGoods.Id = "1"; realGoods.Title = "1"; realGoods.Social_url = "1"; realGoods.Price.Unit = "1"; int shopId = 1; int categoriesId = 1; string description = "sdf"; _goodsCreator = new GoodsCreator(); dbProvider.Setup(r => r.GetCurrency(It.IsAny <string>())).Returns <Currency>(null); dbProvider.Setup(r => r.AddGoods(It.IsAny <AllGoods>(), It.IsAny <GoodsDescription>())); dbProvider.Setup(r => r.AddCurrency(It.IsAny <string>())); dbProvider.Setup(r => r.SaveChanges()); bool result = _goodsCreator.CreateGoods(imagePath, dbProvider.Object, realGoods, shopId, categoriesId, description); Assert.IsTrue(result); dbProvider.Verify(); }
public void GetParsed_NullInner_Null() { string inner = null; RozetkaGoods result = _jParser.GetParsed(inner); Assert.IsNull(result); }
public void Update_NullReferense_Null() { IDataProvider dBConect = null; AllGoods goods = null; RozetkaGoods realGoods = null; AllGoods result = _validator.Update(dBConect, goods, realGoods); Assert.IsNull(result); }
public void GetParsed_NullStringHaveNoJsClass_Null() { string inner = "< !doctype html > < html > < head > </ head > < body > " + " < table class=\"chars-t\"><tr><td class=\"chars-t\"><div class=\"chars-title\">" + "Страна-производитель товара</div> </td></table></body></html>"; RozetkaGoods result = _jParser.GetParsed(inner); Assert.IsNull(result); }
public void Validate_NullReferense_Null() { AllGoods goods = null; RozetkaGoods realGoods = null; CompareResult result = _validator.Validate(goods, realGoods); CompareResult expected = CompareResult.Null; Assert.AreEqual(result, expected); }
public void GetParsed_ValidData_Ok() { string inner = "< !doctype html > < html > < head > </ head > < body > " + " < table class=\"chars-t\"><tr><td class=\"chars-t\"><div class=\"chars-title\">" + "Страна-производитель товара</div>\n" + "RozetkaStickyGoods_class.prototype.options.goods = {\n" + "id: 63291506,\n" + "social_url: 'https://rozetka.com.ua/prestigio_psb141c01bfh_db_cis/p63291506/',\n" + "title: 'Ноутбук Prestigio SmartBook 141C (PSB141C01BFH_DB_CIS) Dark Blue Суперцена!!!',\n" + "images:\n" + "{\n" + "original: 'https://i2.rozetka.ua/goods/9002685/prestigio_psb141c01bfh_db_cis_images_9002685704.jpg',\n" + "middle: 'https://i1.rozetka.ua/goods/9002686/prestigio_psb141c01bfh_db_cis_images_9002686082.jpg'\n" + "},\n" + "status:\n" + "{\n" + "title: 'Товар заканчивается',\n" + "value: 'limited',\n" + "status_value: 'active'\n" + "},\n" + "state: 'new',\n" + "price:\n" + "{\n" + "value: '4 999',\n" + "unit: 'грн'\n" + "}\n" + "};\n" + "\n</td></table></body></html>"; RozetkaGoods result = _jParser.GetParsed(inner); RozetkaGoods expected = new RozetkaGoods(); expected.Id = "63291506"; expected.Images = new ImgVariable() { Middle = "https://i1.rozetka.ua/goods/9002686/prestigio_psb141c01bfh_db_cis_images_9002686082.jpg", Original = "https://i2.rozetka.ua/goods/9002685/prestigio_psb141c01bfh_db_cis_images_9002685704.jpg" }; expected.Price = new PriceElement() { Unit = "грн", Value = "4 999" }; expected.Social_url = "https://rozetka.com.ua/prestigio_psb141c01bfh_db_cis/p63291506/"; expected.Title = "Ноутбук Prestigio SmartBook 141C (PSB141C01BFH_DB_CIS) Dark Blue Суперцена!!!"; Assert.AreEqual(result.Id, expected.Id); Assert.AreEqual(result.Images.Middle, expected.Images.Middle); Assert.AreEqual(result.Images.Original, expected.Images.Original); Assert.AreEqual(result.Price.Unit, expected.Price.Unit); Assert.AreEqual(result.Price.Value, expected.Price.Value); Assert.AreEqual(result.Social_url, expected.Social_url); Assert.AreEqual(result.Title, expected.Title); }
private RozetkaGoods GetRozetkaGoods(string item) { RozetkaGoods goodsDescription = null; string page; for (int j = 0; j < _tryValidatePage; j++) { page = _pageProvider.GetPage(item + "#tab=characteristics"); goodsDescription = _jParser.GetParsed(page); if (goodsDescription != null) { break; } } return(goodsDescription); }
public void Validate_SameValue_Same() { RozetkaGoods realGoods = new RozetkaGoods(); PriceElement priceElement = new PriceElement(); priceElement.Value = "100 0"; realGoods.Price = priceElement; AllGoods dbGoods = new AllGoods(); dbGoods.Price = 1000; CompareResult result = _validator.Validate(dbGoods, realGoods); CompareResult expected = CompareResult.Same; Assert.AreEqual(result, expected); }
public void Validate_DiferentValue_NedUpdate() { RozetkaGoods realGoods = new RozetkaGoods(); PriceElement priceElement = new PriceElement(); priceElement.Value = "100 0"; realGoods.Price = priceElement; AllGoods bdGoods = new AllGoods(); bdGoods.Price = 10; CompareResult result = _validator.Validate(bdGoods, realGoods); CompareResult expected = CompareResult.NedUpdate; Assert.AreEqual(result, expected); }
public CompareResult Validate(AllGoods goods, RozetkaGoods realGoods) { if (goods == null || realGoods == null) { return(CompareResult.Null); } string realPrise = (realGoods.Price.Value).Replace(" ", string.Empty); double prise; if (!double.TryParse(realPrise, out prise)) { return(CompareResult.Null); } if (goods.Price != prise) { return(CompareResult.NedUpdate); } return(CompareResult.Same); }
public void Update_DifferentPrise_CallSave() { AllGoods goods = new AllGoods(); goods.Price = 100; RozetkaGoods realGoods = new RozetkaGoods(); PriceElement priceElement = new PriceElement(); priceElement.Value = "100 0"; realGoods.Price = priceElement; Mock <IDataProvider> dbProvider = new Mock <IDataProvider>(); dbProvider.Setup(r => r.AddChangeDynamics(It.IsAny <ChangeDynamics>())); dbProvider.Setup(r => r.SaveChanges()); AllGoods result = _validator.Update(dbProvider.Object, goods, realGoods); int expected = 1000; Assert.AreEqual(result.Price, expected); dbProvider.VerifyAll(); }