コード例 #1
0
ファイル: EbayServiceTest.cs プロジェクト: RenzoF/ebayAccess
        public void UpdateInventoryAsync_Update2itemsOneOfThemDoesNotExist_ExceptionOccured(UpdateInventoryAlgorithm updateInventoryAlgorithm)
        {
            //------------ Arrange
            var ebayService = new EbayService(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigSandbox());

            //------------ Act
            var updateInventoryRequestExistingItem = new UpdateInventoryRequest {
                ItemId = ExistingProducts.FixedPrice1WithoutVariations.ItemId, Sku = ExistingProducts.FixedPrice1WithoutVariations.Sku, Quantity = 0
            };
            var updateInventoryRequestNotExistingItem = new UpdateInventoryRequest {
                ItemId = 0000, Sku = ExistingProducts.FixedPrice1WithVariation1.Sku + "qwe", Quantity = 0
            };
            var updateProductsAsyncTask1 = ebayService.UpdateInventoryAsync(new List <UpdateInventoryRequest> {
                updateInventoryRequestNotExistingItem, updateInventoryRequestExistingItem,
            }, updateInventoryAlgorithm);

            var    resp = Enumerable.Empty <UpdateInventoryResponse>();
            Action act  = () =>
            {
                updateProductsAsyncTask1.Wait();
                resp = updateProductsAsyncTask1.Result.ToList();
            };

            //------------ Assert
            act.ShouldThrow <Exception>();
        }
コード例 #2
0
 public List <InventoryQuantity> UpdateAvailableToSellInventory(UpdateInventoryRequest request)
 {
     return(new List <InventoryQuantity>
     {
         new InventoryQuantity("1", "1", new Product("12345"), 1, 1)
     });
 }
コード例 #3
0
        public async Task <UpdateInventoryResponse> UpdateItemInventory(UpdateInventoryRequest reqModel)
        {
            var request = CreateRequest <UpdateInventoryRequest>(reqModel);

            request.URI = "contentmgmt/item/international/inventory";

            var response = await client.PostAsync(request);

            var result = await ProcessResponse <UpdateInventoryResponse>(response);

            return(result);
        }
コード例 #4
0
        [Fact]//XML USA
        public async Task UpdateItemInventory_XML_USA()
        {
            UpdateInventoryRequest UpdateItemInventoryRequest = new UpdateInventoryRequest()
            {
                Type          = ItemQueryType.NewEggItemNumber,
                Value         = "9SIA0068KA0333",
                InventoryList = new List <UpdateInventoryRequest.UpdateInventory>()
                {
                    new UpdateInventoryRequest.UpdateInventory()
                    {
                        AvailableQuantity = 100,
                        WarehouseLocation = "USA"
                    }
                }
            };

            CheckRequestString <UpdateInventoryRequest>(UpdateItemInventoryRequest);
            var body = await fadeAPI_USA_XML.UpdateItemInventory(UpdateItemInventoryRequest);

            Assert.IsType <UpdateInventoryResponse>(body);
        }
コード例 #5
0
        // [RequiresAnyRole("")]
        public UpdateInventoryResponse Put(UpdateInventoryRequest request)
        {
            var Validation = new ValidateUpdateInventory();
            var Valid      = Validation.Validate(request);

            if (!Valid.IsValid)
            {
                return(new UpdateInventoryResponse()
                {
                    Message = Valid.Errors.Select(A => A.ErrorMessage).Join("\n"),
                    Success = false
                });
            }
            var User = this.GetCurrentAppUser();
            var ExistingInventory = Db.Single <Inventory>(A => A.Id == request.InventoryId && A.UserId == User.Id);

            if (ExistingInventory == null)
            {
                return(new UpdateInventoryResponse()
                {
                    Success = false,
                    Message = "No Such Inventory"
                });
            }

            var TotalUpdated = Db.UpdateOnly(() => new Inventory()
            {
                StartingAsk = request.StartingAsk, MinSell = request.MinSell, Quantity = request.Quantity
            }, A => A.Id == ExistingInventory.Id);

            return(new UpdateInventoryResponse()
            {
                TotalUpdated = TotalUpdated,
                Success = true,
            });
        }
コード例 #6
0
        /* --- Overridden methods --- */

        UpdateInventoryResult WssServiceClient.UpdateInventory(UpdateInventoryRequest request)
        {
            return(Service(request));
        }
