public void ReceiveOrders(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            // var firstCreatedItem = this._orders[ credentials.AuthenticatedUserCredentials.SoapApiKey ].OrderBy( x => x.UpdatedAt ).First();
            // var lastCreatedItem = this._orders[ credentials.AuthenticatedUserCredentials.SoapApiKey ].OrderBy( x => x.UpdatedAt ).Last();

            // var modifiedFrom = new DateTime( ( firstCreatedItem.UpdatedAt ).Ticks, DateTimeKind.Utc ).AddSeconds( 1 );
            // var modifiedTo = new DateTime( ( lastCreatedItem.UpdatedAt ).Ticks, DateTimeKind.Utc ).AddSeconds( -1 );
            var modifiedFrom  = new DateTime(2018, 1, 28, 23, 23, 59).AddSeconds(1);
            var modifiedTo    = new DateTime(2018, 2, 2, 23, 30, 39).AddSeconds(-1);
            var getOrdersTask = magentoService.GetOrdersAsync(modifiedFrom, modifiedTo, new Mark("TEST-GET-ORDERS"));

            getOrdersTask.Wait();

            // ------------ Assert
            // var thatMustBeReturned = this._orders[ credentials.AuthenticatedUserCredentials.SoapApiKey ].Where( x => x != firstCreatedItem && x != lastCreatedItem ).Select( x => x.OrderIncrementalId ).ToList();
            // var thatWasReturned = getOrdersTask.Result.Where( x => x != firstCreatedItem && x != lastCreatedItem ).Select( x => x.OrderIncrementalId ).ToList();
            var thatWasReturned = getOrdersTask.Result.Select(x => x.OrderIncrementalId).ToList();

            // thatWasReturned.Should().BeEquivalentTo( thatMustBeReturned );
            thatWasReturned.Should().NotBeNullOrEmpty();
            getOrdersTask.Result.All(x => x.Items.All(y => !string.IsNullOrWhiteSpace(y.Sku))).Should().BeTrue();
        }
Пример #2
0
        public void UpdateInventoryAsync_UserAlreadyHasAccessTokens_ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            //------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            //------------ Act
            var onlyProductsCreatedForThisTests = this.GetOnlyProductsCreatedForThisTests(magentoService);
            var updateFirstTimeQty  = 123;
            var updateInventoryTask = magentoService.UpdateInventoryAsync(onlyProductsCreatedForThisTests.ToInventory(x => updateFirstTimeQty).ToList());

            updateInventoryTask.Wait();

            /////
            var onlyProductsCreatedForThisTests2 = this.GetOnlyProductsCreatedForThisTests(magentoService);

            var updateSecondTimeQty  = 100500;
            var updateInventoryTask2 = magentoService.UpdateInventoryAsync(onlyProductsCreatedForThisTests2.ToInventory(x => updateSecondTimeQty).ToList());

            updateInventoryTask2.Wait();

            //------------ Assert
            var onlyProductsCreatedForThisTests3 = this.GetOnlyProductsCreatedForThisTests(magentoService);

            onlyProductsCreatedForThisTests2.Should().NotBeNullOrEmpty();
            onlyProductsCreatedForThisTests2.Should().OnlyContain(x => x.Qty.ToDecimalOrDefault() == updateFirstTimeQty);
            onlyProductsCreatedForThisTests3.Should().OnlyContain(x => x.Qty.ToDecimalOrDefault() == updateSecondTimeQty);
        }
