Ejemplo n.º 1
0
        public void ShouldNotRegisterNewStockIfItExists()
        {
            // Arrange
            var          stockTableRepository = Substitute.For <ITableRepository <Stock> >();
            StockService stockService         = new StockService(stockTableRepository);
            StockInfo    stockInfo            = new StockInfo
            {
                IssuerId    = 1,
                ShareType   = (StockInfo.StockType)StockType.Common,
                StockPrefix = "KORS"
            };

            // Act
            stockService.AddStock(stockInfo);

            stockTableRepository.ContainsDTO(Arg.Is <Stock>(
                                                 w => w.IssuerID == stockInfo.IssuerId &&
                                                 w.StockType == (StockType)stockInfo.ShareType &&
                                                 w.StockPrefix == stockInfo.StockPrefix)).Returns(true);

            stockService.AddStock(stockInfo);
        }
Ejemplo n.º 2
0
            public void Should_add_the_specified_amount_to_QunatityInStock()
            {
                using var context = new ProductContext(_builder.Options);

                var repository = new ProductRepository(context);

                repository.Insert(new("Product 1", 1));

                var sut             = new StockService(repository);
                var quantityInStock = sut.AddStock(productId: 1, amount: 2);

                Assert.Equal(3, quantityInStock);
                var actual = repository.FindById(1);

                Assert.Equal(3, actual.QuantityInStock);
            }
 public ActionResult _AddStockForModel(StockEditVM mStockEditVm)
 {
     if (ModelState.IsValid && TryValidateModel(mStockEditVm))
     {
         var stk = new Stock {
             History = new List <StockHistory>()
         };
         if (TryUpdateModel(stk))
         {
             if (ExecuteRepositoryAction(() => { _svc.AddStock(stk); _svc.CommitChanges(); }))
             {
                 return(ReturnJsonFormSuccess());
             }
         }
     }
     return(PartialView("_EditStockForModel", mStockEditVm));
 }
Ejemplo n.º 4
0
        public void ShouldAddNewStock()
        {
            //Arrange
            var          stockTableRepository = Substitute.For <ITableRepository <Stock> >();
            StockService stockService         = new StockService(stockTableRepository);
            StockInfo    stockInfo            = new StockInfo
            {
                IssuerId    = 1,
                ShareType   = (StockInfo.StockType)StockType.Common,
                StockPrefix = "KORS"
            };

            //Act
            stockService.AddStock(stockInfo);
            //Assert
            stockTableRepository.Received(1).Add(Arg.Is <Stock>(
                                                     w => w.IssuerID == stockInfo.IssuerId &&
                                                     w.StockType == (StockType)stockInfo.ShareType &&
                                                     w.StockPrefix == stockInfo.StockPrefix
                                                     ));
        }
Ejemplo n.º 5
0
        public ActionResult _AddNewStock(StockEditVM mStockEditVm)
        {
            if (ModelState.IsValid)
            {
                var stk = new Stock();
                if (TryUpdateModel(stk))
                {
                    if (ExecuteRepositoryAction(() => { _svc.AddStock(stk); _svc.CommitChanges(); }))
                    {
                        return(ReturnJsonFormSuccess());
                    }
                }
            }
            mStockEditVm.ProductLifeCycles = _svc.GetProductLifeCycles().Where(m => m.NotAttachedStatus).ToList();
            if (mStockEditVm.ModelId != 0)
            {
                var mdl = _svc.GetModel(mStockEditVm.ModelId);
                mStockEditVm.ManufacturerAndModel = mdl.Manufacturer.Name + " " + mdl.ModelCode;
            }

            return(PartialView("_Edit", mStockEditVm));
        }
Ejemplo n.º 6
0
        private void StockMenu()
        {
            ShowStockMenu();
            Console.WriteLine("Enter an option: ");
            string option = Console.ReadLine().Trim();

            switch (option)
            {
            case "0":
                break;

            case "1":
                Console.Write("Enter Stock by Id: ");
                int id = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter Stock name: ");
                string name = Console.ReadLine();

                Console.Write("Enter Stock cost price: ");
                double costPrice = Convert.ToDouble(Console.ReadLine());

                Console.Write("Enter Stock selling price: ");
                double sellingPrice = Convert.ToDouble(Console.ReadLine());

                Console.Write("Enter Stock SKU: ");
                string sKU = Console.ReadLine();

                Console.Write("Enter Stock quantity: ");
                int quantity = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter Stock variation: ");
                string variation = Console.ReadLine();

                ReshuffleMenu();
                Console.WriteLine("Choose Category. ");
                int category_Id = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("");

                List <Stock> Stocks = stockService.ListAllStocks();
                foreach (var stock in Stocks)
                {
                    stock.Category_Id = category_Id;
                }

                stockService.AddStock(id, name, costPrice, sellingPrice, sKU, quantity, variation, category_Id);
                StockRepository.WriteStockToFile();
                break;

            case "2":
                PrintAllStockList();
                break;

            case "4":
                DeleteStock();
                break;

            case "5":

                break;

            default:
                break;
            }
        }
Ejemplo n.º 7
0
 public ActionResult Create(STOCKS Stock)
 {
     cs.AddStock(Stock);
     return(RedirectToAction("index"));
 }