예제 #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");
        }
예제 #2
0
        private void AddEntryToTransactionHistoryTable(TradeInfo tradeInfo)
        {
            decimal stockCost        = stockTableRepository.GetCost(tradeInfo.Stock_ID);
            decimal transactionPrice = stockCost * tradeInfo.Amount;
            string  stockType        = stockTableRepository.GetType(tradeInfo.Stock_ID);

            HistoryEntity historyEntity = new HistoryEntity()
            {
                CustomerID      = tradeInfo.Customer_ID,
                StockAmount     = tradeInfo.Amount,
                StockID         = tradeInfo.Stock_ID,
                SellerID        = tradeInfo.Seller_ID,
                TransactionTime = DateTime.Now,
                TransactionCost = transactionPrice,
                StockType       = stockType
            };

            this.transactionHistoryTableRepository.Add(historyEntity);
            transactionHistoryTableRepository.SaveChanges();
        }