Esempio n. 1
0
        /// <summary>
        /// Send Customer to Url via Post
        /// </summary>
        /// <param name="c"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        static public CustomerReponse sendCustomer(Customer c, string url)
        {
            string data = Helper.HelperJson.SerializeCustomer(c);

            var response = sendPost(data, url);

            return DeSerializeCustomerResponse(response.Result);
        }
Esempio n. 2
0
        public void TestMethodSendCustomer()
        {
            var customer = new Customer()
            {
                property = "Olof Szymczak",
                action = "order created",
                customer = "Christene Cruz",
                value = 100,
                file = "test.csv"
            };

            var customerResponse = EvilInc.Helper.HelperJson.sendCustomer(customer, Constants.URL + Constants.RESOURCE_UPLOAD);
            Assert.AreEqual("", customerResponse);
        }
        public void TestMethodSerializeCustomer()
        {
            var customer = new Customer()
            {
                property = "testp",
                action = "add",
                customer = "customer1",
                value = 100,
                file = "test.csv"
            };

            var result = EvilInc.Helper.HelperJson.SerializeCustomer(customer);

            string expected = "{\"action\":\"add\",\"customer\":\"customer1\",\"file\":\"test.csv\",\"property\":\"testp\",\"value\":100}";
            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
        /// <summary>
        /// Serialize Customer to JSON string
        /// </summary>
        /// <param name="c"></param>
        /// <returns>Returns JSON representation of customer</returns>
        static public string SerializeCustomer(Customer c)
        {
            string result = "";
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Customer));
            using (MemoryStream ms = new MemoryStream())
            {
                js.WriteObject(ms, c);

                ms.Position = 0;
                using (StreamReader sr = new StreamReader(ms))
                {
                    result = sr.ReadToEnd();
                }
            }
            return result;
        }
Esempio n. 5
0
        private Customer buildCustomer(string[] values, string fileName)
        {
            var customer = new Customer();

            if (String.IsNullOrEmpty(values[0]))
            {
                customer.Added = false;
                customer.Errors = Constants.NO_CUSTOMER;
            }

            customer.property = Constants.PROPERTY;

            customer.customer = values[0];
            customer.action = Constants.ACTION;

            int value = 0;

            if (values.Length == 2)
            {
                customer.Actualvalue = values[1];

                if (int.TryParse(values[1], out value))
                {
                    customer.value = value;
                }
                else
                {
                    customer.Added = false;

                    if (!String.IsNullOrEmpty(customer.Errors))
                    {
                        customer.Errors += " " + Constants.INVALID_VALUE;
                    }
                    else
                    {
                        customer.Errors = Constants.INVALID_VALUE;
                    }
                }

            }

            customer.file = fileName;

            return customer;
        }
Esempio n. 6
0
        private void loadCustomer(Customer c)
        {
            var customerResponse = HelperJson.sendCustomer(c, Constants.URL + Constants.RESOURCE_UPLOAD);

            if(customerResponse.added.ToLower() == "true")
            {
                c.Added = true;

                if (customerResponse.hash.Length != 32)
                {
                    c.Hash = customerResponse.hash.Substring(0,100) + "...";
                    c.Errors = "Invalid hash has been returned by the API";
                }
                else
                {
                    c.Hash = customerResponse.hash;
                    c.Errors = "";
                }
            }
            else
            {
                c.Added = false;
                if (customerResponse.errors != null && customerResponse.errors.Length > 0)
                {
                    c.Errors = String.Join(", ", customerResponse.errors);
                }
            }
        }
Esempio n. 7
0
        private void checkCustomerExists(Customer c)
        {
            var customerGet = HelperJson.GetCustomer(c.Hash, Constants.URL + Constants.RESOURCE_CHECK);

            if (customerGet.errors != null && customerGet.errors.Length > 0)
            {
                c.Errors = String.Join(", ", customerGet.errors);
                c.CustomerExists = false;
            }
            else
            {
                c.CustomerExists = true;
            }
        }