Пример #3
0
        public async Task UpdateInventoryWhenItWasInStock(MagentoServiceCredentialsAndConfig credentialsRest, MagentoServiceCredentialsAndConfig credentialsSoap)
        {
            var sku = "testsku1";
            var previousQuantity   = 99;
            var newQuantity        = 0;
            var magentoServiceRest = this.CreateMagentoService(credentialsRest.AuthenticatedUserCredentials.SoapApiUser, credentialsRest.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsRest.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsRest.Config.VersionByDefault, credentialsRest.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsRest.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            var updateSkuQuantityToZeroRequest = new InventoryBySku()
            {
                Sku = sku, Qty = previousQuantity
            };
            await magentoServiceRest.UpdateInventoryBySkuAsync(new InventoryBySku[] { updateSkuQuantityToZeroRequest });

            var updateSkuQuantityRequest = new InventoryBySku()
            {
                Sku = sku, Qty = newQuantity
            };
            await magentoServiceRest.UpdateInventoryBySkuAsync(new InventoryBySku[] { updateSkuQuantityRequest });

            var searchProductsResult = magentoServiceRest.GetProductsAsync(new[] { 0, 1 }, skus: new string[] { sku }, includeDetails: false).Result;
            var updatedProduct       = searchProductsResult.First();

            // ------------ Assert
            updatedProduct.Qty.Should().Be(updateSkuQuantityRequest.Qty.ToString());
            updatedProduct.IsInStock.Should().Be(false);
        }
        public void ProductsReceived(MagentoServiceCredentialsAndConfig credentialsRest, MagentoServiceCredentialsAndConfig credentialsSoap)
        {
            // ------------ Arrange
            var magentoServiceRest = this.CreateMagentoService(credentialsRest.AuthenticatedUserCredentials.SoapApiUser, credentialsRest.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsRest.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsRest.Config.VersionByDefault, credentialsRest.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsRest.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var magentoServiceSoap = this.CreateMagentoService(credentialsSoap.AuthenticatedUserCredentials.SoapApiUser, credentialsSoap.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsSoap.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsSoap.Config.VersionByDefault, credentialsSoap.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsSoap.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsSoap.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            var swR = Stopwatch.StartNew();
            var getProductsTaskRest = magentoServiceRest.GetProductsAsync(new[] { 0, 1 }, includeDetails: false);

            getProductsTaskRest.Wait();
            swR.Stop();

            Task.Delay(500).Wait();
            var swS = Stopwatch.StartNew();
            var getProductsTaskSoap = magentoServiceSoap.GetProductsAsync(new[] { 0, 1 }, includeDetails: false);

            getProductsTaskSoap.Wait();
            swS.Stop();

            // ------------ Assert
            Console.WriteLine("rest time: " + swR.Elapsed + " soap time: " + swS.Elapsed);

            var thatWasReturnedRest = getProductsTaskRest.Result.OrderBy(x => x.ProductId).ToList();
            var thatWasReturnedSoap = getProductsTaskSoap.Result.OrderBy(x => x.ProductId).ToList();

            thatWasReturnedRest.Should().BeEquivalentTo(thatWasReturnedSoap);
            swS.Elapsed.Should().BeGreaterThan(swR.Elapsed);
        }
Пример #5
0
        public void ReceiveStoreVersionAndSetup(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser,
                                                           credentials.AuthenticatedUserCredentials.SoapApiKey,
                                                           "null",
                                                           "null",
                                                           "null",
                                                           "null",
                                                           credentials.AuthenticatedUserCredentials.BaseMagentoUrl,
                                                           "http://w.com",
                                                           "http://w.com",
                                                           "http://w.com",
                                                           credentials.Config.VersionByDefault,
                                                           credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit,
                                                           credentials.AuthenticatedUserCredentials.SessionLifeTimeMs,
                                                           false,
                                                           credentials.Config.UseVersionByDefaultOnly,
                                                           ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            var getOrdersTask = magentoService.DetermineMagentoVersionAndSetupServiceAsync();

            getOrdersTask.Wait();

            // ------------ Assert
            var pingSoapInfo = getOrdersTask.Result;

            pingSoapInfo.Should().NotBeNull();
            (pingSoapInfo.SoapWorks && string.Compare(pingSoapInfo.ServiceUsedVersion, credentials.Config.VersionByDefault, StringComparison.CurrentCultureIgnoreCase) == 0).Should().BeTrue();
        }
Пример #6
0
        public void InventoryUpdated(MagentoServiceCredentialsAndConfig credentialsRest, MagentoServiceCredentialsAndConfig credentialsSoap)
        {
            // ------------ Arrange
            var magentoServiceRest = this.CreateMagentoService(credentialsRest.AuthenticatedUserCredentials.SoapApiUser, credentialsRest.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsRest.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsRest.Config.VersionByDefault, credentialsRest.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsRest.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var magentoServiceSoap = this.CreateMagentoService(credentialsSoap.AuthenticatedUserCredentials.SoapApiUser, credentialsSoap.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsSoap.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsSoap.Config.VersionByDefault, credentialsSoap.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsSoap.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsSoap.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var skus = new string[] { "testsku1", "testsku2", "testsku3", "testsku4" };

            // ------------ Act
            var getProductsTaskRest = magentoServiceRest.GetProductsAsync(new[] { 0, 1 }, skus: skus, includeDetails: true);

            getProductsTaskRest.Wait();
            var inventoryToUpdate = getProductsTaskRest.Result.Where(p => p.ProductType == "simple").OrderBy(p => p.ProductId).Select(p => new Inventory()
            {
                ItemId = p.ProductId, ProductId = p.ProductId, Sku = p.Sku, Qty = long.Parse(p.Qty) + 1
            });

            magentoServiceRest.UpdateInventoryAsync(inventoryToUpdate);

            Task.Delay(2000).Wait();
            var getProductsTaskSoap = magentoServiceSoap.GetProductsAsync(new[] { 0, 1 }, skus: skus, includeDetails: true);

            getProductsTaskSoap.Wait();
            var updatedInventory = getProductsTaskSoap.Result.Where(p => p.ProductType == "simple").OrderBy(p => p.ProductId).Select(p => new Inventory()
            {
                ItemId = p.ProductId, ProductId = p.ProductId, Sku = p.Sku, Qty = long.Parse(p.Qty)
            });

            // ------------ Assert
            inventoryToUpdate.Should().BeEquivalentTo(updatedInventory);
        }
Пример #7
0
        protected IEnumerable <Product> GetOnlyProductsCreatedForThisTests(MagentoServiceCredentialsAndConfig magentoServiceSoapCredentials)
        {
            var magentoService  = this.CreateMagentoService(magentoServiceSoapCredentials.AuthenticatedUserCredentials.SoapApiUser, magentoServiceSoapCredentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", magentoServiceSoapCredentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", MagentoVersions.M_2_0_2_0, magentoServiceSoapCredentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, magentoServiceSoapCredentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, magentoServiceSoapCredentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var getProductsTask = magentoService.GetProductsAsync(new[] { 0, 1 });

            getProductsTask.Wait();

            var allProductsinMagent             = getProductsTask.Result.ToList();
            var onlyProductsCreatedForThisTests = allProductsinMagent.Where(x => this._productsIds[magentoServiceSoapCredentials.AuthenticatedUserCredentials.SoapApiKey].ContainsKey(int.Parse(x.ProductId)));

            return(onlyProductsCreatedForThisTests);
        }
        public void NoExceptionThrow(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            Action act = () =>
            {
                var magentoInfoAsyncTask = magentoService.PingSoapAsync();
                magentoInfoAsyncTask.Wait();
            };

            // ------------ Assert
            act.ShouldNotThrow <Exception>();
        }
        public void ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            var getProductsTask = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: false);

            getProductsTask.Wait();

            // ------------ Assert
            var items = getProductsTask.Result.ToList();
            var dupl  = items.GroupBy(x => x.ProductId).Count(x => x.Count() > 1);

            dupl.Should().Be(0);
            getProductsTask.Result.Should().NotBeNullOrEmpty();
        }
Пример #10
0
        public void ThrowException(MagentoServiceCredentialsAndConfig credentials)
        {
            // can be red for magento 2.0 since user doesn't used in magento2.0 version
            // ------------ Arrange

            // ------------ Act
            Action act = () =>
            {
                var service = this.CreateMagentoService("incorrectuser", credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

                var magentoInfoAsyncTask = service.PingSoapAsync();
                magentoInfoAsyncTask.Wait();
            };

            // ------------ Assert
            act.ShouldThrow <Exception>();
        }
Пример #11
0
        public void ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            // ------------ Act
            var getProductsTask1 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true, productType: "simple", excludeProductByType: false, mark: new Mark(nameof(ReceiveProducts) + "_s"));
            var getProductsTask2 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true, productType: "bundle", excludeProductByType: false, mark: new Mark(nameof(ReceiveProducts) + "_b"));

            Task.WhenAll(getProductsTask1, getProductsTask2).Wait();

            // ------------ Assert
            getProductsTask1.Result.Should().NotBeNullOrEmpty();
            getProductsTask2.Result.Should().NotBeNullOrEmpty();

            getProductsTask1.Result.All(x => x.ProductType == "simple").Should().BeTrue();
            getProductsTask2.Result.All(x => x.ProductType == "bundle").Should().BeTrue();
        }
        public void ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var updatedFrom    = DateTime.UtcNow.AddMonths(-15);

            // ------------ Act
            var getProductsTask1 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true, updatedFrom: updatedFrom);
            var getProductsTask2 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true);

            Task.WhenAll(getProductsTask1, getProductsTask2).Wait();

            // ------------ Assert
            getProductsTask1.Result.Should().NotBeNullOrEmpty();
            getProductsTask2.Result.Should().NotBeNullOrEmpty();

            getProductsTask1.Result.All(x => x.UpdatedAt.ToDateTimeOrDefault() >= updatedFrom).Should().BeTrue();
            getProductsTask2.Result.Count().Should().BeGreaterOrEqualTo(getProductsTask1.Result.Count());
        }
        public void ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var updatedFrom    = DateTime.UtcNow.AddMonths(-15);

            // ------------ Act
            var productsAsync = magentoService.GetProductsAsync(new[] { 0, 1 }, stockItemsOnly: false, updatedFrom: updatedFrom);

            productsAsync.Wait();

            var fillProductsDetailsAsync = magentoService.FillProductsDetailsAsync(productsAsync.Result);

            fillProductsDetailsAsync.Wait();

            // ------------ Assert
            productsAsync.Result.Should().NotBeNullOrEmpty();
            //productsAsync.Result.All( x => x.UpdatedAt.ToDateTimeOrDefault() >= updatedFrom ).Should().BeTrue();
            fillProductsDetailsAsync.Result.Should().NotBeNullOrEmpty();
            fillProductsDetailsAsync.Result.Count().Should().Be(productsAsync.Result.Count());
            fillProductsDetailsAsync.Result.All(x => x.Categories != null && x.Images != null).Should().BeTrue();
        }
