public static Order GetOrderFromDto(OrderDto order)
        {
            if (order == null) return null;

            Order o = new Order()
            {
                OrderID = order.OrderId,
                Latitude = order.Latitude,
                Longitude = order.Longitude,
                SubmittedAt = order.SubmittedAt,
                DeliveredAt = order.DeliveredAt,
                Status = !order.Status.HasValue ? eOrderStatus.NEW : (eOrderStatus)eOrderStatus.Parse(typeof(eOrderStatus),order.Status.ToString(),true),
                OrderedProducts = new List<ProductOrder>()
            };
            foreach (var product in order.Products)
            {
                o.OrderedProducts.Add(new ProductOrder()
                    {
                        OriginOrder = o,
                        Units = product.Units,
                        ProductID = product.ProductID
                    });
            }
            return o;
        }
        public void OrdersSanityTest()
        {
            OrderDto dto = new OrderDto()
            {
                Latitude = 40,
                Longitude = 50,
                Products = new List<ProductOrderDto>()
                {
                    new ProductOrderDto()
                    {
                        ProductID = 5,
                        Units = 5
                    }
                }
            };

            int id = jsonApi.PutOrder(dto);

            Assert.IsNotNull(id , "Id return by inserting order was null");

            var returnedDto = jsonApi.GetOrder(id);

            Assert.AreEqual(id, returnedDto.OrderId);
            Assert.AreEqual(dto.Latitude, returnedDto.Latitude);
            Assert.AreEqual(dto.Longitude, returnedDto.Longitude);

            jsonApi.SetOrderStatus(id, OrderStatus.DELIVERED);

            returnedDto = jsonApi.GetOrder(id);

            Assert.AreEqual(id, returnedDto.OrderId);
            Assert.AreEqual(dto.Latitude, returnedDto.Latitude);
            Assert.AreEqual(dto.Longitude, returnedDto.Longitude);
            Assert.AreEqual(OrderStatus.DELIVERED, returnedDto.Status);
            Assert.IsNotNull(returnedDto.DeliveredAt);

            jsonApi.DeleteOrder(returnedDto.OrderId);
            var orders = jsonApi.GetActiveOrders();

            Assert.IsFalse(orders.Select(o => o.OrderId).Contains<int>(returnedDto.OrderId),
                "returned list of orders contained deleted order");
        }
Beispiel #3
0
        public static OrderDto OrderDtoFromOrderModel(Order order)
        {
            if (order == null) return null;

            OrderDto dto = new OrderDto()
            {
                OrderId = order.OrderID,
                Latitude = order.Latitude,
                Longitude = order.Longitude,
                SubmittedAt = order.SubmittedAt,
                DeliveredAt = order.DeliveredAt,
                Status = (OrderStatus)OrderStatus.Parse(typeof(OrderStatus),order.Status.ToString(),true),
                Products = new List<ProductOrderDto>()
            };
            foreach (var product in order.OrderedProducts)
            {
                dto.Products.Add(new ProductOrderDto()
                    {
                        ProductID = product.ProductID,
                        Units = product.Units
                    });
            }
            return dto;
        }
Beispiel #4
0
 public int PutOrder(OrderDto order)
 {
     var request = new PutOrderRequest(baseUrl, order);
     String response = requester.Put<OrderDto>(request);
     return Convert.ToInt32(response);
 }
Beispiel #5
0
 protected GeoLocation GetLocation(OrderDto order)
 {
     return new GeoLocation(order.Latitude, order.Longitude);
 }