public static ZoneDraft DefaultZoneWithEmptyLocations(ZoneDraft draft) { var zoneDraft = DefaultZoneDraft(draft); zoneDraft.Locations = new List <Location>(); return(zoneDraft); }
public void Init() { _client = new Client(Helper.GetConfiguration()); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.IsTrue(projectTask.Result.Success); _project = projectTask.Result.Result; _testZones = new List <Zone>(); for (int i = 0; i < 5; i++) { ZoneDraft zoneDraft = Helper.GetTestZoneDraft(); Task <Response <Zone> > zoneTask = _client.Zones().CreateZoneAsync(zoneDraft); zoneTask.Wait(); Assert.IsTrue(zoneTask.Result.Success); Zone zone = zoneTask.Result.Result; Assert.NotNull(zone.Id); _testZones.Add(zone); } }
public Zone CreateZone(ZoneDraft zoneDraft) { IClient commerceToolsClient = this.GetService <IClient>(); Zone zone = commerceToolsClient.ExecuteAsync(new CreateCommand <Zone>(zoneDraft)).Result; return(zone); }
public static ZoneDraft DefaultZoneDraftWithKey(ZoneDraft draft, string key) { var zoneDraft = DefaultZoneDraft(draft); zoneDraft.Key = key; return(zoneDraft); }
public static ZoneDraft DefaultZoneDraft(ZoneDraft zoneDraft) { var random = TestingUtility.RandomInt(); zoneDraft.Key = $"key_{random}"; zoneDraft.Name = $"Name_{random}"; return(zoneDraft); }
public static ZoneDraft DefaultZoneWithOneLocation(ZoneDraft draft, Location location) { var zoneDraft = DefaultZoneDraft(draft); zoneDraft.Locations = new List <Location> { location }; return(zoneDraft); }
public void CreateZone() { IClient commerceToolsClient = this.zonesFixture.GetService <IClient>(); ZoneDraft zoneDraft = this.zonesFixture.GetZoneDraft(); Zone zone = commerceToolsClient .ExecuteAsync(new CreateCommand <Zone>(zoneDraft)).Result; this.zonesFixture.ZonesToDelete.Add(zone); Assert.Equal(zoneDraft.Key, zone.Key); }
/// <summary> /// Creates a test shipping method draft. /// </summary> /// <returns>ShippingMethodDraft</returns> public static ZoneDraft GetTestZoneDraft(List <Location> locations = null) { string name = string.Concat("Test Zone ", Helper.GetRandomString(10)); ZoneDraft zoneDraft = new ZoneDraft(name); if (locations != null) { zoneDraft.Locations = locations; } return(zoneDraft); }
/// <summary> /// Create Zone Draft /// </summary> /// <returns></returns> public ZoneDraft GetZoneDraft(string country = null) { int ran = this.RandomInt(); string zoneCountry = country ?? this.GetRandomEuropeCountry(); var locations = new List <Location>() { new Location() { Country = zoneCountry } }; ZoneDraft zoneDraft = new ZoneDraft() { Name = $"EuropeZone_{ran}", Key = $"Zone_Key_{ran}", Locations = locations }; return(zoneDraft); }
public async Task ShouldCreateAndDeleteZoneAsync() { ZoneDraft zoneDraft = Helper.GetTestZoneDraft(); Response <Zone> response = await _client.Zones().CreateZoneAsync(zoneDraft); Assert.IsTrue(response.Success); Zone zone = response.Result; Assert.NotNull(zone.Id); string deletedZoneId = zone.Id; Response <JObject> deleteResponse = await _client.Zones().DeleteZoneAsync(zone); Assert.IsTrue(deleteResponse.Success); response = await _client.Zones().GetZoneByIdAsync(deletedZoneId); Assert.IsFalse(response.Success); }
/// <summary> /// Create Zone Draft, set default country and default state if they're not provided in params /// </summary> /// <returns></returns> public ZoneDraft GetZoneDraft(string country = null, string state = null) { int ran = TestingUtility.RandomInt(); string zoneCountry = country ?? TestingUtility.GetRandomEuropeCountry(); string zoneState = state ?? $"{zoneCountry}_State_{TestingUtility.RandomInt()}"; var locations = new List <Location>() { new Location() { Country = zoneCountry, State = zoneState } }; ZoneDraft zoneDraft = new ZoneDraft() { Name = $"EuropeZone_{ran}", Key = $"Zone_Key_{ran}", Locations = locations }; return(zoneDraft); }
/// <summary> /// Test setup /// </summary> public ShippingMethodManagerTest() { _client = new Client(Helper.GetConfiguration()); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.True(projectTask.Result.Success); _project = projectTask.Result.Result; Assert.True(_project.Languages.Count > 0); Assert.True(_project.Currencies.Count > 0); TaxCategoryDraft taxCategoryDraft = Helper.GetTestTaxCategoryDraft(_project); Task <Response <TaxCategory> > taxCategoryTask = _client.TaxCategories().CreateTaxCategoryAsync(taxCategoryDraft); taxCategoryTask.Wait(); Assert.True(taxCategoryTask.Result.Success); _testTaxCategory = taxCategoryTask.Result.Result; Assert.NotNull(_testTaxCategory.Id); Task <Response <ZoneQueryResult> > zoneQueryResultTask = _client.Zones().QueryZonesAsync(); zoneQueryResultTask.Wait(); Assert.True(zoneQueryResultTask.Result.Success); if (zoneQueryResultTask.Result.Result.Results.Count > 0) { _testZone = zoneQueryResultTask.Result.Result.Results[0]; _createdTestZone = false; } else { ZoneDraft zoneDraft = Helper.GetTestZoneDraft(); Task <Response <Zone> > zoneTask = _client.Zones().CreateZoneAsync(zoneDraft); zoneTask.Wait(); Assert.True(zoneTask.Result.Success); _testZone = zoneTask.Result.Result; _createdTestZone = true; } Assert.NotNull(_testZone.Id); foreach (string country in _project.Countries) { Location location = _testZone.Locations .Where(l => l.Country.Equals(country, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (location == null) { location = new Location(); location.Country = country; AddLocationAction addLocationAction = new AddLocationAction(location); Task <Response <Zone> > updateZoneTask = _client.Zones().UpdateZoneAsync(_testZone, addLocationAction); updateZoneTask.Wait(); Assert.True(updateZoneTask.Result.Success); _testZone = updateZoneTask.Result.Result; } } Assert.NotNull(_testZone.Locations.Count > 0); _testShippingMethods = new List <ShippingMethod>(); for (int i = 0; i < 5; i++) { ShippingMethodDraft shippingMethodDraft = Helper.GetTestShippingMethodDraft(_project, _testTaxCategory, _testZone); Task <Response <ShippingMethod> > shippingMethodTask = _client.ShippingMethods().CreateShippingMethodAsync(shippingMethodDraft); shippingMethodTask.Wait(); Assert.True(shippingMethodTask.Result.Success); ShippingMethod shippingMethod = shippingMethodTask.Result.Result; Assert.NotNull(shippingMethod.Id); _testShippingMethods.Add(shippingMethod); } }
public void Init() { _client = new Client(Helper.GetConfiguration()); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.IsTrue(projectTask.Result.Success); _project = projectTask.Result.Result; Assert.IsTrue(_project.Languages.Count > 0, "No Languages"); Assert.IsTrue(_project.Currencies.Count > 0, "No Currencies"); _testCustomers = new List <Customer>(); _testCarts = new List <Cart>(); _testCartsExternalAmountTaxMode = new List <Cart>(); CustomerDraft customerDraft; Task <Response <CustomerCreatedMessage> > customerTask; CustomerCreatedMessage customerCreatedMessage; CartDraft cartDraft; Cart cart; Task <Response <Cart> > cartTask; for (int i = 0; i < 5; i++) { customerDraft = Helper.GetTestCustomerDraft(); customerTask = _client.Customers().CreateCustomerAsync(customerDraft); customerTask.Wait(); Assert.IsTrue(customerTask.Result.Success); customerCreatedMessage = customerTask.Result.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); _testCustomers.Add(customerCreatedMessage.Customer); cartDraft = Helper.GetTestCartDraft(_project, customerCreatedMessage.Customer.Id); cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.NotNull(cartTask.Result); Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed"); cart = cartTask.Result.Result; Assert.NotNull(cart.Id); Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cartDraft.TaxMode == null ? "(default)" : cart.TaxMode.ToString())); _testCarts.Add(cart); cartDraft = Helper.GetTestCartDraft(_project, customerCreatedMessage.Customer.Id); cartDraft.TaxMode = TaxMode.ExternalAmount; cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.NotNull(cartTask.Result); Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed"); cart = cartTask.Result.Result; Assert.IsTrue(cart.TaxMode == TaxMode.ExternalAmount, string.Format("Cart created using ExternalAmount TaxMode failed - TaxMode: {0}", cart.TaxMode)); Assert.NotNull(cart.Id); Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cartDraft.TaxMode == null ? "(default)" : cart.TaxMode.ToString())); _testCartsExternalAmountTaxMode.Add(cart); } //customer/cart with external tax mode enabled customerDraft = Helper.GetTestCustomerDraft(); customerTask = _client.Customers().CreateCustomerAsync(customerDraft); customerTask.Wait(); Assert.IsTrue(customerTask.Result.Success); customerCreatedMessage = customerTask.Result.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); _testCustomers.Add(customerCreatedMessage.Customer); cartDraft = Helper.GetTestCartDraftUsingExternalTaxMode(_project, customerCreatedMessage.Customer.Id); cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.NotNull(cartTask.Result); Assert.IsTrue(cartTask.Result.Success, "CreateCartAsync failed"); cart = cartTask.Result.Result; Assert.NotNull(cart.Id); Console.Error.WriteLine(string.Format("CartManagerTest - Information Only - Init TestCartDraft TaxMode: {0}", cart.TaxMode)); _testCarts.Add(cart); ProductTypeDraft productTypeDraft = Helper.GetTestProductTypeDraft(); Task <Response <ProductType> > testProductTypeTask = _client.ProductTypes().CreateProductTypeAsync(productTypeDraft); testProductTypeTask.Wait(); Assert.IsTrue(testProductTypeTask.Result.Success, "CreateProductType failed"); _testProductType = testProductTypeTask.Result.Result; Assert.NotNull(_testProductType.Id); TaxCategoryDraft taxCategoryDraft = Helper.GetTestTaxCategoryDraft(_project); Task <Response <TaxCategory> > taxCategoryTask = _client.TaxCategories().CreateTaxCategoryAsync(taxCategoryDraft); taxCategoryTask.Wait(); Assert.IsTrue(taxCategoryTask.Result.Success, "CreateTaxCategory failed"); _testTaxCategory = taxCategoryTask.Result.Result; Assert.NotNull(_testTaxCategory.Id); Task <Response <ZoneQueryResult> > zoneQueryResultTask = _client.Zones().QueryZonesAsync(); zoneQueryResultTask.Wait(); Assert.IsTrue(zoneQueryResultTask.Result.Success); if (zoneQueryResultTask.Result.Result.Results.Count > 0) { _testZone = zoneQueryResultTask.Result.Result.Results[0]; _createdTestZone = false; } else { ZoneDraft zoneDraft = Helper.GetTestZoneDraft(); Task <Response <Zone> > zoneTask = _client.Zones().CreateZoneAsync(zoneDraft); zoneTask.Wait(); Assert.IsTrue(zoneTask.Result.Success, "CreateZone failed"); _testZone = zoneTask.Result.Result; _createdTestZone = true; } Assert.NotNull(_testZone.Id); foreach (string country in _project.Countries) { Location location = _testZone.Locations .Where(l => l.Country.Equals(country, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (location == null) { location = new Location(); location.Country = country; AddLocationAction addLocationAction = new AddLocationAction(location); Task <Response <Zone> > updateZoneTask = _client.Zones().UpdateZoneAsync(_testZone, addLocationAction); updateZoneTask.Wait(); Assert.IsTrue(updateZoneTask.Result.Success, "UpdateZone failed"); _testZone = updateZoneTask.Result.Result; } } Assert.NotNull(_testZone.Locations.Count > 0); ShippingMethodDraft shippingMethodDraft = Helper.GetTestShippingMethodDraft(_project, _testTaxCategory, _testZone); Task <Response <ShippingMethod> > shippingMethodTask = _client.ShippingMethods().CreateShippingMethodAsync(shippingMethodDraft); shippingMethodTask.Wait(); Assert.IsTrue(shippingMethodTask.Result.Success, "CreateShippingMethod failed"); _testShippingMethod = shippingMethodTask.Result.Result; Assert.NotNull(_testShippingMethod.Id); ProductDraft productDraft = Helper.GetTestProductDraft(_project, _testProductType.Id, _testTaxCategory.Id); Task <Response <Product> > testProductTask = _client.Products().CreateProductAsync(productDraft); testProductTask.Wait(); Assert.IsTrue(testProductTask.Result.Success, "CreateProduct failed"); _testProduct = testProductTask.Result.Result; Assert.NotNull(_testProduct.Id); PaymentDraft paymentDraft = Helper.GetTestPaymentDraft(_project, _testCustomers[0].Id); Task <Response <Payment> > paymentTask = _client.Payments().CreatePaymentAsync(paymentDraft); paymentTask.Wait(); Assert.IsTrue(paymentTask.Result.Success, "CreatePayment failed"); _testPayment = paymentTask.Result.Result; Assert.NotNull(_testPayment.Id); TypeDraft typeDraft = Helper.GetTypeDraft(_project); Task <Response <Type> > typeTask = _client.Types().CreateTypeAsync(typeDraft); typeTask.Wait(); Assert.IsTrue(typeTask.Result.Success, "CreateType failed"); _testType = typeTask.Result.Result; }
public void Init() { _client = new Client(Helper.GetConfiguration()); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.IsTrue(projectTask.Result.Success); _project = projectTask.Result.Result; _testCustomers = new List <Customer>(); for (int i = 0; i < 5; i++) { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Task <Response <CustomerCreatedMessage> > customerTask = _client.Customers().CreateCustomerAsync(customerDraft); customerTask.Wait(); Assert.IsTrue(customerTask.Result.Success); CustomerCreatedMessage customerCreatedMessage = customerTask.Result.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); _testCustomers.Add(customerCreatedMessage.Customer); } _testCarts = new List <Cart>(); Task <Response <Cart> > cartTask; for (int i = 0; i < 5; i++) { CartDraft cartDraft = Helper.GetTestCartDraft(_project, _testCustomers[i].Id); cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.IsTrue(cartTask.Result.Success); Cart cart = cartTask.Result.Result; Assert.NotNull(cart.Id); _testCarts.Add(cart); } ProductTypeDraft productTypeDraft = Helper.GetTestProductTypeDraft(); Task <Response <ProductType> > productTypeTask = _client.ProductTypes().CreateProductTypeAsync(productTypeDraft); productTypeTask.Wait(); Assert.IsTrue(productTypeTask.Result.Success); _testProductType = productTypeTask.Result.Result; Assert.NotNull(_testProductType.Id); TaxCategoryDraft taxCategoryDraft = Helper.GetTestTaxCategoryDraft(_project); Task <Response <TaxCategory> > taxCategoryTask = _client.TaxCategories().CreateTaxCategoryAsync(taxCategoryDraft); taxCategoryTask.Wait(); Assert.IsTrue(taxCategoryTask.Result.Success); _testTaxCategory = taxCategoryTask.Result.Result; Assert.NotNull(_testTaxCategory.Id); Task <Response <ZoneQueryResult> > zoneQueryResultTask = _client.Zones().QueryZonesAsync(); zoneQueryResultTask.Wait(); if (zoneQueryResultTask.Result.Success && zoneQueryResultTask.Result.Result.Results.Count > 0) { _testZone = zoneQueryResultTask.Result.Result.Results[0]; _createdTestZone = false; } else { ZoneDraft zoneDraft = Helper.GetTestZoneDraft(); Task <Response <Zone> > zoneTask = _client.Zones().CreateZoneAsync(zoneDraft); zoneTask.Wait(); Assert.IsTrue(zoneTask.Result.Success); _testZone = zoneTask.Result.Result; _createdTestZone = true; } Assert.NotNull(_testZone.Id); ShippingMethodDraft shippingMethodDraft = Helper.GetTestShippingMethodDraft(_project, _testTaxCategory, _testZone); Task <Response <ShippingMethod> > shippingMethodTask = _client.ShippingMethods().CreateShippingMethodAsync(shippingMethodDraft); shippingMethodTask.Wait(); Assert.IsTrue(shippingMethodTask.Result.Success); _testShippingMethod = shippingMethodTask.Result.Result; Assert.NotNull(_testShippingMethod.Id); ProductDraft productDraft = Helper.GetTestProductDraft(_project, _testProductType.Id, _testTaxCategory.Id); Task <Response <Product> > productTask = _client.Products().CreateProductAsync(productDraft); productTask.Wait(); Assert.IsTrue(productTask.Result.Success); _testProduct = productTask.Result.Result; Assert.NotNull(_testProduct.Id); int quantity = 1; AddLineItemAction addLineItemAction = new AddLineItemAction(_testProduct.Id, _testProduct.MasterData.Current.MasterVariant.Id); addLineItemAction.Quantity = quantity; cartTask = _client.Carts().UpdateCartAsync(_testCarts[0], addLineItemAction); cartTask.Wait(); Assert.IsTrue(cartTask.Result.Success); _testCarts[0] = cartTask.Result.Result; Assert.NotNull(_testCarts[0].Id); Assert.NotNull(_testCarts[0].LineItems); Assert.AreEqual(_testCarts[0].LineItems.Count, 1); Assert.AreEqual(_testCarts[0].LineItems[0].ProductId, _testProduct.Id); Assert.AreEqual(_testCarts[0].LineItems[0].Variant.Id, _testProduct.MasterData.Current.MasterVariant.Id); Assert.AreEqual(_testCarts[0].LineItems[0].Quantity, quantity); OrderFromCartDraft orderFromCartDraft = Helper.GetTestOrderFromCartDraft(_testCarts[0]); Task <Response <Order> > orderTask = _client.Orders().CreateOrderFromCartAsync(orderFromCartDraft); orderTask.Wait(); Assert.IsTrue(orderTask.Result.Success); _testOrder = orderTask.Result.Result; Assert.NotNull(_testOrder.Id); cartTask = _client.Carts().GetCartByIdAsync(_testCarts[0].Id); cartTask.Wait(); Assert.IsTrue(cartTask.Result.Success); _testCarts[0] = cartTask.Result.Result; Assert.NotNull(_testCarts[0].Id); }