public async Task ShouldAuthenticateCustomer() { string email = string.Concat("authtest", Helper.GetRandomString(20), "@example.com"); string password = "******"; CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); customerDraft.Email = email; customerDraft.Password = password; Response <CustomerCreatedMessage> customerCreatedResponse = await _client.Customers().CreateCustomerAsync(customerDraft); Assert.IsTrue(customerCreatedResponse.Success); CustomerCreatedMessage customerCreatedMessage = customerCreatedResponse.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.AreEqual(customerCreatedMessage.Customer.Email, email); Customer customer = customerCreatedMessage.Customer; Response <CustomerSignInResult> customerSignInResponse = await _client.Customers().AuthenticateCustomerAsync(email, password); Assert.IsTrue(customerSignInResponse.Success); CustomerSignInResult customerSignInResult = customerSignInResponse.Result; Assert.NotNull(customerSignInResult.Customer); Assert.AreEqual(customerSignInResult.Customer.Email, email); await _client.Customers().DeleteCustomerAsync(customer); }
public void Init() { _client = Helper.GetClient(); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.IsTrue(projectTask.Result.Success); _project = projectTask.Result.Result; 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); _testCustomer = customerCreatedMessage.Customer; CartDraft cartDraft = Helper.GetTestCartDraft(_project, _testCustomer.Id); Task <Response <Cart> > cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.IsTrue(cartTask.Result.Success); _testCart = cartTask.Result.Result; Assert.NotNull(_testCart.Id); Assert.AreEqual(_testCart.CustomerId, _testCustomer.Id); }
public async Task ShouldSetCustomerIdAsync() { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Response <CustomerCreatedMessage> customerResponse = await _client.Customers().CreateCustomerAsync(customerDraft); Assert.True(customerResponse.Success); CustomerCreatedMessage customerCreatedMessage = customerResponse.Result; Assert.NotNull(customerCreatedMessage.Customer); Customer customer = customerCreatedMessage.Customer; SetCustomerIdAction setCustomerIdAction = new SetCustomerIdAction { CustomerId = customer.Id }; Response <Cart> cartResponse = await _client.Carts().UpdateCartAsync(_testCarts[0], setCustomerIdAction); Assert.True(cartResponse.Success); _testCarts[0] = cartResponse.Result; Assert.NotNull(_testCarts[0].Id); Assert.Equal(_testCarts[0].CustomerId, customer.Id); setCustomerIdAction = new SetCustomerIdAction(); cartResponse = await _client.Carts().UpdateCartAsync(_testCarts[0], setCustomerIdAction); Assert.True(cartResponse.Success); _testCarts[0] = cartResponse.Result; Assert.NotNull(_testCarts[0].Id); Assert.NotEqual(_testCarts[0].CustomerId, customer.Id); await _client.Customers().DeleteCustomerAsync(customer); }
public void SerializeMessageWithDateTime() { var serializerService = this.serializationFixture.SerializerService; //use date format first var customerCreatedMessage = new CustomerCreatedMessage { CreatedAt = DateTime.Parse("2021-09-09") }; var customerJson = serializerService.Serialize(customerCreatedMessage); Assert.NotNull(customerJson); // use datetime format var message = new OrderCreatedMessage { CreatedAt = DateTime.Parse("2021-09-09T09:50:25") }; var orderJson = serializerService.Serialize(message); Assert.NotNull(orderJson); Assert.Equal( "{\"sequenceNumber\":0,\"resourceVersion\":0," + "\"type\":\"OrderCreated\",\"version\":0," + "\"createdAt\":\"2021-09-09T09:50:25\"," + "\"lastModifiedAt\":\"0001-01-01\"}", orderJson); }
public async Task ShouldUpdateCartAsync() { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Response <CustomerCreatedMessage> messageResponse = await _client.Customers().CreateCustomerAsync(customerDraft); Assert.IsTrue(messageResponse.Success); CustomerCreatedMessage customerCreatedMessage = messageResponse.Result; Assert.NotNull(customerCreatedMessage.Customer); Customer customer = customerCreatedMessage.Customer; Assert.NotNull(customer.Id); SetCustomerIdAction setCustomerIdAction = new SetCustomerIdAction(); setCustomerIdAction.CustomerId = customer.Id; GenericAction recalculateAction = new GenericAction("recalculate"); List <UpdateAction> actions = new List <UpdateAction>(); actions.Add(setCustomerIdAction); actions.Add(recalculateAction); Response <Cart> cartResponse = await _client.Carts().UpdateCartAsync(_testCarts[0], actions); Assert.IsTrue(cartResponse.Success); _testCarts[0] = cartResponse.Result; Assert.NotNull(_testCarts[0].Id); Assert.AreEqual(_testCarts[0].CustomerId, customer.Id); await _client.Customers().DeleteCustomerAsync(customer.Id, customer.Version); }
public void Init() { _client = Helper.GetClient(); Task <Response <Project.Project> > projectTask = _client.Project().GetProjectAsync(); projectTask.Wait(); Assert.IsTrue(projectTask.Result.Success); _project = projectTask.Result.Result; _testCustomers = new List <Customer>(); _testPayments = new List <Payment>(); for (int i = 0; i < 5; i++) { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Task <Response <CustomerCreatedMessage> > customerCreatedTask = _client.Customers().CreateCustomerAsync(customerDraft); customerCreatedTask.Wait(); Assert.IsTrue(customerCreatedTask.Result.Success); CustomerCreatedMessage customerCreatedMessage = customerCreatedTask.Result.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); _testCustomers.Add(customerCreatedMessage.Customer); PaymentDraft paymentDraft = Helper.GetTestPaymentDraft(_project, customerCreatedMessage.Customer.Id); Task <Response <Payment> > paymentTask = _client.Payments().CreatePaymentAsync(paymentDraft); paymentTask.Wait(); Assert.IsTrue(paymentTask.Result.Success); Payment payment = paymentTask.Result.Result; Assert.NotNull(payment.Id); _testPayments.Add(payment); } }
public async Task ShouldCreateAndDeleteCustomerAsync() { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Response <CustomerCreatedMessage> customerCreatedResponse = await _client.Customers().CreateCustomerAsync(customerDraft); Assert.IsTrue(customerCreatedResponse.Success); CustomerCreatedMessage customerCreatedMessage = customerCreatedResponse.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); Customer customer = customerCreatedMessage.Customer; string deletedCustomerId = customer.Id; Response <Customer> customerResponse = await _client.Customers().DeleteCustomerAsync(customer); Assert.IsTrue(customerResponse.Success); customerResponse = await _client.Customers().GetCustomerByIdAsync(deletedCustomerId); Assert.IsFalse(customerResponse.Success); }
/// <summary> /// Test setup /// </summary> public CartManagerTest() { _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); _testCustomers = new List <Customer>(); _testCarts = new List <Cart>(); _testCartsExternalAmountTaxMode = new List <Cart>(); for (int i = 0; i < 5; i++) { CustomerDraft customerDraft = Helper.GetTestCustomerDraft(); Task <Response <CustomerCreatedMessage> > customerTask = _client.Customers().CreateCustomerAsync(customerDraft); customerTask.Wait(); Assert.True(customerTask.Result.Success); CustomerCreatedMessage customerCreatedMessage = customerTask.Result.Result; Assert.NotNull(customerCreatedMessage.Customer); Assert.NotNull(customerCreatedMessage.Customer.Id); _testCustomers.Add(customerCreatedMessage.Customer); CartDraft cartDraft = Helper.GetTestCartDraft(_project, customerCreatedMessage.Customer.Id); Task <Response <Cart> > cartTask = _client.Carts().CreateCartAsync(cartDraft); cartTask.Wait(); Assert.True(cartTask.Result.Success); Cart cart = cartTask.Result.Result; Assert.NotNull(cart.Id); _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.True(cartTask.Result.Success, "CreateCartAsync failed"); cart = cartTask.Result.Result; Assert.True(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); } ProductTypeDraft productTypeDraft = Helper.GetTestProductTypeDraft(); Task <Response <ProductType> > testProductTypeTask = _client.ProductTypes().CreateProductTypeAsync(productTypeDraft); testProductTypeTask.Wait(); Assert.True(testProductTypeTask.Result.Success); _testProductType = testProductTypeTask.Result.Result; Assert.NotNull(_testProductType.Id); 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); ShippingMethodDraft shippingMethodDraft = Helper.GetTestShippingMethodDraft(_project, _testTaxCategory, _testZone); Task <Response <ShippingMethod> > shippingMethodTask = _client.ShippingMethods().CreateShippingMethodAsync(shippingMethodDraft); shippingMethodTask.Wait(); Assert.True(shippingMethodTask.Result.Success); _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.True(testProductTask.Result.Success); _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.True(paymentTask.Result.Success); _testPayment = paymentTask.Result.Result; Assert.NotNull(_testPayment.Id); TypeDraft typeDraft = Helper.GetTypeDraft(_project); Task <Response <Type> > typeTask = _client.Types().CreateTypeAsync(typeDraft); typeTask.Wait(); Assert.True(typeTask.Result.Success); _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); }