Ejemplo n.º 1
0
        public void Put()
        {
            var name      = CreateTestProductName();
            var inventory = new Inventory
            {
                Name      = name,
                Quantity  = 900,
                CreatedOn = DateTime.UtcNow
            };

            var expected = new Message
            {
                Action      = "Put",
                Inventories = new List <Inventory> {
                    inventory
                }
            };

            AddedProducts.Add(name);
            _ = InventoryController.Put(name, inventory);
            var result = JsonSerializer.Deserialize <Message>(ConsumeMessage());

            Assert.AreEqual(expected.Action, result.Action);
            Assert.AreEqual(expected.Inventories.ToList().Count, result.Inventories.ToList().Count);
            Assert.AreEqual(expected.Inventories.First().Name, result.Inventories.First().Name);
            Assert.AreEqual(expected.Inventories.First().Quantity, result.Inventories.First().Quantity);
            Assert.AreEqual(expected.Inventories.First().CreatedOn.ToString("G"), result.Inventories.First().CreatedOn.ToString("G"));
        }
Ejemplo n.º 2
0
        private void SetupPicklist()
        {
            var orderProductsIds  = Order.Model.OrderItems.Select(o => o.Product.Id).ToList();
            var addedProducts     = _allProducts.Where(p => orderProductsIds.Contains(p.Id)).OrderBy(o => o.Name);
            var availableProducts = _allProducts.Except(addedProducts).OrderBy(p => p.Name);

            AddedProducts.Clear();
            AvailableProducts.Clear();
            foreach (var addedProduct in addedProducts)
            {
                AddedProducts.Add(addedProduct);
            }
            foreach (var availableProduct in availableProducts)
            {
                AvailableProducts.Add(availableProduct);
            }
        }
Ejemplo n.º 3
0
        public void Put()
        {
            var name      = CreateTestProductName();
            var inventory = new Inventory
            {
                Name      = name,
                Quantity  = 900,
                CreatedOn = DateTime.UtcNow
            };

            AddedProducts.Add(name);

            _ = InventoryController.Put(name, inventory);
            var results = ExecuteQuery(
                Properties.Resources.GetByName.Replace(NAME_PARAMETER, name)).Tables[0];

            Assert.AreEqual(1, results.Rows.Count);
        }
Ejemplo n.º 4
0
        public void PutSameProductDifferentCriteria()
        {
            var counter       = 0;
            var quantity      = 100;
            var inventoryList = new List <Inventory>();
            var name          = CreateTestProductName();

            var postRecordCount = int.Parse(Properties.Resources.PostRecordCount);
            var negative        = postRecordCount * -1;
            var createdOn       = DateTime.UtcNow.AddDays(negative);

            AddedProducts.Add(name);

            do
            {
                quantity += counter;
                inventoryList.Add(new Inventory
                {
                    Name      = name,
                    Quantity  = quantity,
                    CreatedOn = createdOn.AddDays(counter)
                });

                counter++;
            } while (counter < postRecordCount);

            foreach (var inventoryItem in inventoryList)
            {
                _ = InventoryController.Put(name, inventoryItem);
            }

            var inventory = JsonSerializer.Deserialize <Inventory>(GetJsonFromResultTable(ExecuteQuery(
                                                                                              Properties.Resources.GetByName.Replace(NAME_PARAMETER, name)).Tables[0]).TrimStart('[').TrimEnd(']'));

            //Check that the date is the original date
            Assert.AreEqual(createdOn.ToString("G"), inventory.CreatedOn.ToString("G"));

            //Check that the quantity is the last quantity
            Assert.AreEqual(quantity, inventory.Quantity);
        }
Ejemplo n.º 5
0
        private void OnAddProductExecute()
        {
            var     productToAdd = SelectedAvailableProduct;
            decimal discount     = (100m - Convert.ToDecimal(productToAdd.ProductDiscount.Rate)) / 100m;

            Order.Model.OrderItems.Add(new OrderItem
            {
                OrderId    = Id,
                ProductId  = productToAdd.Id,
                UnitPrice  = productToAdd.Price,
                Quantity   = ProductQuantityToAdd,
                TotalPrice = ProductQuantityToAdd * productToAdd.Price * discount
            });

            SelectedAvailableProduct.StockBalance -= ProductQuantityToAdd;
            Order.TotalAmount +=
                ProductQuantityToAdd * productToAdd.Price * discount;

            AddedProducts.Add(productToAdd);
            AvailableProducts.Remove(productToAdd);
            HasChanges = _orderRepository.HasChanges();
            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();
        }
Ejemplo n.º 6
0
 public Task SaveProductAsync(Product product)
 {
     return(Task.Factory.StartNew(() => AddedProducts.Add(product)));
 }