private int PostXml(OrderGroup model) { var xml = SerializeXml(model); AcceptXml(); var response = Client.PostAsync($"/episerverapi/commerce/order", new StringContent(xml, Encoding.Unicode, "application/xml")).Result; RemoveAcceptXml(); var message = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { throw new Exception($"Post failed! Status: {response.StatusCode}. Message: {message}"); } var document = XDocument.Parse(message); var str = document.Descendants(XName.Get("OrderGroupId")).First().Value; int orderGroupId; int.TryParse(str, out orderGroupId); return(orderGroupId); }
public void it_posts_and_searches_with_accept_xml() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = "default"; var postModel = new OrderGroup { CustomerId = contactId, Name = cartName, OrderAddresses = new [] { new Models.OrderAddress { FirstName = "Lara", LastName = "Olson" } }, OrderNotes = new[] { new Models.OrderNote { Title = "The note", Detail = "There are some details." } } }; var orderGroupId = PostXml(postModel); var xmlString = SearchXml(); Delete(orderGroupId); Assert.True(IsXml(xmlString)); }
public void it_searches_by_statuses() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var statuses = new[] { "InProgress", "Completed", "OnHold", "PartiallyShipped" }; var orderIds = new List <int>(); foreach (var status in statuses) { var postModel = new OrderGroup { CustomerId = contactId, Name = cartName, Status = status }; var newOrder = Post(postModel); orderIds.Add((int)newOrder.OrderGroupId); } var expectedStatuses = new[] { "InProgress", "OnHold" }; var orders = Search(expectedStatuses); foreach (var orderId in orderIds) { Delete(orderId); } Assert.True(orders.All(x => expectedStatuses.Contains((string)x["Status"]))); }
public void it_updates_order_status() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var postModel = new OrderGroup { CustomerId = contactId, Name = cartName }; var newOrder = Post(postModel); int orderGroupId = newOrder.OrderGroupId; var order = Get(orderGroupId); var orderGroup = ToOrderGroup(order); var expectedStatus = "New status"; orderGroup.Status = expectedStatus; Put(orderGroupId, orderGroup); var savedOrder = Get(orderGroupId); Delete(orderGroupId); Assert.Equal(expectedStatus, savedOrder.Status.ToString()); }
private void Put(int orderId, OrderGroup model) { var json = JsonConvert.SerializeObject(model); var response = Client.PutAsync($"/episerverapi/commerce/order/{orderId}", new StringContent(json, Encoding.UTF8, "application/json")).Result; var message = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { throw new Exception($"Post failed! Status: {response.StatusCode}. Message: {message}"); } }
private dynamic Post(OrderGroup model) { var json = JsonConvert.SerializeObject(model); var response = Client.PostAsync($"/episerverapi/commerce/order", new StringContent(json, Encoding.UTF8, "application/json")).Result; AcceptXml(); var message = response.Content.ReadAsStringAsync().Result; RemoveAcceptXml(); if (!response.IsSuccessStatusCode) { throw new Exception($"Post failed! Status: {response.StatusCode}. Message: {message}"); } return(JObject.Parse(message)); }
public void post_creates_new_order_and_searches_it() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var model = new OrderGroup { CustomerId = contactId, Name = cartName }; var order = Post(model); Search(OrderShipmentStatus.Packing, Guid.NewGuid()); Search(OrderShipmentStatus.AwaitingInventory, null); Search(null, Guid.NewGuid()); Search(null, null); Delete((int)order.OrderGroupId); }
public void it_searches_since_modified_date() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var postModel = new OrderGroup { CustomerId = contactId, Name = cartName }; var newOrder = Post(postModel); int orderGroupId = newOrder.OrderGroupId; var updatedSince = DateTime.UtcNow.AddMinutes(-1); var orders = Search(updatedSince); Delete(orderGroupId); Assert.True(orders.Any(x => (DateTime)x["Modified"] >= updatedSince)); Assert.False(orders.Any(x => (DateTime)x["Modified"] < updatedSince)); }
public void post_creates_new_order() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var now = DateTime.UtcNow; var model = new OrderGroup { CustomerId = contactId, Name = cartName, OrderForms = new[] { new Models.OrderForm { Name = "Default", Total = 500, Shipments = new [] { new Models.Shipment { ShipmentTrackingNumber = "Track-123", ShippingMethodName = "FedEx", Status = $"Shipped on {now}", LineItems = new [] { new Models.LineItem { Code = "XYZ", DisplayName = "XYZ Shirt", Quantity = 1, PlacedPrice = 150, Properties = new List <PropertyItem> // Requires properties created in commerce DB through API or CM { new PropertyItem { Key = "CustomLineItemProperty", Value = "Shipped" } } } }, Properties = new List <PropertyItem> // Requires properties created in commerce DB through API or CM { new PropertyItem { Key = "Carrier", Value = "FedEx" }, new PropertyItem { Key = "CarrierTrackingUrl", Value = "http://fedex.com/track/{0}" } } } } } }, OrderAddresses = new[] { new Models.OrderAddress { FirstName = "Antony", LastName = "Hopkins" } }, OrderNotes = new[] { new Models.OrderNote { Title = "The note", Detail = "There are some notes." } } }; var order = Post(model); Assert.NotNull(order); Assert.NotNull(order.OrderForms); Assert.Equal(1, order.OrderForms.Count); Assert.NotNull(order.OrderAddresses); Assert.Equal(1, order.OrderAddresses.Count); Assert.NotNull(order.OrderNotes); Assert.Equal(1, order.OrderNotes.Count); Delete((int)order.OrderGroupId); }
public void it_stores_lineitem_custom_property() { var contactId = Guid.Parse("2A40754D-86D5-460B-A5A4-32BC87703567"); // admin contact var cartName = Cart.DefaultName; var now = DateTime.UtcNow; var lineItemPropertyKey = "CustomLineItemProperty"; var lineItemPropertyValue = "TestSucceeded"; var model = new OrderGroup { CustomerId = contactId, Name = cartName, OrderForms = new[] { new Models.OrderForm { Name = "Default", Total = 500, Shipments = new [] { new Models.Shipment { ShipmentTrackingNumber = "Track-123", ShippingMethodName = "FedEx", Status = $"Shipped on {now}", LineItems = new [] { new Models.LineItem { Code = "XYZ", DisplayName = "XYZ Shirt", Quantity = 1, PlacedPrice = 150, Properties = new List <PropertyItem> // Requires properties created in commerce DB through API or CM { new PropertyItem { Key = lineItemPropertyKey, Value = lineItemPropertyValue } } } } } } } } }; var order = ((JObject)Post(model)).ToObject <Models.PurchaseOrder>(); var firstLineItem = order?.OrderForms[0]?.LineItems?.FirstOrDefault(); Assert.NotNull(firstLineItem?.Properties); var customProperty = order.OrderForms[0]?.LineItems?.FirstOrDefault() ?.Properties.FirstOrDefault(x => x.Key.Equals(lineItemPropertyKey)); Assert.NotNull(customProperty); Assert.Equal(lineItemPropertyValue, customProperty.Value); Delete((int)order.OrderGroupId); }