public void ShouldOpenAccountForNewClient() { //Arrange ClientsService clientsService = new ClientsService(clientsTableRepository, accountTableRepository, stockPriceTableRepository, stockOfClientTableRepository, logger); ClientRegistrationInfo args = new ClientRegistrationInfo(); args.Name = "John"; args.Surname = "Jaymson"; args.PhoneNumber = "+78908901234"; AccountRegistrationInfo argsForAcc = new AccountRegistrationInfo(); argsForAcc.Balance = 10m; argsForAcc.Stocks = new List <StockOfClientEntity>(); argsForAcc.Zone = "white"; //Act argsForAcc.ClientId = clientsService.RegisterNewClient(args); clientsService.CreateNewAccountForNewClient(argsForAcc); //Assert accountTableRepository.Received(1).Add(Arg.Is <AccountEntity>( w => w.Balance == argsForAcc.Balance && w.ClientId == argsForAcc.ClientId && w.Stocks == argsForAcc.Stocks && w.Zone == argsForAcc.Zone)); accountTableRepository.Received(1).SaveChanges(); }
public void ShouldMakeATrade() { //Arrange TradingService tradingService = new TradingService(accountTableRepository, stockPriceTableRepository, historyTableRepository, stockOfClientTableRepository, logger); TransactionInfo transactionInfo = new TransactionInfo(); transactionInfo.BuyerId = 1; transactionInfo.SellerId = 2; transactionInfo.TypeOfStock = "AAA"; transactionInfo.QuantityOfStocks = 20; StockPriceEntity stockPriceEntity = new StockPriceEntity() { TypeOfStock = transactionInfo.TypeOfStock, PriceOfStock = 4 }; AccountEntity buyer = new AccountEntity() { AccountId = 11, ClientId = 1, Balance = 100, Stocks = new List <StockOfClientEntity>() }; AccountEntity seller = new AccountEntity() { AccountId = 22, ClientId = 2, Balance = 100, Stocks = new List <StockOfClientEntity>() }; StockOfClientEntity stockForSell = new StockOfClientEntity() { Id = 222, TypeOfStocks = "AAA", AccountId = 22, AccountForStock = seller, quantityOfStocks = 30 }; stockPriceTableRepository.GetStockPriceEntityByStockType(Arg.Is <string>( w => w == transactionInfo.TypeOfStock)).Returns(stockPriceEntity); accountTableRepository.GetAccountByClientId(Arg.Is <int>( w => w == transactionInfo.BuyerId)).Returns(buyer); accountTableRepository.GetAccountByClientId(Arg.Is <int>( w => w == transactionInfo.SellerId)).Returns(seller); stockOfClientTableRepository.GetStockOfClientEntityByAccountIdAndType(Arg.Is <int>( w => w == seller.AccountId), Arg.Is <string>( w => w == transactionInfo.TypeOfStock)).Returns(stockForSell); stockOfClientTableRepository.GetStockOfClientEntityByAccountIdAndType(Arg.Is <int>( w => w == buyer.AccountId), Arg.Is <string>( w => w == transactionInfo.TypeOfStock)).Returns(stockForSell); //Act seller.Stocks.Add(stockForSell); tradingService.MakeATrade(transactionInfo); //Assert stockOfClientTableRepository.Received(1).Add(Arg.Is <StockOfClientEntity>( w => w.AccountForStock == buyer && w.quantityOfStocks == transactionInfo.QuantityOfStocks && w.TypeOfStocks == transactionInfo.TypeOfStock) ); stockOfClientTableRepository.Received(2).SaveChanges(); accountTableRepository.Received(1).Change(Arg.Is <AccountEntity>(buyer)); accountTableRepository.Received(1).Change(Arg.Is <AccountEntity>(seller)); accountTableRepository.Received(2).SaveChanges(); historyTableRepository.Received(1).Add(Arg.Is <HistoryEntity> (w => w.BuyerId == transactionInfo.BuyerId && w.SellerId == transactionInfo.SellerId && w.QuantityOfStocks == transactionInfo.QuantityOfStocks && w.TypeOfStock == transactionInfo.TypeOfStock && w.FullPrice == 80 )); historyTableRepository.Received(1).SaveChanges(); }