Example #1
0
        public void Initialize()
        {
            this.clientTableRepository             = Substitute.For <IClientTableRepository>();
            this.stockTableRepository              = Substitute.For <IStockTableRepository>();
            this.stockOfClientsTableRepository     = Substitute.For <IStockOfClientsTableRepository>();
            this.transactionHistoryTableRepository = Substitute.For <ITransactionHistoryTableRepository>();
            this.editClientStockService            = new EditCleintStockService(this.stockOfClientsTableRepository);


            clientTableRepository.Get(5).Returns(new ClientEntity()
            {
                ID             = 5,
                Name           = "Serj",
                Surname        = "Tankian",
                PhoneNumber    = "+7228133705",
                AccountBalance = 100,
            });
            clientTableRepository.Get(32).Returns(new ClientEntity()
            {
                ID             = 32,
                Name           = "Chester",
                Surname        = "Bennington",
                PhoneNumber    = "+7228133705",
                AccountBalance = 50
            });

            stockTableRepository.Get(1).Returns(new StockEntity()
            {
                ID   = 1,
                Name = "Yandex",
                Type = "P",
                Cost = 10
            });

            stockOfClientsTableRepository.Get(2).Returns(new StockOfClientsEntity()
            {
                ID       = 2,
                ClientID = 32,
                StockID  = 1,
                Amount   = 5
            });

            stockTableRepository.GetCost(Arg.Is <int>(1)).Returns(10);
            stockOfClientsTableRepository.GetAmount(Arg.Is <int>(5),
                                                    Arg.Is <int>(1)).Returns(0);
            stockOfClientsTableRepository.GetAmount(Arg.Is <int>(32),
                                                    Arg.Is <int>(1)).Returns(10);
            clientTableRepository.GetBalance(Arg.Is <int>(5)).Returns(100);
            clientTableRepository.GetBalance(Arg.Is <int>(32)).Returns(50);
            stockTableRepository.GetType(Arg.Is <int>(1)).Returns("P");
        }
Example #2
0
        private void BuyPartOfTrasaction(TradeInfo tradeInfo)
        {
            decimal stockCost      = stockTableRepository.GetCost(tradeInfo.Stock_ID);
            int     customerStocks = stockClientTableRepository.GetAmount(tradeInfo.Customer_ID, tradeInfo.Stock_ID);

            decimal customerMoney = clientTableRepository.GetBalance(tradeInfo.Customer_ID);

            decimal transactionPrice   = stockCost * tradeInfo.Amount;
            decimal newCustomerBalance = customerMoney - transactionPrice;

            int newCustomerStockAmount = customerStocks + tradeInfo.Amount;

            clientTableRepository.UpdateBalance(tradeInfo.Customer_ID, newCustomerBalance);

            editCleintStockService.Edit(new EditStockOfClientInfo
            {
                Client_ID      = tradeInfo.Customer_ID,
                Stock_ID       = tradeInfo.Stock_ID,
                AmountOfStocks = newCustomerStockAmount
            });
            clientTableRepository.SaveChanges();
        }
Example #3
0
        public string GetStateOfClient(int clientId)
        {
            string result = string.Empty;

            if (clientTableRepository.ContainsById(clientId))
            {
                decimal clientBalance = clientTableRepository.GetBalance(clientId);
                if (clientBalance > 0)
                {
                    result = $"This client belongs to Green zone.";
                }
                else if (clientBalance == 0)
                {
                    result = $"This client belongs to Orange zone.";
                }
                else if (clientBalance < 0)
                {
                    result = $"This client belongs to Black zone.";
                }
                return(result);
            }
            result = "Such client doesn't exist in DataBase.";
            return(result);
        }