Exemplo n.º 1
0
        public void PutWithResponseWithExpectedStatus()
        {
            ProductJson p = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };
            var req = WebServiceUtils.MakeStringContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var res = this.WebServiceDriver.PutWithResponse("/api/XML_JSON/Put/1", "application/json", req, HttpStatusCode.OK);

            Assert.IsNotNull(res);
        }
Exemplo n.º 2
0
        public void PostWithJson()
        {
            ProductJson p = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };
            var content = WebServiceUtils.MakeStreamContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = this.WebServiceDriver.Post <ProductJson>("/api/XML_JSON/Post", "application/json", content, true);

            Assert.IsTrue(result == null);
        }
Exemplo n.º 3
0
        public void PostMoreParamsWithResponseWithExpectedStatus()
        {
            ProductJson p = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };

            var res = this.WebServiceDriver.PostWithResponse("/api/XML_JSON/Post", "application/json", JsonConvert.SerializeObject(p), Encoding.UTF8, "application/json", HttpStatusCode.OK, true);

            Assert.IsNotNull(res);
        }
Exemplo n.º 4
0
        public void Save(ProductJson json)
        {
            if (!authorization.IsAuthorized())
            {
                throw new WebFaultException(HttpStatusCode.Unauthorized);
            }
            // TODO: walidacja

            Product product = json.ToProduct();

            product.OwnerLogin = userRepository.Find(authorization.UserId).Login;

            productRepository.Save(product);
        }
Exemplo n.º 5
0
        public void PatchJSONWithoutBaseTest()
        {
            WebServiceDriver client = new WebServiceDriver(new Uri(url));
            ProductJson      p      = new ProductJson();

            p.Category = "ff";
            p.Id       = 4;
            p.Name     = "ff";
            p.Price    = 3.25f;
            var content = WebServiceUtils.MakeStringContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = client.PatchWithResponse("/api/XML_JSON/Patch/1", "application/json", content, true);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemplo n.º 6
0
        public void PutJSONWithType()
        {
            ProductJson p = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };
            var content = WebServiceUtils.MakeStringContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = this.WebServiceDriver.Put <ProductJson>("/api/XML_JSON/Put/1", "application/json", content, true);

            Assert.AreEqual(null, result);
        }
Exemplo n.º 7
0
        public void PutJSONStreamSerializedVerifyStatusCode()
        {
            ProductJson p = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };
            var content = WebServiceUtils.MakeStreamContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = this.WebServiceDriver.PutWithResponse("/api/XML_JSON/Put/1", "application/json", content, true);

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemplo n.º 8
0
        public Product ConvertProductJsonToProduct(ProductJson productJson)
        {
            var product = new Product()
            {
                Id              = productJson.id,
                Name            = productJson.name,
                Description     = productJson.description,
                CategoryId      = productJson.categoryId,
                Price           = productJson.price,
                PublicationDate = DateTime.Now,
                StockQuantity   = 1
            };

            return(product);
        }
Exemplo n.º 9
0
        public void PatchJSONWithType()
        {
            ProductJson p = new ProductJson();

            p.Category = "ff";
            p.Id       = 4;
            p.Name     = "ff";
            p.Price    = 3.25f;
            var content = WebServiceUtils.MakeStringContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = this.WebServiceDriver.Patch <ProductJson>("/api/XML_JSON/Patch/1", "application/json", content, true);

            Assert.AreEqual(p.Category, result.Category);
            Assert.AreEqual(p.Id, result.Id);
            Assert.AreEqual(p.Name, result.Name);
            Assert.AreEqual(p.Price, result.Price);
        }
Exemplo n.º 10
0
        public ProductJson ConvertProductToProductJson(Product product)
        {
            var productCategory = db.Categories.Where(c => c.Id == product.CategoryId).FirstOrDefault();
            var productJson     = new ProductJson()
            {
                id              = product.Id,
                name            = product.Name,
                description     = product.Description,
                categoryId      = product.CategoryId,
                price           = product.Price,
                publicationDate = product.PublicationDate,
                category        = productCategory.Name
            };

            return(productJson);
        }
Exemplo n.º 11
0
        public void NewtonsoftJsonSerializationBenchmark()
        {
            ProductJson product = new ProductJson()
            {
                Id           = 1,
                Description  = "The next generation of widgets are here, order one today!",
                Manufacturer = "ACME Corp",
                Name         = "Widget 2.0",
                Price        = 5.00f
            };

            var serializedProdct = JsonConvert.SerializeObject(product);

            Bin bin = new Bin(Bin, serializedProdct);
            Key key = new Key(Namespace, Set, NewtonsoftBenchmarkKey);

            _client.Put(null, key, bin);
        }
Exemplo n.º 12
0
        public void PatchJSONWithTypeWithoutBaseTest()
        {
            WebServiceDriver client = new WebServiceDriver(new Uri(url));
            ProductJson      p      = new ProductJson
            {
                Category = "ff",
                Id       = 4,
                Name     = "ff",
                Price    = 3.25f
            };

            var content = WebServiceUtils.MakeStringContent <ProductJson>(p, Encoding.UTF8, "application/json");
            var result  = client.Patch <ProductJson>("/api/XML_JSON/Patch/1", "application/json", content, true);

            Assert.AreEqual(p.Category, result.Category);
            Assert.AreEqual(p.Id, result.Id);
            Assert.AreEqual(p.Name, result.Name);
            Assert.AreEqual(p.Price, result.Price);
        }
