Esempio n. 1
0
        public void CustomerTest()
        {
            APICustomer customer = new APICustomer
            {
                CustomerID = 1,
                FirstName  = "Tri",
                LastName   = "Nguyen",
                Email      = "*****@*****.**",
                Password   = "******"
            };

            Assert.Equal(1, customer.CustomerID);
            Assert.Equal("Tri", customer.FirstName);
            Assert.Equal("Nguyen", customer.LastName);
            Assert.Equal("*****@*****.**", customer.Email);
            Assert.Equal("tri1234", customer.Password);
        }
        public async Task <string> CreateCustomer(APICustomer Customer)
        {
            var response = this.HttpService.POST <APICustomer>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/customer", Customer, null, new Dictionary <string, string>
            {
                ["Accept"]        = "application/json",
                ["Content-Type"]  = "application/json",
                ["Authorization"] = $"Bearer {this.Config.AccessToken}"
            });

            // Unauthorized (401) - refresh token and try again
            if (!response.Success && response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                await this.RefreshToken();

                response = this.HttpService.POST <APICustomer>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/customer", Customer, null, new Dictionary <string, string>
                {
                    ["Accept"]        = "application/json",
                    ["Content-Type"]  = "application/json",
                    ["Authorization"] = $"Bearer {this.Config.AccessToken}"
                });
            }

            if (!response.Success)
            {
                throw new APIException(this.ParseError(response.Content));
            }

            var modelSchema = new
            {
                Vendor = new
                {
                    Id = string.Empty
                }
            };

            var responseData = JsonConvert.DeserializeAnonymousType(response.Content, modelSchema);

            return(responseData?.Vendor?.Id);
        }