public async Task SucesGetAllCards() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "SucesGetAllCards") .Options; string userId = "userId"; var newBankCard = new BankCard() { UserId = "userId", }; DateTime expiration = new DateTime(2019, 11, 10); using (var context = new CasinoContext(contextOptions)) { var cardService = new CardService(context); await context.BankCards.AddAsync(newBankCard); await context.SaveChangesAsync(); var card = await cardService.GetAllCards(userId); Assert.AreEqual(1, card.Count()); } }
public async Task ThrowArgumentNullException_WhenWithdrawCardDateIsExpired() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ThrowArgumentNullException_WhenWithdrawCardDateIsExpired") .Options; string cardNumber = "0000000000000000"; double amount = 100.2; var newBankCard = new BankCard() { Id = cardNumber, Expiration = new DateTime(2017, 2, 2) }; using (var context = new CasinoContext(contextOptions)) { var cardService = new CardService(context); await context.BankCards.AddAsync(newBankCard); await context.SaveChangesAsync(); await Assert.ThrowsExceptionAsync <CardExpirationException>( () => cardService.Withdraw(cardNumber, amount) ); } }
public async Task SucesRemoveingCard() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "SucesGetAllCard") .Options; string cardNumber = "0000000000000000"; var newBankCard = new BankCard() { CardNumber = cardNumber }; DateTime expiration = new DateTime(2019, 11, 10); using (var context = new CasinoContext(contextOptions)) { var cardService = new CardService(context); await context.BankCards.AddAsync(newBankCard); await context.SaveChangesAsync(); var card = await cardService.RemoveCard(cardNumber); Assert.IsInstanceOfType(card, typeof(BankCard)); Assert.IsTrue(card.CardNumber == cardNumber); Assert.IsTrue(card.IsDeleted == true); } }
public async Task ReturnResultOne() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ReturnZeroCount") .Options; var type = "Win"; var transactionType = new TransactionType() { Id = 1, Name = type }; var transaction = new Transaction() { TransactionType = transactionType }; using (var context = new CasinoContext(contextOptions)) { context.Transactions.Add(transaction); await context.SaveChangesAsync(); var adminService = new AdminDashboardService(context); var result = await adminService.GetTotaTransactionsByTypeCount(type); Assert.AreEqual(1, result); } }
public async Task WidthdrawSucessuly() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "WidthdrawSucessuly") .Options; string cardId = "0000000000000000"; double amount = 100.2; var newBankCard = new BankCard() { Id = cardId, Expiration = new DateTime(2019, 2, 2) }; using (var context = new CasinoContext(contextOptions)) { var cardService = new CardService(context); await context.BankCards.AddAsync(newBankCard); await context.SaveChangesAsync(); await cardService.Withdraw(cardId, amount); Assert.IsTrue(newBankCard.MoneyRetrieved == amount); } }
public async Task DepositSuccesfully() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "DepositSuccesfully") .Options; string cardNumber = "0000000000000000"; double amount = 100.2; var newBankCard = new BankCard() { Id = cardNumber, Expiration = new DateTime(2019, 2, 2) }; using (var context = new CasinoContext(contextOptions)) { var cardService = new CardService(context); await context.BankCards.AddAsync(newBankCard); await context.SaveChangesAsync(); await cardService.Deposit(cardNumber, amount); Assert.IsTrue(newBankCard.MoneyAdded == amount); } }
public async Task ReturnUserWhenCorrectParametersArePassed_AndUserIdIsInDb() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ReturnUserWhenCorrectParametersArePassed_AndUserIdIsInDb") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var userId = "user-id"; var transactionsData = new Transaction() { UserId = userId, TransactionType = new TransactionType() }; using (var context = new CasinoContext(contextOptions)) { var transactionService = new TransactionService(context, currencyServiceMock.Object); context.Transactions.Add(transactionsData); await context.SaveChangesAsync(); var result = await transactionService.GetUserTransactions(userId); Assert.AreEqual(1, result.Count()); Assert.IsInstanceOfType(result, typeof(IEnumerable <Transaction>)); } }
public async Task <Wallet> CreateWallet(string userId, int currencyId) { var wallet = await this.context.Wallets.FirstOrDefaultAsync(wa => wa.UserId == userId); var currency = await this.context.Currencies.FirstOrDefaultAsync(cu => cu.Id == currencyId); if (wallet != null) { throw new EntityAlreadyExistsException("The user already has wallet"); } ServiceValidator.ObjectIsNotEqualNull(currency); var newWallet = new Wallet() { Id = Guid.NewGuid().ToString(), UserId = userId, Currency = currency }; context.Wallets.Add(newWallet); await context.SaveChangesAsync(); return(newWallet); }
public async Task Add_Stake_WithCorrectAmountOfCurrency() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "Add_Stake_WithCorrectAmountOfCurrency") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var baseCurrency = "USD"; var currency = 1.50; var serviceReturn = new ConcurrentDictionary <string, double>(); serviceReturn.TryAdd(baseCurrency, currency); currencyServiceMock.Setup(s => s.GetRatesAsync()).Returns(Task.FromResult(serviceReturn)); string userId = "userId"; double amountInUserCurrency = 50; string description = "1234567890"; var user = new User() { Id = userId, Wallet = new Wallet() { Id = "walledId", Currency = new Currency() { Id = 1, Name = baseCurrency }, DisplayBalance = 750, NormalisedBalance = 500 } }; using (var context = new CasinoContext(contextOptions)) { context.Users.Add(user); await context.SaveChangesAsync(); var transactionService = new TransactionService(context, currencyServiceMock.Object); var savedTransaction = await transactionService.AddStakeTransaction(userId, amountInUserCurrency, description); var originalAmount = savedTransaction.OriginalAmount; var normalisedAmount = savedTransaction.NormalisedAmount; var userAmount = context.Users.Find(userId).Wallet.NormalisedBalance; var userDisplayAmount = context.Users.Find(userId).Wallet.DisplayBalance; var winTransaction = savedTransaction.TransactionTypeId; Assert.AreEqual(amountInUserCurrency, originalAmount); Assert.AreEqual(amountInUserCurrency / currency, normalisedAmount); Assert.AreEqual(500 - amountInUserCurrency / currency, userAmount); Assert.AreEqual(750 - amountInUserCurrency, userDisplayAmount); Assert.IsTrue(winTransaction == 2); } }
public async Task ThrowWhenInsufficientFundsForOperation() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ThrowWhenInsufficientFundsForOperation") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var baseCurrency = "USD"; var currency = 1.50; string cardId = "cardId"; var serviceReturn = new ConcurrentDictionary <string, double>(); serviceReturn.TryAdd(baseCurrency, currency); currencyServiceMock.Setup(s => s.GetRatesAsync()).Returns(Task.FromResult(serviceReturn)); string userId = "userId"; double amountInUserCurrency = 50; string description = "1234567890"; var user = new User() { Id = userId, Wallet = new Wallet() { Id = "walledId", Currency = new Currency() { Id = 1, Name = baseCurrency }, }, Cards = new List <BankCard>() { new BankCard() { Id = "cardId" } } }; using (var context = new CasinoContext(contextOptions)) { context.Users.Add(user); await context.SaveChangesAsync(); var transactionService = new TransactionService(context, currencyServiceMock.Object); await Assert.ThrowsExceptionAsync <InsufficientFundsException>( () => transactionService.AddWithdrawTransaction(userId, cardId, amountInUserCurrency, description)); } }
public async Task ReturnUserTransactionsCorrectParametersArePassed_AndUserIdIsInDb() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ReturnUserTransactionshenCorrectParametersArePassed_AndUserIdIsInDb") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var userId = "user-id"; var type = "Win"; var currency = "USD"; var transactionsData = new Transaction() { Id = userId, UserId = userId, User = new User() { Id = userId, Wallet = new Wallet() { Currency = new Currency() { Name = currency } }, }, TransactionType = new TransactionType() { Name = type } }; using (var context = new CasinoContext(contextOptions)) { var transactionService = new TransactionService(context, currencyServiceMock.Object); context.Transactions.Add(transactionsData); await context.SaveChangesAsync(); var result = await transactionService.RetrieveUserTransaction(userId); Assert.IsInstanceOfType(result, typeof(Transaction)); Assert.IsTrue(result.UserId.Equals(userId)); Assert.IsTrue(result.TransactionType.Name.Equals(type)); Assert.IsTrue(result.User.Id.Equals(userId)); Assert.IsTrue(result.User.Wallet.Currency.Name.Equals(currency)); } }
public async Task ThrowEntityCurrencyNotFoundException_WhenUserUseUnMaitainableCurrency() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "DepositThrowEntityCurrencyNotFoundException_WhenUserUseUnMaitainableCurrency") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var serviceReturn = new ConcurrentDictionary <string, double>(); serviceReturn.TryAdd("USD", 4); currencyServiceMock.Setup(s => s.GetRatesAsync()).Returns(Task.FromResult(serviceReturn)); string userId = "userId"; string cardId = "cardId"; double amountInUserCurrency = 50.05; string description = "1234567890"; var user = new User() { Id = userId, Wallet = new Wallet() { Id = "walledId", Currency = new Currency() { Id = 1, Name = "GBP" } }, Cards = new List <BankCard>() { new BankCard() { Id = "cardId" } } }; using (var context = new CasinoContext(contextOptions)) { context.Users.Add(user); await context.SaveChangesAsync(); var transactionService = new TransactionService(context, currencyServiceMock.Object); await Assert.ThrowsExceptionAsync <EntityCurrencyNotFoundException>(() => transactionService.AddDepositTransaction(userId, cardId, amountInUserCurrency, description)); } }
public async Task ReturnAllTransactions() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ReturnAllTransactions") .Options; var currencyServiceMock = new Mock <ICurrencyRateApiService>(); var serviceReturn = new ConcurrentDictionary <string, double>(); string userId = "userId"; double amountInUserCurrency = 50; string description = "1234567890"; var transactionType = new TransactionType() { Id = 1 }; var newTransaction = new Transaction() { UserId = userId, OriginalAmount = amountInUserCurrency, Description = description, TransactionTypeId = 1, TransactionType = transactionType }; using (var context = new CasinoContext(contextOptions)) { context.Transactions.Add(newTransaction); await context.SaveChangesAsync(); var transactionService = new TransactionService(context, currencyServiceMock.Object); var transactions = await transactionService.GetAllTransactionsTable().ToListAsync(); Assert.AreEqual(1, transactions.Count()); Assert.IsTrue(transactions.First(u => u.UserId == userId).UserId == userId); Assert.IsTrue(transactions.First(u => u.UserId == userId).OriginalAmount == amountInUserCurrency); Assert.IsTrue(transactions.First(u => u.UserId == userId).Description == description); } }
public async Task ReturnDaylyTotalInBGN() { var contextOptions = new DbContextOptionsBuilder <CasinoContext>() .UseInMemoryDatabase(databaseName: "ReturnDaylyTotalInBGN") .Options; var normalisedAmount = 10; var transactionType = new TransactionType() { Id = 1, Name = "Win" }; var wallet = new Wallet() { Currency = new Currency() { Name = "BGN" } }; var user = new User() { Wallet = wallet }; var transaction = new Transaction() { CreatedOn = DateTime.Now, TransactionType = transactionType, User = user, NormalisedAmount = normalisedAmount }; var currentDay = DateTime.Now.Day; using (var context = new CasinoContext(contextOptions)) { context.Transactions.Add(transaction); var adminService = new AdminDashboardService(context); await context.SaveChangesAsync(); var result = await adminService.GetTransactionsCurrencyDaylyWins(currentDay); Assert.AreEqual(normalisedAmount, result.DaylyTotalUSD); } }