public async Task CreateTransfer_ReturnsNewTransfer() { string walletsJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"Wallets.json"); var wallets = JsonConvert.DeserializeObject <List <Wallet> >(walletsJson).Where(w => w.User.Id == TESTING_USER_ID); const string sourceCurrencyAbbreviation = "USD"; const string targetCurrencyAbbreviation = "BYN"; const double shareAmount = 1; const float exchangeRate = 2.61f; var sourceWallet = wallets.First(s => s.Currency.Abbreviation == sourceCurrencyAbbreviation); var targetWallet = wallets.First(s => s.Currency.Abbreviation == targetCurrencyAbbreviation); double initSourceBalance = sourceWallet.Balance; double initTargetBalance = targetWallet.Balance; var transfer = new Transfer { SourceWalletId = sourceWallet.Id, TargetWalletId = targetWallet.Id, Amount = shareAmount, ExchangeRate = exchangeRate }; WalletRepository .Setup(w => w.GetByKey(sourceWallet.Id)) .Returns(sourceWallet); WalletRepository .Setup(w => w.GetByKey(targetWallet.Id)) .Returns(targetWallet); WalletRepository.Setup(w => w.Update(sourceWallet)).ReturnsAsync(sourceWallet); WalletRepository.Setup(w => w.Update(targetWallet)).ReturnsAsync(targetWallet); var resultTransfer = await WalletService.CreateTransfer(transfer); Assert.NotNull(resultTransfer); Assert.NotNull(resultTransfer.SourceWallet); Assert.NotNull(resultTransfer.TargetWallet); Assert.Equal(sourceWallet.Id, resultTransfer.SourceWallet.Id); Assert.Equal(targetWallet.Id, resultTransfer.TargetWallet.Id); Assert.Equal(shareAmount, resultTransfer.Amount); Assert.Equal(exchangeRate, resultTransfer.ExchangeRate); Assert.Equal(initSourceBalance - shareAmount, resultTransfer.SourceWallet.Balance); Assert.Equal(initTargetBalance + shareAmount * exchangeRate, resultTransfer.TargetWallet.Balance); }
public async Task CreateTransfer_ThrowsErrorAboutMoney() { string walletsJson = File.ReadAllText(TestConfiguration.MockDataFolderPath + @"Wallets.json"); var wallets = JsonConvert.DeserializeObject <List <Wallet> >(walletsJson).Where(w => w.User.Id == TESTING_USER_ID); const string sourceCurrencyAbbreviation = "USD"; const string targetCurrencyAbbreviation = "BYN"; const double shareAmount = 10000000; const float exchangeRate = 2.61f; var sourceWallet = wallets.First(s => s.Currency.Abbreviation == sourceCurrencyAbbreviation); var targetWallet = wallets.First(s => s.Currency.Abbreviation == targetCurrencyAbbreviation); var transfer = new Transfer { SourceWalletId = sourceWallet.Id, TargetWalletId = targetWallet.Id, Amount = shareAmount, ExchangeRate = exchangeRate }; WalletRepository .Setup(w => w.GetByKey(sourceWallet.Id)) .Returns(sourceWallet); WalletRepository .Setup(w => w.GetByKey(targetWallet.Id)) .Returns(targetWallet); WalletRepository.Setup(w => w.Update(sourceWallet)).ReturnsAsync(sourceWallet); WalletRepository.Setup(w => w.Update(targetWallet)).ReturnsAsync(targetWallet); await Assert.ThrowsAsync <CashSchedulerException>(async() => { await WalletService.CreateTransfer(transfer); }); }