Exemplo n.º 13
0
 // POST: api/Product
 public void Post(ProductJson productJson)
 {
     productLogic.PostProduct(productJson);
 }
Exemplo n.º 14
0
        public static List <Product> GetProductsList()
        {
            ProductJson cs = JsonConvert.DeserializeObject <ProductJson>(ProductsJSON);

            return(cs.Products);
        }
Exemplo n.º 15
0
        public void GetJsonDeserialized()
        {
            ProductJson result = this.WebServiceDriver.Get <ProductJson>("/api/XML_JSON/GetProduct/1", "application/json", false);

            Assert.AreEqual(1, result.Id, "Expected to get product 1");
        }
Exemplo n.º 16
0
 public ProductJson SubscribeProductGetDate([EventMessage] ProductJson product)
 {
     return(product);
 }
Exemplo n.º 17
0
        private void Seed()
        {
            using var context = new ApplicationDb(ContextOptions);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var company1 = new CompanyData {
                Name = "One"
            };

            var productJson1 = new ProductJson {
                Title = "One"
            };
            var productJson2 = new ProductJson {
                Title = "Two"
            };
            var productJson3 = new ProductJson {
                Title = "Three"
            };

            var product1 = new ProductData
            {
                Title        = "One", JsonData = JsonConvert.SerializeObject(productJson1), Url = "Url1", ExternalId = "1",
                ProductState = ProductState.Success
            };
            var product2 = new ProductData
            {
                Title = "Two", JsonData = JsonConvert.SerializeObject(productJson2), Url = "Url2", ExternalId = "2"
            };
            var product3 = new ProductData
            {
                Title = "Three", JsonData = JsonConvert.SerializeObject(productJson3), Url = "Url3", ExternalId = "3"
            };

            var category1 = new CategoryData {
                Name = "One"
            };
            var category2 = new CategoryData {
                Name = "Two", SupCategoryData = category1
            };
            var category3 = new CategoryData {
                Name = "Three", SupCategoryData = category2
            };

            product1.Categories = new List <CategoryData> {
                category1, category2, category3
            };
            product2.Categories = new List <CategoryData> {
                category1, category2
            };
            product3.Categories = new List <CategoryData> {
                category1
            };

            company1.Products = new List <ProductData> {
                product1, product2, product3
            };

            context.Add(company1);

            context.SaveChanges();
        }
Exemplo n.º 18
0
        public async void EditProduct()
        {
            Value = true;
            var connection = await apiService.CheckConnection();
            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Warning,
                    Languages.CheckConnection,
                    Languages.Ok);
                return;
            }
            if (string.IsNullOrEmpty(Product.code) || string.IsNullOrEmpty(Product.description))
            {
                Value = true;
                return;
            }
            if (Product.supplier == null || Product.customsDuty == null || Product.measureUnit == null)
            {
                Value = true;
                return;
            }
            if(SelectedStatus == null)
            {
                await Application.Current.MainPage.DisplayAlert("Warning", "Select Availability", "ok");
                return;
            }
            var purchaseCost = new PurchaseCost
            {
                id = Product.purchaseCost.id,
                currency = Product.purchaseCost.currency,
                value = Product.purchaseCost.value
            };
            var currencyStatic = new Currency
            {
                id = 2,
                entity = "ÅLAND ISLANDS",
                currency = "Euro",
                alphabeticCode = "EUR",
                numericCode = "978",
                minorUnit = "2",
                withdrawalDate = null,
                remark = null
            };
            var packagingCost = new PackagingCost
            {
                id = Product.packagingCost.id,
                currency = currencyStatic,
                value = Product.packagingCost.value
            };

            var product = new Product
            {
                id = Product.id,
                code = Product.code,
                availability = SelectedStatus.Key,
                description = Product.description,
                purchaseCost = purchaseCost,
                packagingCost = packagingCost,
                updateCostDate = Product.updateCostDate,
                costChange = Product.costChange,
                quantityPerPackage = 1,
                active = Product.active,
                fob = Product.fob,
                supplier = Product.supplier,
                packagingMethod = Product.packagingMethod,
                measureUnit = Product.measureUnit,
                composed = Product.composed,
                component = Product.component,
                importVolume = Product.importVolume,
                importQuantity = Product.importQuantity,
                customsDuty = Product.customsDuty,
                note = Product.note,
                width = Product.width,
                height = Product.height,
                length = Product.length,
                cartonVolume = 1,
                useCarton = Product.useCarton
            };

            var eubasiccost = new PackagingCost
            {
                currency = currencyStatic,
                value = Product.purchaseCost.value
            };
            var euddpcost = new PackagingCost
            {
                currency = currencyStatic,
                value = Product.purchaseCost.value
            };
            var productJson = new ProductJson
            {
                // prices = [],
                product = product,
                username = "******",
                eubasicpcost = eubasiccost,
                euddpcost = euddpcost,
                //piecesPerContainer = 30
            };
            var response = await apiService.PutProduct<Product>(
                 "https://app.smart-path.it",
                 "/md-core",
                 "/medial/product",
                  productJson);            
           /* if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "ok");
                return;
            }*/
            Value = false;
            //ProductsViewModel.GetInstance().Update(productJson);
            MessagingCenter.Send((App)Application.Current, "OnSaved");
            DependencyService.Get<INotification>().CreateNotification("Medial", "Product Updated");
            await Navigation.PopAsync();
        }