コード例 #7
0
        /* --- Private methods --- */

        /**
         * The method calls the White Source service.
         */
        private R Service <R>(BaseRequest <R> request)
        {
            try
            {
                HttpWebRequest httpRequest = WebRequest.Create(serviceUrl) as HttpWebRequest;
                httpRequest.Method      = "POST";
                httpRequest.ContentType = "application/x-www-form-urlencoded";
                httpRequest.Accept      = "application/json";

                SetProxy(httpRequest);

                // add post data to request
                StringBuilder postString = new StringBuilder();
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_REQUEST_TYPE, System.Web.HttpUtility.UrlEncode(request.Type.ToString()));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_AGENT, System.Web.HttpUtility.UrlEncode(request.Agent));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_AGENT_VERSION, System.Web.HttpUtility.UrlEncode(request.AgentVersion));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_TOKEN, System.Web.HttpUtility.UrlEncode(request.OrgToken));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_PRODUCT, System.Web.HttpUtility.UrlEncode(request.Product));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_PRODUCT_VERSION, System.Web.HttpUtility.UrlEncode(request.ProductVersion));
                postString.Append("&");
                postString.AppendFormat("{0}={1}", APIConstants.PARAM_TIME_STAMP, System.Web.HttpUtility.UrlEncode(request.TimeStamp.ToString()));

                // Serialize projects to JSON
                switch (request.Type)
                {
                case RequestType.UPDATE:
                    UpdateInventoryRequest updateRequest = (UpdateInventoryRequest)Convert.ChangeType(request, typeof(UpdateInventoryRequest));
                    AppendProjects(updateRequest.Projects, postString);
                    break;

                case RequestType.CHECK_POLICIES:
                    CheckPoliciesRequest checkPoliciesRequest = (CheckPoliciesRequest)Convert.ChangeType(request, typeof(CheckPoliciesRequest));
                    AppendProjects(checkPoliciesRequest.Projects, postString);
                    break;

                default:
                    throw new InvalidOperationException("Unsupported request type.");
                }

                ASCIIEncoding ascii     = new ASCIIEncoding();
                byte[]        postBytes = ascii.GetBytes(postString.ToString());
                httpRequest.ContentLength = postBytes.Length;

                Stream postStream = httpRequest.GetRequestStream();
                postStream.Write(postBytes, 0, postBytes.Length);
                postStream.Close();

                using (HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(String.Format("Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription));
                    }

                    using (Stream stream = response.GetResponseStream())
                    {
                        StreamReader reader         = new StreamReader(stream, Encoding.UTF8);
                        String       responseString = reader.ReadToEnd();
                        Debug("response: " + responseString);

                        // convert response JSON to ResultEnvelope
                        ResultEnvelope resultEnvelope;
                        MemoryStream   responseMS = new MemoryStream(Encoding.Unicode.GetBytes(responseString));
                        System.Runtime.Serialization.Json.DataContractJsonSerializer responseSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResultEnvelope));
                        resultEnvelope = responseSerializer.ReadObject(responseMS) as ResultEnvelope;
                        responseMS.Close();

                        String data = resultEnvelope.Data;
                        Debug("Result data is: " + data);

                        // convert data JSON to result according to type
                        R            result;
                        MemoryStream dataMS = new MemoryStream(Encoding.Unicode.GetBytes(data));
                        switch (request.Type)
                        {
                        case RequestType.UPDATE:
                            System.Runtime.Serialization.Json.DataContractJsonSerializer updateSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(UpdateInventoryResult));
                            result = (R)Convert.ChangeType(updateSerializer.ReadObject(dataMS) as UpdateInventoryResult, typeof(R));
                            dataMS.Close();
                            break;

                        case RequestType.CHECK_POLICIES:
                            // enable Dictionary support
                            DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings();
                            settings.UseSimpleDictionaryFormat = true;

                            System.Runtime.Serialization.Json.DataContractJsonSerializer checkPoliciesSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(CheckPoliciesResult), settings);
                            result = (R)Convert.ChangeType(checkPoliciesSerializer.ReadObject(dataMS) as CheckPoliciesResult, typeof(R));
                            dataMS.Close();
                            break;

                        default:
                            dataMS.Close();
                            throw new InvalidOperationException("Unsupported request type.");
                        }
                        dataMS.Close();

                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                Debug(e.Message);
                return(default(R));
            }
        }
コード例 #8
0
        /// <summary>
        /// Update specific fields in a product.
        /// </summary>
        /// <param name="productId">product Id</param>
        /// <param name="request">product to be updated</param>
        /// <returns>The <see cref="Entities.Product"/>.</returns>
        public virtual async Task UpdateAsync(string productId, UpdateInventoryRequest request, int flat)
        {
            var req = PrepareProductRequest($"products/{productId}", flat);

            await ExecutePostAsync <object>(request.ToJsonString(), true, req);
        }