Exemple #1
0
        public void GetActiveProductsAsync_ServiceWithExistingProductsCancellationTokenCancelled_ReturnPartOfProductsOrEmptyCollectionImmidiatelly()
        {
            //------------ Arrange
            var ebayService = new EbayService(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigProduction());

            var sw1 = Stopwatch.StartNew();
            var inventoryStatTask1 = ebayService.GetActiveProductsAsync(CancellationToken.None);

            inventoryStatTask1.Wait();
            var products1 = inventoryStatTask1.Result;

            sw1.Stop();

            var cts = new CancellationTokenSource(( int )(sw1.ElapsedMilliseconds * 0.5));
            var ct  = cts.Token;

            //------------ Act
            var sw2 = Stopwatch.StartNew();
            var inventoryStat1Task = ebayService.GetActiveProductsAsync(ct);

            inventoryStat1Task.Wait();
            var products2 = inventoryStat1Task.Result;

            sw2.Stop();

            //------------ Assert
            var products2List = products2 as IList <Item> ?? products2.ToList();
            var products1List = products1 as IList <Item> ?? products1.ToList();

            products2List.Count().Should().BeLessThan(products1List.Count(), "because on site there are items");
            products2List.Count().Should().BeGreaterThan(0, "because on site there are items");
            sw2.ElapsedMilliseconds.Should().BeLessThan(sw1.ElapsedMilliseconds, "because on site there are items");
            Debug.WriteLine("products1 {0}, t:{1}", products1List.Count(), sw1.Elapsed.ToString());
            Debug.WriteLine("products2 {0}, t:{1}", products2List.Count(), sw2.Elapsed.ToString());
        }
        public void ReviseInventoriesStatusAsync_EbayServiceWithNonVariationFixedPriceItems_QuantityUpdatedForAll()
        {
            //A
            var ebayServiceLowLevel = new EbayServiceLowLevel(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigSandbox());

            var ebayService = new EbayService(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigSandbox());

            var temp1 = ebayService.GetActiveProductsAsync(CancellationToken.None, true);

            temp1.Wait();
            var activeProducts = temp1.Result.Where(x => !x.IsItemWithVariations()).ToList();
            var activeProductWithoutVariations1 = activeProducts.Skip(0).First();
            var activeProductWithoutVariations2 = activeProducts.Skip(1).First();

            //A
            var updateProductsAsyncTask1 = ebayServiceLowLevel.ReviseInventoriesStatusAsync(new List <InventoryStatusRequest>
            {
                new InventoryStatusRequest {
                    ItemId = activeProductWithoutVariations1.ItemId.ToLongOrDefault(), Quantity = activeProductWithoutVariations1.Quantity + this.QtyUpdateFor
                },
                new InventoryStatusRequest {
                    ItemId = activeProductWithoutVariations2.ItemId.ToLongOrDefault(), Quantity = activeProductWithoutVariations2.Quantity + this.QtyUpdateFor
                },
            }, new Guid().ToString());

            updateProductsAsyncTask1.Wait();

            var updateProductsAsyncTask2 = ebayServiceLowLevel.ReviseInventoriesStatusAsync(new List <InventoryStatusRequest>
            {
                new InventoryStatusRequest {
                    ItemId = activeProductWithoutVariations1.ItemId.ToLongOrDefault(), Quantity = activeProductWithoutVariations1.Quantity
                },
                new InventoryStatusRequest {
                    ItemId = activeProductWithoutVariations2.ItemId.ToLongOrDefault(), Quantity = activeProductWithoutVariations2.Quantity
                },
            }, new Guid().ToString());

            updateProductsAsyncTask2.Wait();

            //A
            updateProductsAsyncTask1.Result.ToList().TrueForAll(x => x.Items.Count == 2).Should().Be(true);
            updateProductsAsyncTask2.Result.ToList().TrueForAll(x => x.Items.Count == 2).Should().Be(true);

            var item1Update1 = updateProductsAsyncTask1.Result.ToList().First().Items.Where(x => x.ItemId == activeProductWithoutVariations1.ItemId.ToLongOrDefault(false)).First();
            var item1Update2 = updateProductsAsyncTask2.Result.ToList().First().Items.Where(x => x.ItemId == activeProductWithoutVariations1.ItemId.ToLongOrDefault(false)).First();
            var item2Update1 = updateProductsAsyncTask1.Result.ToList().First().Items.Where(x => x.ItemId == activeProductWithoutVariations2.ItemId.ToLongOrDefault(false)).First();
            var item2Update2 = updateProductsAsyncTask2.Result.ToList().First().Items.Where(x => x.ItemId == activeProductWithoutVariations2.ItemId.ToLongOrDefault(false)).First();

            (item1Update1.Quantity - item1Update2.Quantity).Should().Be(this.QtyUpdateFor);
            (item2Update1.Quantity - item2Update2.Quantity).Should().Be(this.QtyUpdateFor);
        }
