public void OrderSystem_UnitTest_Payments_Invoice_SaveAndRetrieveSucceed() { Cart cart; Cart cartVerify; InvoicePayment payment; InvoicePayment paymentVerify; string invoiceNumber = "3511122A"; //A cart has to exist for a payment instance to be created cart = OrderHelper.CreateCartSimple(Guid.NewGuid()); cart.OrderForms[0].Payments.Clear(); //create invoice payment to test payment = (InvoicePayment)OrderHelper.CreateInvoicePayment(); payment.InvoiceNumber = invoiceNumber; //save the cart and then retrieve the cart from the database cartVerify = SaveAndRetrieveCart(cart, payment); //confirm the payment is retrieved Assert.AreNotEqual(cartVerify.OrderForms[0].Payments.Count, 0, "Invoice Payment not saved to the database"); //confirm the correct type returned Assert.AreEqual(cartVerify.OrderForms[0].Payments[0].GetType(), typeof(InvoicePayment), "InvoicePayment type not saved properly."); //verify properties set and returned correctly paymentVerify = (InvoicePayment)cartVerify.OrderForms[0].Payments[0]; Assert.AreEqual(paymentVerify.InvoiceNumber, invoiceNumber, "InvoicePayment fields not saved to the database."); }
public void OrderSystem_UnitTest_Payments_InvoiceSucceed() { Cart cart = OrderHelper.CreateCartSimple(Guid.NewGuid()); cart.OrderForms[0].Payments.Clear(); cart.OrderForms[0].Payments.Add(OrderHelper.CreateInvoicePayment()); cart.AcceptChanges(); cart.RunWorkflow("CartValidate"); cart.RunWorkflow("CartPrepare"); cart.OrderForms[0].Payments[0].Amount = cart.Total; cart.RunWorkflow("CartCheckout"); cart.AcceptChanges(); PurchaseOrder po = cart.SaveAsPurchaseOrder(); po = OrderContext.Current.GetPurchaseOrder(po.CustomerId, po.OrderGroupId); // Validate Assert.AreEqual(po.OrderForms[0].Payments.Count, 1); }
public void OrderSystem_CreateRandomOrder() { Cart cart = OrderContext.Current.GetCart(Cart.DefaultName, Guid.NewGuid()); String customerFullName = _customerNames[_random.Next(0, _customerNames.Length - 1)]; int space = customerFullName.IndexOf(' '); String customerFirstName = customerFullName.Substring(0, space); String customerLastName = customerFullName.Substring(space + 1); //String customerHomeId = customerFullName + "\'s " + "Home"; cart.CustomerName = customerFullName; cart.BillingCurrency = CommonSettingsManager.GetDefaultCurrency(); cart.OrderAddresses.Add(OrderHelper.CreateAddress()); cart.OrderAddresses[0].Name = "Home"; cart.OrderAddresses[0].FirstName = customerFirstName; cart.OrderAddresses[0].LastName = customerLastName; OrderForm orderForm = new OrderForm(); orderForm.Name = "default"; // Randomly pick a shipping method. Mediachase.Commerce.Orders.Dto.ShippingMethodDto smd = Mediachase.Commerce.Orders.Managers.ShippingManager.GetShippingMethods("en-us"); int shippingMethod = _random.Next(smd.ShippingMethod.Count); Guid shippingMethodId = smd.ShippingMethod[shippingMethod].ShippingMethodId; String shippingMethodName = smd.ShippingMethod[shippingMethod].Name; // Add line items // Random number of line items in an order int itemNum = _random.Next(3, 10); for (int i = 0; i < itemNum; i++) { orderForm.LineItems.Add(createLineItem(_random, shippingMethodId, shippingMethodName)); } // Add payments // Pay by phone orderForm.Payments.Add(OrderHelper.CreateInvoicePayment()); // Pay by credit card (sends out emails) //orderForm.Payments.Add(OrderHelper.CreateCreditCardPayment()); // Add discounts orderForm.Discounts.Add(OrderHelper.CreateOrderFormDiscount()); cart.OrderForms.Add(orderForm); cart.OrderForms[0].BillingAddressId = cart.OrderAddresses[0].Name; cart.RunWorkflow("CartValidate"); cart.RunWorkflow("CartPrepare"); cart.OrderForms[0].Payments[0].Amount = cart.Total; cart.RunWorkflow("CartCheckout"); // Last step PurchaseOrder po = cart.SaveAsPurchaseOrder(); // Randomize created date and time po.OrderForms[0].Created = randomDate(); // Randomize order status po.Status = randomStatus(); po.AcceptChanges(); }