public async void unit_test_updateWallet_checkContent() { //Arrange WalletEntity test = new WalletEntity() { Amount = 2000, card = new CardEntity() { CardId = 1, CardNumber = 20202020202020, CVVnumber = 200, ExpireMonth = 10, ExpireYear = 24 }, userID = "f8ac5f4b-d637-4bc4-acd2-cd940663f3ef" }; //Act var update = await _uut.updateWallet(test); var result = await _uut.getDetails("f8ac5f4b-d637-4bc4-acd2-cd940663f3ef"); //Assert Xunit.Assert.Equal(test.card.CardNumber, result.card.CardNumber); }
public void Save(WalletEntity wallet) { using (var session = _factory.OpenSession()) { session.Save(wallet); } }
public async Task GetAllWalletBalances() { string url = ApiPaths.WALLETS_BALANCES_PATH; var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.GET); Assert.True(response.Status == HttpStatusCode.OK); List <WalletBalanceDTO> parsedResponse = JsonUtils.DeserializeJson <List <WalletBalanceDTO> >(response.ResponseJson); AccountEntity accountEntity = await this.AccountRepository.TryGetAsync(Consumer.ClientInfo.Account.Id) as AccountEntity; foreach (WalletBalanceDTO wbDTO in parsedResponse) { WalletEntity walletEntity = this.AllWalletsFromDb.Where(w => w.Id == wbDTO.Id).FirstOrDefault(); if (walletEntity != null) { Assert.True(walletEntity.Name == wbDTO.Name); Assert.True(walletEntity.Type == wbDTO.Type); Assert.True(walletEntity.Description == wbDTO.Description); } if (accountEntity != null) { foreach (BalanceDTO balanceDTO in accountEntity.BalancesParsed) { var parsedBalance = wbDTO.Balances.Where(b => b.AssetId == balanceDTO.AssetId).FirstOrDefault(); if (parsedBalance != null) { Assert.True(balanceDTO.Balance == parsedBalance.Balance); Assert.True(balanceDTO.Reserved == parsedBalance.Reserved); } } } } }
public async Task <Unit> Handle(DepositCommand request, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var userId = request.UserId; var balance = request.Balance; var currency = request.Currency; var user = await GetUserAsync(userId, cancellationToken); if (user == null) { throw new UserNotFoundException(nameof(UserEntity), userId); } var wallet = await GetWalletAsync(userId, currency, cancellationToken); if (wallet == null) { var entity = new WalletEntity(balance, currency, user); await AddWalletAsync(entity, cancellationToken); return(Unit.Value); } wallet.AddBalance(balance); await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
private async Task AddWalletAsync(WalletEntity entity, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await _dbContext.Wallets.AddAsync(entity, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); }
public async Task <WalletDto> TryGetAsync(string blockchainType, string assetId, Guid clientId) { var partitionKey = WalletEntity.GetPartitionKey(blockchainType, assetId, clientId); var rowKey = WalletEntity.GetRowKey(clientId); var entity = await _walletsTable.GetDataAsync(partitionKey, rowKey); return(entity != null ? ConvertEntityToDto(entity) : null); }
private static WalletDto ConvertEntityToDto(WalletEntity entity) { return(new WalletDto { Address = entity.Address, AssetId = entity.AssetId, BlockchainType = entity.IntegrationLayerId, ClientId = entity.ClientId }); }
/// <inheritdoc /> protected override CommandResult Execute(ConvertCommandModel model) { WalletEntity correspongingWalletToWithdraw = Context.WalletEntities .FirstOrDefault(x => x.UserId == model.UserId && x.Currency == model.InitialCurrency); if (correspongingWalletToWithdraw == null) { return(new CommandResult("У пользователя отсутствует счет в указанной валюте")); } if (correspongingWalletToWithdraw.Balance < model.InitialAmount) { return(new CommandResult("На счету пользователя недостаточно средств")); } var exchangeRatesQueryResult = ExchangeRatesQuery.Run(null); if (!exchangeRatesQueryResult.IsSuccessful) { return(new CommandResult(exchangeRatesQueryResult.ErrorMessage)); } var exchangeRates = exchangeRatesQueryResult.Data; var initialRate = exchangeRates.Rates.FirstOrDefault(r => r.Item1 == model.InitialCurrency); var targetRate = exchangeRates.Rates.FirstOrDefault(r => r.Item1 == model.TargetCurrency); if (targetRate == null || initialRate == null) { return(new CommandResult("Не найден курс перевода в указанную валюту")); } decimal convertedAmount = model.InitialAmount / initialRate.Item2 * targetRate.Item2; var correspongingDepositWallet = Context.WalletEntities .FirstOrDefault(x => x.UserId == model.UserId && x.Currency == model.TargetCurrency); if (correspongingDepositWallet == null) { correspongingDepositWallet = new WalletEntity { UserId = model.UserId, Currency = model.TargetCurrency, Balance = 0, }; } correspongingWalletToWithdraw.Balance -= model.InitialAmount; correspongingDepositWallet.Balance += convertedAmount; Context.WalletEntities.Update(correspongingWalletToWithdraw); Context.WalletEntities.Update(correspongingDepositWallet); Context.SaveChanges(); return(new CommandResult()); }
public async Task <IActionResult> addMoney([FromBody] WalletEntity toAdd) { int wait = await _wallet.setAmount(User.Identity.Name, toAdd.Amount); if (wait > 0) { return(Ok()); } return(BadRequest()); }
public void CreateWallet_UserDoesExist_ThrowsUserAlreadyExistsException() { var user = new WalletEntity() { UserId = "9fefa208-5c52-4435-a3ca-70d1e9cee692" }; _walletQueryService.GetWallet(Arg.Any <string>()).Returns(user); Assert.Throws <UserAlreadyExistsException>(() => _sut.CreateWallet("9fefa208-5c52-4435-a3ca-70d1e9cee692")); }
public async Task DeleteWallet() { string url = ApiPaths.WALLETS_BASE_PATH + "/" + this.TestWalletDelete.Id; var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.DELETE); Assert.True(response.Status == HttpStatusCode.OK); WalletEntity entity = await this.WalletRepository.TryGetAsync(this.TestWalletDelete.Id) as WalletEntity; Assert.True(entity.State == "deleted"); }
public void Buy_CashIsLessThanTotalPrice_ThrowsInsufficientAvailableFundsException() { var wallet = new WalletEntity() { Cash = 100.00M }; _walletQueryService.GetWallet(Arg.Any <string>()).Returns(wallet); Assert.Throws <InsufficientAvailableFundsException>(() => _sut.Buy("9fefa208-5c52-4435-a3ca-70d1e9cee692", "V", 101.00M, 1)); }
public async Task <IActionResult> UpdateWallet([FromBody] WalletEntity wallet) { wallet.userID = User.Identity.Name; int wait = await _wallet.updateWallet(wallet); if (wait > 0) { return(Ok()); } return(BadRequest()); }
public void CreateWallet_UserDoesNotExist_ReturnsUserId() { WalletEntity user = null; _walletQueryService.GetWallet(Arg.Any <string>()).Returns(user); _walletQueryService.Save(Arg.Any <WalletEntity>()); var result = _sut.CreateWallet("9fefa208-5c52-4435-a3ca-70d1e9cee692"); Assert.That(result, Is.EqualTo("9fefa208-5c52-4435-a3ca-70d1e9cee692")); }
public void Sell_WhenCalled_ReturnsWallet() { var wallet = new WalletEntity() { Cash = 100.00M }; _walletQueryService.GetWallet(Arg.Any <string>()).Returns(wallet); var result = _sut.Sell("9fefa208-5c52-4435-a3ca-70d1e9cee692", "V", 10.00M, 1); Assert.That(result.Cash, Is.EqualTo(100.00M)); }
public async Task CreateWallet() { WalletDTO createdWallet = await this.CreateTestWallet(); Assert.NotNull(createdWallet); WalletEntity entity = await this.WalletRepository.TryGetAsync(createdWallet.Id) as WalletEntity; Assert.NotNull(entity); entity.ShouldBeEquivalentTo(createdWallet, o => o .ExcludingMissingMembers()); }
public void Buy_CashIsGreaterThanTotalPrice_ReturnsWallet() { var wallet = new WalletEntity() { Cash = 100.00M }; _walletQueryService.GetWallet(Arg.Any <string>()).Returns(wallet); var result = _sut.Buy("9fefa208-5c52-4435-a3ca-70d1e9cee692", "V", 10.00M, 1); Assert.That(result.Cash, Is.EqualTo(100.00M)); }
private WalletEntity GenerateWallet(WalletFactory _walletFactory, Guid accountId, int idValue, string cryptoCode) { var wallet = new WalletEntity { AccountId = accountId, CryptoId = idValue, Balance = 0M, FrozenBalance = 0M, Address = null, CryptoCode = cryptoCode }; return(_walletFactory.Insert(wallet)); }
public async Task SaveWalletAsync( string address, byte[] publicKey) { using (var context = _contextFactory.CreateDataContext()) { var entity = new WalletEntity { Address = address, PublicKey = publicKey }; context.Wallets.Add(entity); await context.SaveChangesAsync(); } }
public async Task DeleteIfExistsAsync(string blockchainType, string assetId, Guid clientId) { var partitionKey = WalletEntity.GetPartitionKey(blockchainType, assetId, clientId); var rowKey = WalletEntity.GetRowKey(clientId); var wallet = await _walletsTable.GetDataAsync(partitionKey, rowKey); if (wallet != null) { var(indexPartitionKey, indexRowKey) = GetAddressIndexKeys(wallet); var(clientIndexPartitionKey, clientIndexRowKey) = GetClientIndexKeys(wallet); await _walletsTable.DeleteIfExistAsync(wallet.PartitionKey, wallet.RowKey); await _addressIndexTable.DeleteIfExistAsync(indexPartitionKey, indexRowKey); await _clientIndexTable.DeleteIfExistAsync(clientIndexPartitionKey, clientIndexRowKey); } }
public async Task GetHoldings_TransactionCountIsZeroOrLess_ReturnsHoldings() { var transactions = new List <TransactionEntity>(); var cash = new WalletEntity() { Cash = 100M }; _transactionQueryService.GetTransactions(Arg.Any <string>()).Returns(transactions); _walletQueryService.GetWallet(Arg.Any <string>()).Returns(cash); var result = await _sut.GetHoldings("9fefa208-5c52-4435-a3ca-70d1e9cee692"); Assert.That(result.Holdings, Is.Null); Assert.That(result.Cash, Is.EqualTo(100M)); Assert.That(result.Value, Is.EqualTo(0M)); }
public string CreateWallet(string userId) { var wallet = new WalletEntity() { UserId = userId, Cash = 100000.00M }; var user = _walletQueryService.GetWallet(userId); if (user == null) { _walletQueryService.Save(wallet); return(userId); } else { throw new UserAlreadyExistsException($"Error in creating wallet"); } }
public async void Create() { //Arrange var context = new Mock <HttpContext>(); var identity = new GenericIdentity("test"); identity.AddClaim(new Claim(ClaimTypes.Name, "f8ac5f4b-d637-4bc4-acd2-cd940663f3ef")); var principal = new GenericPrincipal(identity, new[] { "User" }); context.Setup(s => s.User).Returns(principal); _uut.ControllerContext.HttpContext = context.Object; WalletEntity test = new WalletEntity() { Amount = 2000 }; //Act var result = await _uut.CreateWallet(test); //Assert Xunit.Assert.IsType <OkResult>(result); }
/// <inheritdoc /> protected override CommandResult Execute(DepositCommandModel model) { var correspongingWallet = Context.WalletEntities .FirstOrDefault(x => x.UserId == model.UserId && x.Currency == model.Currency); if (correspongingWallet == null) { correspongingWallet = new WalletEntity { UserId = model.UserId, Currency = model.Currency, Balance = 0, }; } correspongingWallet.Balance += model.Amount; Context.WalletEntities.Update(correspongingWallet); Context.SaveChanges(); return(new CommandResult()); }
public async void unit_test_addWallet() { //Arrange WalletEntity test = new WalletEntity() { Amount = 100, card = new CardEntity() { CardNumber = 10000, CVVnumber = 321, ExpireMonth = 02, ExpireYear = 32 }, userID = "test" }; //Act _uut.addWallet(test); var result = await _uut.getAmount("test"); //Assert Xunit.Assert.Equal(test.Amount, result); }
public async void unit_test_updateWallet(string name, int amount) { //Arrange WalletEntity test = new WalletEntity() { Amount = amount, card = new CardEntity() { CardId = 1, CardNumber = 20202020202020, CVVnumber = 200, ExpireMonth = 10, ExpireYear = 24 }, userID = name }; //Act var result = await _uut.updateWallet(test); //Assert //forventer 2 da det er 2 DbSets der skal arbejds på. Xunit.Assert.Equal(2, result); }
public async Task AddAsync(string blockchainType, string assetId, Guid clientId, string address) { var partitionKey = WalletEntity.GetPartitionKey(blockchainType, assetId, clientId); var rowKey = WalletEntity.GetRowKey(clientId); // Address index var(indexPartitionKey, indexRowKey) = GetAddressIndexKeys(blockchainType, address); var(clientIndexPartitionKey, clientIndexRowKey) = GetClientIndexKeys(blockchainType, assetId, clientId); await _addressIndexTable.InsertOrReplaceAsync(new AzureIndex( indexPartitionKey, indexRowKey, partitionKey, rowKey )); await _clientIndexTable.InsertOrReplaceAsync(new AzureIndex( clientIndexPartitionKey, clientIndexRowKey, partitionKey, rowKey )); // Wallet entity await _walletsTable.InsertOrReplaceAsync(new WalletEntity { PartitionKey = partitionKey, RowKey = rowKey, Address = address, AssetId = assetId, ClientId = clientId, IntegrationLayerId = blockchainType }); }
private static (string PartitionKey, string RowKey) GetClientIndexKeys(WalletEntity wallet) { return(GetClientIndexKeys(wallet.IntegrationLayerId, wallet.AssetId, wallet.ClientId)); }
private static (string PartitionKey, string RowKey) GetAddressIndexKeys(WalletEntity wallet) { return(GetAddressIndexKeys(wallet.IntegrationLayerId, wallet.Address)); }
public async Task GetHoldings_TransactionCountIsGreaterThanZero_ReturnsHoldings() { var transactions = new List <TransactionEntity>(); transactions.Add(new TransactionEntity() { Price = 1.00M, Quantity = 1, Stock = "v" }); transactions.Add(new TransactionEntity() { Price = 5.00M, Quantity = 1, Stock = "tsla" }); transactions.Add(new TransactionEntity() { Price = 10.00M, Quantity = 1, Stock = "goog" }); var latestPrice = new Dictionary <string, LatestPriceModel>(); latestPrice.Add("v", new LatestPriceModel() { Quote = new QuoteModel() { LatestPrice = 10.00M } }); latestPrice.Add("tsla", new LatestPriceModel() { Quote = new QuoteModel() { LatestPrice = 50.00M } }); latestPrice.Add("goog", new LatestPriceModel() { Quote = new QuoteModel() { LatestPrice = 100.00M } }); var processedHoldings = new List <Holding>(); processedHoldings.Add(new Holding() { Stock = "v", LatestPrice = 10.00M, Quantity = 1 }); processedHoldings.Add(new Holding() { Stock = "tsla", LatestPrice = 50.00M, Quantity = 1 }); processedHoldings.Add(new Holding() { Stock = "goog", LatestPrice = 100.00M, Quantity = 1 }); var holdingsValue = 160.00M; var cash = new WalletEntity() { Cash = 100.00M }; _transactionQueryService.GetTransactions(Arg.Any <string>()).Returns(transactions); _stockService.LatestPrice(Arg.Any <List <TransactionEntity> >()).Returns(latestPrice); _holdingsProcessor.HoldingsCombiner(Arg.Any <List <TransactionEntity> >(), Arg.Any <Dictionary <string, LatestPriceModel> >()).Returns(processedHoldings); _holdingsProcessor.HoldingsValue(Arg.Any <List <Holding> >()).Returns(holdingsValue); _walletQueryService.GetWallet(Arg.Any <string>()).Returns(cash); var result = await _sut.GetHoldings("9fefa208-5c52-4435-a3ca-70d1e9cee692"); Assert.That(result.Holdings.Count, Is.EqualTo(3)); Assert.That(result.Cash, Is.EqualTo(100.00M)); Assert.That(result.Value, Is.EqualTo(160.00M)); }