public void RegisterNewTypeOfStock(StockPriceInfo args) { if (CheckIfStockPriseConteinStockOfClientByTypeOfStock(args.TypeOfStock)) { throw new ArgumentException("StockPrice Table already contain this type of stock"); } var entityToAdd = new StockPriceEntity() { TypeOfStock = args.TypeOfStock.ToUpper(), PriceOfStock = args.PriceOfStock }; stockPriceTableRepository.Add(entityToAdd); stockPriceTableRepository.SaveChanges(); logger.Info($"Stock {entityToAdd.Id} of type {entityToAdd.TypeOfStock} with price {entityToAdd.PriceOfStock} has been created"); }
public void ShouldNotRegisterNewTypeOfStockIfItExists() { //Arrange ClientsService clientsService = new ClientsService(clientsTableRepository, accountTableRepository, stockPriceTableRepository, stockOfClientTableRepository, logger); StockPriceInfo args = new StockPriceInfo() { TypeOfStock = "A", PriceOfStock = 10 }; StockPriceEntity stockPrice = new StockPriceEntity(); stockPriceTableRepository.GetStockPriceEntityByStockType(Arg.Is <string>(w => w == args.TypeOfStock.ToUpper())).Returns(stockPrice); //Act clientsService.RegisterNewTypeOfStock(args); //Assert stockPriceTableRepository.Received(1).Add(Arg.Is <StockPriceEntity>( w => w.TypeOfStock == args.TypeOfStock && w.PriceOfStock == args.PriceOfStock)); stockPriceTableRepository.Received(1).SaveChanges(); }
private void Registration() { ClientRegistrationInfo clientRegistrationInfo = new ClientRegistrationInfo(); AccountRegistrationInfo accountRegistrationInfo = new AccountRegistrationInfo(); StockOfClientInfo stockOfClientInfo = new StockOfClientInfo(); clientRegistrationInfo.Name = AskUser(KeysForPhrases.RegName); clientRegistrationInfo.Surname = AskUser(KeysForPhrases.RegSurname); clientRegistrationInfo.PhoneNumber = AskUser(KeysForPhrases.RegPhone, true); accountRegistrationInfo.ClientId = clientsService.RegisterNewClient(clientRegistrationInfo); accountRegistrationInfo.Balance = Convert.ToDecimal(AskUser(KeysForPhrases.RegBalance, true)); stockOfClientInfo.ClientsAccountId = clientsService.CreateNewAccountForNewClient(accountRegistrationInfo); if (Convert.ToInt32(AskUser(KeysForPhrases.RegStock, true)) == 1) { stockOfClientInfo.TypeOfStocks = AskUser(KeysForPhrases.RegStockType); stockOfClientInfo.quantityOfStocks = Convert.ToInt32(AskUser(KeysForPhrases.RegStockQuant, true)); if (!clientsService.CheckIfStockPriseConteinStockOfClientByTypeOfStock(stockOfClientInfo.TypeOfStocks)) { StockPriceInfo stockPriceInfo = new StockPriceInfo() { TypeOfStock = stockOfClientInfo.TypeOfStocks }; stockPriceInfo.PriceOfStock = Convert.ToDecimal(AskUser(KeysForPhrases.RegStockPrice, true)); clientsService.RegisterNewTypeOfStock(stockPriceInfo); } clientsService.RegisterStockForNewClient(stockOfClientInfo); } }