Exemple #3
0
        public void GetActiveProductsAsync_ServiceWithExistingProducts_HookupProducts()
        {
            //------------ Arrange
            var ebayService = new EbayService(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigSandbox());

            //------------ Act
            var inventoryStat1Task = ebayService.GetActiveProductsAsync(CancellationToken.None);

            inventoryStat1Task.Wait();
            var products = inventoryStat1Task.Result;

            //------------ Assert
            products.Count().Should().BeGreaterThan(0, "because on site there are items");
        }
Exemple #4
0
        public void UpdateInventoryAsync_UpdateFixedPriceItemWithVariationsAndNonvariation_NoExceptionOccuredAndResponseNotEmpty(UpdateInventoryAlgorithm algorithm)
        {
            //------------ Arrange
            var ebayService = new EbayService(this._credentials.GetEbayUserCredentials(), this._credentials.GetEbayConfigSandbox());

            var temp1 = ebayService.GetActiveProductsAsync(CancellationToken.None, true);

            temp1.Wait();
            var activeProducts = temp1.Result.ToList();

            var activeProductWithVariations1    = activeProducts.First(x => x.IsItemWithVariations());
            var activeProductWithoutVariations1 = activeProducts.First(x => !x.IsItemWithVariations());

            //------------ Act
            //1
            var updayeInventoryTask1 = ebayService.UpdateInventoryAsync(new List <UpdateInventoryRequest>
            {
                new UpdateInventoryRequest {
                    ItemId = activeProductWithVariations1.ItemId.ToLongOrDefault(false), Sku = activeProductWithVariations1.GetSku().Sku, Quantity = 100500, ConditionID = activeProductWithVariations1.ConditionId, IsVariation = activeProductWithVariations1.IsItemWithVariations()
                },
                new UpdateInventoryRequest {
                    ItemId = activeProductWithoutVariations1.ItemId.ToLongOrDefault(false), Sku = activeProductWithoutVariations1.GetSku().Sku, Quantity = 100500, ConditionID = activeProductWithoutVariations1.ConditionId, IsVariation = activeProductWithoutVariations1.IsItemWithVariations()
                },
            }, algorithm);

            updayeInventoryTask1.Wait();
            var updateInventoryResponse1 = updayeInventoryTask1.Result.ToList();

            //2
            var temp2 = ebayService.GetActiveProductsAsync(CancellationToken.None, true);

            temp2.Wait();
            activeProducts = temp2.Result.ToList();
            var activeProductWithVariations2    = activeProducts.First(x => x.ItemId == activeProductWithVariations1.ItemId && x.GetSku().Sku == activeProductWithVariations1.GetSku().Sku);
            var activeProductWithoutVariations2 = activeProducts.First(x => x.ItemId == activeProductWithoutVariations1.ItemId && x.GetSku().Sku == activeProductWithoutVariations1.GetSku().Sku);

            var updateInventoryTask2 = ebayService.UpdateInventoryAsync(new List <UpdateInventoryRequest>
            {
                new UpdateInventoryRequest {
                    ItemId = activeProductWithVariations2.ItemId.ToLongOrDefault(false), Sku = activeProductWithVariations2.GetSku().Sku, Quantity = 0, ConditionID = activeProductWithVariations2.ConditionId, IsVariation = activeProductWithVariations2.IsItemWithVariations()
                },
                new UpdateInventoryRequest {
                    ItemId = activeProductWithoutVariations2.ItemId.ToLongOrDefault(false), Sku = activeProductWithoutVariations2.GetSku().Sku, Quantity = 0, ConditionID = activeProductWithoutVariations2.ConditionId, IsVariation = activeProductWithoutVariations2.IsItemWithVariations()
                },
            }, algorithm);

            updateInventoryTask2.Wait();
            var updateInventoryResponse2 = updateInventoryTask2.Result.ToList();

            //3
            var temp3 = ebayService.GetActiveProductsAsync(CancellationToken.None, true);

            temp3.Wait();
            activeProducts = temp3.Result.ToList();
            var activeProductWithVariations3    = activeProducts.First(x => x.ItemId == activeProductWithVariations1.ItemId && x.GetSku().Sku == activeProductWithVariations1.GetSku().Sku);
            var activeProductWithoutVariations3 = activeProducts.First(x => x.ItemId == activeProductWithoutVariations1.ItemId && x.GetSku().Sku == activeProductWithoutVariations1.GetSku().Sku);

            //------------ Assert
            activeProductWithVariations3.GetQuantity().Quantity.Should().Be(0);
            activeProductWithoutVariations3.GetQuantity().Quantity.Should().Be(0);

            activeProductWithVariations2.GetQuantity().Quantity.Should().Be(100500);
            activeProductWithoutVariations2.GetQuantity().Quantity.Should().Be(100500);
        }