public SaleService( ITraderStockTableRepository traderStockTableRepository, ITraderTableRepository traderTableRepository, IHistoryTableRepository historyTableRepository) { this.traderTableRepository = traderTableRepository; this.traderStockTableRepository = traderStockTableRepository; this.historyTableRepository = historyTableRepository; }
public TraderStocksService(ITraderStockTableRepository traderStockTableRepository) { this.traderStockTableRepository = traderStockTableRepository; }
public void Initialize() { historyTableRepository = Substitute.For <IHistoryTableRepository>(); traderStockTableRepository = Substitute.For <ITraderStockTableRepository>(); traderTableRepository = Substitute.For <ITraderTableRepository>(); traderTableRepository.GetById(5).Returns(new TraderEntityDB() { Id = 5, Name = "Muhamed", Surname = "Ali", Balance = 123123.0M }); traderTableRepository.GetById(40).Returns(new TraderEntityDB() { Id = 40, Name = "Brad", Surname = "Pitt", Balance = 1243123.0M }); stockTableRepository = Substitute.For <IStockTableRepository>(); stockTableRepository.GetById(7).Returns(new StockEntityDB() { Id = 7, Name = "Pepsi", PricePerItem = 123.0M }); stockTableRepository.GetById(20).Returns(new StockEntityDB() { Id = 20, Name = "Shmepsi", PricePerItem = 33.0M }); this.traderStocksTable = new List <StockToTraderEntityDB>() { new StockToTraderEntityDB() { Id = 1, TraderId = 5, StockId = 7, StockCount = 4, PricePerItem = 123.0M }, new StockToTraderEntityDB() { Id = 2, TraderId = 5, StockId = 20, StockCount = 2, PricePerItem = 33.0M }, new StockToTraderEntityDB() { Id = 3, TraderId = 40, StockId = 7, StockCount = 2, PricePerItem = 33.0M } }; traderStockTableRepository.GetStocksFromSeller(Arg.Any <BuyArguments>()) .Returns((callInfo) => { var buyArguments = callInfo.Arg <BuyArguments>(); var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.SellerID && w.StockId == buyArguments.StockID); return(retVal); }); traderStockTableRepository.ContainsSeller(Arg.Any <BuyArguments>()) .Returns((callInfo) => { var buyArguments = callInfo.Arg <BuyArguments>(); try { var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.SellerID && w.StockId == buyArguments.StockID); } catch (Exception) { return(false); } return(true); }); traderStockTableRepository.ContainsCustomer(Arg.Any <BuyArguments>()) .Returns((callInfo) => { var buyArguments = callInfo.Arg <BuyArguments>(); try { var retVal = this.traderStocksTable.First(w => w.TraderId == buyArguments.CustomerID && w.StockId == buyArguments.StockID); } catch (Exception) { return(false); } return(true); }); traderStockTableRepository.Contains(Arg.Any <StockToTraderEntityDB>()) .Returns((callInfo) => { var stockToTrader = callInfo.Arg <StockToTraderEntityDB>(); try { var retVal = this.traderStocksTable.First(w => w.TraderId == stockToTrader.TraderId && w.StockId == stockToTrader.StockId); } catch (Exception) { return(false); } return(true); }); traderTableRepository.ContainsById(5).Returns(true); traderTableRepository.ContainsById(40).Returns(true); saleHandler = new SaleService(this.traderStockTableRepository, this.traderTableRepository, this.historyTableRepository); }
public void Initialize() { traderStocksTableRepository = Substitute.For <ITraderStockTableRepository>(); traderStockService = new TraderStocksService(this.traderStocksTableRepository); }