Пример #14
0
        public void ProductsDetailsFilled(MagentoServiceCredentialsAndConfig credentialsRest, MagentoServiceCredentialsAndConfig credentialsSoap)
        {
            // ------------ Arrange
            var magentoServiceRest = this.CreateMagentoService(credentialsRest.AuthenticatedUserCredentials.SoapApiUser, credentialsRest.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsRest.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsRest.Config.VersionByDefault, credentialsRest.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsRest.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var magentoServiceSoap = this.CreateMagentoService(credentialsSoap.AuthenticatedUserCredentials.SoapApiUser, credentialsSoap.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsSoap.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsSoap.Config.VersionByDefault, credentialsSoap.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsSoap.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            var getProductsSoapTask = magentoServiceSoap.GetProductsAsync(new[] { 0, 1 }, includeDetails: false);

            getProductsSoapTask.Wait();
            var productsList = getProductsSoapTask.Result;

            // ------------ Act
            var swR = Stopwatch.StartNew();
            var productsListRest        = productsList.Select(p => p.DeepClone());
            var fillProductsDetailsRest = magentoServiceRest.FillProductsDetailsAsync(productsListRest);

            fillProductsDetailsRest.Wait();
            swR.Stop();

            Task.Delay(500).Wait();
            var swS = Stopwatch.StartNew();
            var productsListSoap        = productsList.Select(p => p.DeepClone());
            var fillProductsDetailsSoap = magentoServiceSoap.FillProductsDetailsAsync(productsListSoap);

            fillProductsDetailsSoap.Wait();
            swS.Stop();

            // ------------ Assert
            Console.WriteLine("rest time: " + swR.Elapsed + " soap time: " + swS.Elapsed);

            var thatWasReturnedRest = fillProductsDetailsRest.Result.OrderBy(x => x.ProductId).ToList();
            var thatWasReturnedSoap = fillProductsDetailsSoap.Result.OrderBy(x => x.ProductId).ToList();

            thatWasReturnedRest.ForEach(item => item.Categories = item.Categories?.OrderBy(c => c.Id).Select(c => new Category(c, true)).ToArray());
            thatWasReturnedSoap.ForEach(item => item.Categories = item.Categories?.OrderBy(c => c.Id).Select(c => new Category(c, true)).ToArray());

            thatWasReturnedRest.Should().BeEquivalentTo(thatWasReturnedSoap);
            swS.Elapsed.Should().BeGreaterThan(swR.Elapsed);
        }
Пример #15
0
        public void InventoryUpdated(MagentoServiceCredentialsAndConfig credentials)
        {
            // ------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var rnd            = new Random(DateTime.UtcNow.Millisecond);
            var val            = rnd.Next(100, 1500);

            // ------------ Act
            //get products
            var getProductsTask1 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true, productType: "simple", excludeProductByType: false, mark: new Mark(nameof(InventoryUpdated) + "_s"));

            Task.WhenAll(getProductsTask1).Wait();
            var initialSkus = getProductsTask1.Result./*Where( x => x.Sku.Contains( "estSku1" ) ).*/ ToList();
            var src         = initialSkus.ToInventory(x => ( int )x.Qty.ToDecimalOrDefault());
            var inventories = src as IList <Inventory> ?? src.ToList();

            inventories.ForEach(x => x.Qty = val);

            //update
            var updateInventoryTask = magentoService.UpdateInventoryAsync(inventories);

            Task.WhenAll(updateInventoryTask).Wait();

            //get products
            var getProductsTask3 = magentoService.GetProductsAsync(new[] { 0, 1 }, includeDetails: true, productType: "simple", excludeProductByType: false, mark: new Mark(nameof(InventoryUpdated) + "_s"));

            Task.WhenAll(getProductsTask3).Wait();
            var resultSku = getProductsTask3.Result /*.Where( x => x.Sku.Contains( "estSku1" ) )*/;

            // ------------ Assert
            initialSkus.Should().NotBeNullOrEmpty();
            resultSku.Should().NotBeNullOrEmpty();

            initialSkus.Any(x => x.Qty.ToDecimalOrDefault() != val).Should().BeTrue();
            resultSku.All(x => x.Qty.ToDecimalOrDefault() == val).Should().BeTrue();
        }
Пример #16
0
        public void UpdateInventoryBYSkuAsync_UserAlreadyHasAccessTokens_ReceiveProducts(MagentoServiceCredentialsAndConfig credentials)
        {
            //------------ Arrange
            var magentoService = this.CreateMagentoService(credentials.AuthenticatedUserCredentials.SoapApiUser, credentials.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentials.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentials.Config.VersionByDefault, credentials.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentials.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentials.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            //------------ Act
            var getProductsTask = magentoService.GetProductsAsync(new[] { 0, 1 });

            getProductsTask.Wait();

            var allProductsinMagent             = getProductsTask.Result.ToList();
            var onlyProductsCreatedForThisTests = allProductsinMagent.Where(x => this._productsIds[credentials.AuthenticatedUserCredentials.SoapApiKey].ContainsKey(int.Parse(x.ProductId)));

            var itemsToUpdate = onlyProductsCreatedForThisTests.Select(x => new InventoryBySku()
            {
                Sku = x.Sku, Qty = 123
            });

            var updateInventoryTask = magentoService.UpdateInventoryBySkuAsync(itemsToUpdate, new[] { 0, 1 });

            updateInventoryTask.Wait();

            /////

            var getProductsTask2 = magentoService.GetProductsAsync(new[] { 0, 1 });

            getProductsTask2.Wait();

            var allProductsinMagent2             = getProductsTask2.Result.ToList();
            var onlyProductsCreatedForThisTests2 = allProductsinMagent2.Where(x => this._productsIds[credentials.AuthenticatedUserCredentials.SoapApiKey].ContainsKey(int.Parse(x.ProductId)));

            var itemsToUpdate2 = onlyProductsCreatedForThisTests2.Select(x => new InventoryBySku()
            {
                Sku = x.Sku, Qty = 100500
            });

            var updateInventoryTask2 = magentoService.UpdateInventoryBySkuAsync(itemsToUpdate2, new[] { 0, 1 });

            updateInventoryTask2.Wait();

            //------------ Assert
            var getProductsTask3 = magentoService.GetProductsAsync(new[] { 0, 1 });

            getProductsTask3.Wait();

            var allProductsinMagent3             = getProductsTask3.Result.ToList();
            var onlyProductsCreatedForThisTests3 = allProductsinMagent3.Where(x => this._productsIds[credentials.AuthenticatedUserCredentials.SoapApiKey].ContainsKey(int.Parse(x.ProductId)));

            onlyProductsCreatedForThisTests2.Should().OnlyContain(x => x.Qty.ToDecimalOrDefault() == 123);
            onlyProductsCreatedForThisTests3.Should().OnlyContain(x => x.Qty.ToDecimalOrDefault() == 100500);
        }
Пример #17
0
        public void OrdersReceived(MagentoServiceCredentialsAndConfig credentialsRest, MagentoServiceCredentialsAndConfig credentialsSoap)
        {
            // ------------ Arrange
            var magentoServiceRest = this.CreateMagentoService(credentialsRest.AuthenticatedUserCredentials.SoapApiUser, credentialsRest.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsRest.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsRest.Config.VersionByDefault, credentialsRest.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsRest.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsRest.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);
            var magentoServiceSoap = this.CreateMagentoService(credentialsSoap.AuthenticatedUserCredentials.SoapApiUser, credentialsSoap.AuthenticatedUserCredentials.SoapApiKey, "null", "null", "null", "null", credentialsSoap.AuthenticatedUserCredentials.BaseMagentoUrl, "http://w.com", "http://w.com", "http://w.com", credentialsSoap.Config.VersionByDefault, credentialsSoap.AuthenticatedUserCredentials.GetProductsThreadsLimit, credentialsSoap.AuthenticatedUserCredentials.SessionLifeTimeMs, false, credentialsSoap.Config.UseVersionByDefaultOnly, ThrowExceptionIfFailed.AllItems);

            //------------Act
            var modifiedFrom = new DateTime(2017, 6, 2, 23, 23, 59).AddSeconds(1);
            var modifiedTo   = new DateTime(2017, 7, 2, 23, 30, 39).AddSeconds(-1);

            var swR = Stopwatch.StartNew();
            var getOrdersTaskRest = magentoServiceRest.GetOrdersAsync(modifiedFrom, modifiedTo, new Mark("TEST-GET-ORDERS"));

            getOrdersTaskRest.Wait();
            swR.Stop();

            Task.Delay(10000).Wait();
            var swS            = Stopwatch.StartNew();
            var getOrdersTask2 = magentoServiceSoap.GetOrdersAsync(modifiedFrom, modifiedTo, new Mark("TEST-GET-ORDERS-2"));

            getOrdersTask2.Wait();
            swS.Stop();

            //------------Assert
            Console.WriteLine("rest time: " + swR.Elapsed + " soap time: " + swS.Elapsed);


            //these fields works in rest, but doesn't in soap. We need to skip them for assert.
            Action <Order> soapPreparer = x =>
            {
                var ba = x.Addresses.FirstOrDefault(y => y.Item1 == AddressTypeEnum.Billing);
                if (ba?.Item2?.Street != null)
                {
                    ba.Item2.Street = ba.Item2.Street.Replace(",", "").Replace(" ", "").Replace("\n", "");
                }

                var sa = x.Addresses.FirstOrDefault(y => y.Item1 == AddressTypeEnum.Shipping);
                if (sa?.Item2?.Street != null)
                {
                    sa.Item2.Street = sa.Item2.Street.Replace(",", "").Replace(" ", "").Replace("\n", "");
                }
            };

            //soap uses null for such values, but rest empty string
            Action <Order> restPreparer = x =>
            {
                var ba = x.Addresses.FirstOrDefault(y => y.Item1 == AddressTypeEnum.Billing);
                if (ba?.Item2?.Region == string.Empty)
                {
                    ba.Item2.Region = null;
                }

                if (ba?.Item2?.Street != null)
                {
                    ba.Item2.Street = ba.Item2.Street.Replace(",", "").Replace(" ", "").Replace("\n", "");
                }

                if (ba?.Item2?.Company == string.Empty)
                {
                    ba.Item2.Company = null;
                }

                var sa = x.Addresses.FirstOrDefault(y => y.Item1 == AddressTypeEnum.Shipping);
                if (sa?.Item2?.Region == string.Empty)
                {
                    sa.Item2.Region = null;
                }

                if (sa?.Item2?.Company == string.Empty)
                {
                    sa.Item2.Company = null;
                }

                if (sa?.Item2?.Street != null)
                {
                    sa.Item2.Street = sa.Item2.Street.Replace(",", "").Replace(" ", "").Replace("\n", "");
                }

                x.OrderId           = string.Empty;
                x.ShippingAddressId = null;
                x.ShippingFirstname = null;
                x.ShippingLastname  = null;
                x.ShippingMethod    = null;
                x.ShippingName      = null;
            };

            var thatWasReturnedRest = getOrdersTaskRest.Result.OrderBy(x => x.OrderIncrementalId).ToList();
            var thatWasReturnedSoap = getOrdersTask2.Result.OrderBy(x => x.OrderIncrementalId).ToList();

            thatWasReturnedSoap.ForEach(soapPreparer);
            thatWasReturnedRest.ForEach(restPreparer);
            thatWasReturnedRest.Should().BeEquivalentTo(thatWasReturnedSoap);
            swS.Elapsed.Should().BeGreaterThan(swR.Elapsed);              // I know this thing shouldn't be tested here. I hope, it will be fixed soon and will be moved to appropriate place
        }