private async void bCreate_Click(object sender, RoutedEventArgs e) { if (cProduct.SelectedIndex == -1 || string.IsNullOrEmpty(txtCustomerID.Text) || string.IsNullOrEmpty(txtQuantity.Text)) { MessageBox.Show("There are fields missing."); return; } int productId = (cProduct.SelectedItem as Tuple<int, string>).Item1; bCreate.IsEnabled = false; txtQuantity.IsEnabled = false; cProduct.IsEnabled = false; OrdersServiceClient ordersServiceClient = new OrdersServiceClient(); await ordersServiceClient.PlaceOrderAsync(new OrderModel { ProductCode = productId, CustomerId = int.Parse(txtCustomerID.Text), Quantity = int.Parse(txtQuantity.Text) }); bCreate.IsEnabled = true; txtQuantity.IsEnabled = true; cProduct.IsEnabled = true; cProduct.SelectedIndex = -1; txtCustomerID.Text = string.Empty; txtQuantity.Text = string.Empty; (DataContext as PlaceOrderViewModel).Products = new List<Tuple<int, string>>(); }
public void CreateNewOrderFaultTest() { using (var client = new OrdersServiceClient()) { client.CreateNewOrder(null); } }
private async void RefreshProducts() { OrdersServiceClient ordersServiceClient = new OrdersServiceClient(); IEnumerable<ProductModel> products = await ordersServiceClient.ListProductsAsync(); (DataContext as PlaceOrderViewModel).Products = products.Select(p => Tuple.Create(p.Code, p.Name)); }
public void SendOrder(Order o) { using (var client = new OrdersServiceClient()) { client.Open(); client.PrepareOrder(o); client.Close(); } }
public void CloseOrderFaultTest() { using (var client = new OrdersServiceClient()) { var order = this.GetExistingOder(dto => dto.OrderState.Equals(OrderState.New) || dto.OrderState.Equals(OrderState.Closed)); client.CloseOrder(order.OrderId); } }
public async Task <ObservableCollection <OrderDataModel> > LoadOrdersAsync() { OrdersServiceClient client = new OrdersServiceClient(); Loading = true; await Task.Delay(1000); Orders = new ObservableCollection <OrderDataModel>(client.GetOrders(SearchText)); Loading = false; return(await Task.FromResult(Orders)); }
public void DeleteOrderFaultOnAttemptToDeleteClosedOrderTest() { using (var client = new OrdersServiceClient()) { var order = this.GetExistingOder(dto => dto.OrderState.Equals(OrderState.Closed)); if (order != null) { client.DeleteOrder(order.OrderId); } } }
public void CreateNewOrderTest() { using (var client = new OrdersServiceClient()) { var newOrder = this.CreateNewOrder(); var orderId = client.CreateNewOrder(newOrder); Assert.IsTrue(orderId > 0); var newOrderFromDB = client.GetById(orderId); Assert.IsNotNull(newOrderFromDB); Assert.IsTrue(newOrderFromDB.OrderState.Equals(OrderState.New)); } }
public void CloseOrderTest() { using (var client = new OrdersServiceClient()) { var newOrder = this.CreateNewOrder(); var newOrderId = client.CreateNewOrder(newOrder); client.ProcessOrder(newOrderId); client.CloseOrder(newOrderId); var newOrderFromDB = client.GetById(newOrderId); Assert.IsTrue(newOrderFromDB.OrderState.Equals(OrderState.Closed)); } }
private async void OnBtnChangeOrderStatusClick(object sender, System.EventArgs e) { using (var client = new OrdersServiceClient()) { try { this.btnChangeOrderStatus.Enabled = false; var allOrders = await client.GetAllAsync(); if (!allOrders.Any()) { this.AppendMessage("There is no one order in DB."); return; } var orderInNewState = allOrders.FirstOrDefault(o => o.OrderState.Equals(OrderState.New)); if (orderInNewState == null) { this.AppendMessage("There is no one New order in DB."); return; } orderInNewState.RequiredDate = DateTime.Now.AddDays(1); await client.UpdateOrderAsync(orderInNewState); await client.ProcessOrderAsync(orderInNewState.OrderId); } catch (CommunicationException exception) { this.AppendMessage("An error occured on attempt of changing order status."); this.AppendMessage(exception.Message); } finally { this.btnChangeOrderStatus.Enabled = true; } } }
public void GetAllTest() { using (var client = new OrdersServiceClient()) { var allOrders = client.GetAll(); Assert.IsTrue(allOrders != null && allOrders.Any()); } }
public void GetByIdTest() { using (var client = new OrdersServiceClient()) { var allOrders = client.GetAll(); var orderId = allOrders.First().OrderId; var orderById = client.GetById(orderId); Assert.IsNotNull(orderById); } }
public void DeleteOrderTest() { using (var client = new OrdersServiceClient()) { var newOrder = this.CreateNewOrder(); var orderId = client.CreateNewOrder(newOrder); var affectedRows = client.DeleteOrder(orderId); Assert.AreEqual(affectedRows, 1); } }
public void DeleteOrderFaultOnAttemptToDeleteNotExistingOrderTest() { using (var client = new OrdersServiceClient()) { client.DeleteOrder(-1); } }
private static void TestOrdersService() { List <Order> orders = new List <Order> { new Order() { Id = null, DateOrder = DateTime.Now, DeliveryService = new DeliveriService("Self"), OrderCustomer = new Customer { Id = 1 }, Comment = "", TotalSum = 340, OrderStatuses = new List <OrderStatus> { new OrderStatus { Status = new Status("moderation"), DateChange = DateTime.Now } }, OrderList = new List <OrderedProduct> { new OrderedProduct { Product = new Product { Articulus = 1 }, Quantity = 5 }, new OrderedProduct { Product = new Product { Articulus = 2 }, Quantity = 2 } } } }; using (OrdersServiceClient ordersclient = new OrdersServiceClient()) { //Insert Console.WriteLine("1. Insert data:"); var cres = ordersclient.Create(orders[0]); orders[0].Id = (int)cres.Item2; Console.WriteLine("Insert data\n"); //GetAll Console.WriteLine("2. Viewing data:"); var gres = ordersclient.GetAll(); foreach (var order in gres) { Console.WriteLine(order.Id + " " + order.DateOrder + " " + order.OrderCustomer.Id); } //Update Console.WriteLine("\n3. Update data:"); orders[0].TotalSum = 80; orders[0].Comment = "12212121"; orders[0].DeliveryService = new DeliveriService("RusPochta"); orders[0].OrderList[0].Quantity = 8; orders[0].OrderList[0].Quantity = 9; orders[0].OrderList.Add(new OrderedProduct { Product = new Product { Articulus = 3 }, Quantity = 4 }); var ures = ordersclient.Update(orders); Console.WriteLine(ures.Item2 + "\n"); //GetAll Console.WriteLine("4. Viewing data:"); var gres2 = ordersclient.GetAll(); foreach (var order in gres2) { Console.WriteLine(order.Id + " " + order.DateOrder + " " + order.OrderCustomer.Id); } //Delete Console.WriteLine("\n5. Deleting data:"); var dres = ordersclient.Delete(orders); Console.WriteLine(dres.Item2 + "\n"); //GetAll Console.WriteLine("6. Viewing data:"); var gres3 = ordersclient.GetAll(); foreach (var order in gres3) { Console.WriteLine(order.Id + " " + order.DateOrder + " " + order.OrderCustomer.Id); } } }
private OrderDTO GetExistingOder(Func<OrderDTO, bool> predicate = null) { using (var client = new OrdersServiceClient()) { var allOrders = client.GetAll(); predicate = predicate ?? (dto => true); return allOrders.First(predicate); } }
public void UpdateOrderFaultOnNullParameterTest() { using (var client = new OrdersServiceClient()) { client.UpdateOrder(null); } }
public void UpdateOrderFaultOnAttemptNotInNewStateTest() { using (var client = new OrdersServiceClient()) { var order = this.GetExistingOder(dto => dto.OrderState.Equals(OrderState.InWork) || dto.OrderState.Equals(OrderState.Closed)); client.UpdateOrder(order); } }