public void Gallery_Product_ApiEdit() { var urlapi = new UrlApi() { Url = "https://localhost:44397/api/v1/" }; var client = new WebClient(); var option = new Mock <IOptions <UrlApi> >(); option.Setup(c => c.Value).Returns(urlapi); var getapi = new GetProductApi(client, option.Object); var result = client.DownloadString(option.Object.Value.Url + "product/1/1"); var getAllProduct = JsonConvert.DeserializeObject <GetAllProductViewModel>(result); var product = getAllProduct.Products.LastOrDefault(); var find = new FindProductViewModel { Customer = product.Customer, SiteName = product.SiteName, SiteUrl = product.SiteUrl }; product.Customer = "Dorika"; var model = new UpdateProductViewModel { ProductBefore = find, Product = product }; result = getapi.Edit(model); Assert.Equal("Modified", result); }
public ActionResult <IEnumerable <Product> > Get() { var fpvm = new FindProductViewModel { Title = HttpContext.Request.Query["title"], StartPrice = float.Parse(HttpContext.Request.Query["startPrice"].ToString()), EndPrice = float.Parse(HttpContext.Request.Query["endPrice"].ToString()), Category = HttpContext.Request.Query["category"], }; IEnumerable <Product> products = null; if (fpvm.Category != "undefined") { var cat = _dataManager.Categories.GetCategoryByName(fpvm.Category); products = _dataManager.Products.GetProductsByCategory(cat); } products ??= _dataManager.Products.GetProducts(); fpvm.EndPrice = fpvm.EndPrice == 0 ? int.MaxValue : fpvm.EndPrice; products = products.Where(x => x.Price >= fpvm.StartPrice && x.Price <= fpvm.EndPrice && x.Title.Contains(fpvm.Title)); return(Ok(ModifyProduct(products))); }
public void Gallery_Product_Get() { var urlapi = new UrlApi() { Url = "https://localhost:44397/api/v1/" }; var client = new WebClient(); var option = new Mock <IOptions <UrlApi> >(); option.Setup(c => c.Value).Returns(urlapi); var getapi = new GetProductApi(client, option.Object); var result = client.DownloadString(option.Object.Value.Url + "product/1/1"); var getAllProduct = JsonConvert.DeserializeObject <GetAllProductViewModel>(result); var product = getAllProduct.Products.LastOrDefault(); var model = new FindProductViewModel { Customer = product.Customer, SiteName = product.SiteName, SiteUrl = product.SiteUrl }; //var GetJsonResult = JsonConvert.SerializeObject(model); var GetProduct = getapi.Get(model, model.Customer); helper.WriteLine(GetProduct.SiteUrl); }