public async Task ReturnUserCurrency_WhenValidUserIdIsPassed()
        {
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnUserCurrency_WhenValidUserIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var user = new User()
            {
                Currency = Currency.BGN
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.Users.AddAsync(user);

                await bedeSlotsContext.SaveChangesAsync();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut    = new Data.CurrencyService(bedeSlotsContext);
                var result = await sut.GetUserCurrencyAsync(user.Id);

                Assert.IsTrue(result == user.Currency);
                Assert.IsInstanceOfType(result, typeof(Currency));
            }
        }
        public async Task ReturnCardNumberDto_WhenValidId()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCardNumberDto_WhenValidId")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard()
            {
                Id     = 1,
                Number = "1111111111111111"
            };
            CardNumberDto result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();

                result = await sut.GetCardNumberByIdAsync(card.Id);
            }

            Assert.IsTrue(result.Number == card.Number.Substring(12));
            Assert.IsInstanceOfType(result, typeof(CardNumberDto));
        }
예제 #3
0
        public async Task ReturnTrue_WhenCardExistsInDatabase()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnTrue_WhenCardExistsInDatabase")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard();

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);

                Assert.IsTrue(sut.CardExists(card.Id));
            }
        }
        public async Task ReturnCollectionOfUserTransactions_WhenValidUserIdIsPassed()
        {
            var serviceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfUserTransactions_WhenValidUserIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var user = new User()
            {
                Email = "test"
            };
            var otherUser = new User();

            var transaction = new Transaction()
            {
                User   = user,
                UserId = user.Id,
                Type   = TransactionType.Deposit
            };

            var secondTransaction = new Transaction()
            {
                User   = user,
                UserId = user.Id,
                Type   = TransactionType.Deposit
            };

            var thirdTransaction = new Transaction()
            {
                User   = otherUser,
                UserId = otherUser.Id,
                Type   = TransactionType.Deposit
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.Users.AddAsync(user);

                await bedeSlotsContext.Users.AddAsync(otherUser);

                await bedeSlotsContext.Transactions.AddAsync(transaction);

                await bedeSlotsContext.Transactions.AddAsync(secondTransaction);

                await bedeSlotsContext.Transactions.AddAsync(thirdTransaction);

                await bedeSlotsContext.SaveChangesAsync();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var currencyConverterMock = new Mock <ICurrencyConverterService>();
                var sut    = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object);
                var result = sut.GetUserTransactionsAsync(user.Id);

                Assert.IsTrue(await result.CountAsync() == 2);
            }
        }
        public async Task ThrowServiceException_WhenUserCurrencyIsNull()
        {
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenUserCurrencyIsNull")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var user = new User();

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.Users.AddAsync(user);

                await bedeSlotsContext.SaveChangesAsync();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CurrencyService(bedeSlotsContext);
                await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserCurrencyAsync(user.Id));
            }
        }
예제 #6
0
        public async Task ReturnCardDetailsDto_WhenValidIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCardDetailsDto_WhenValidIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard()
            {
                UserId    = user.Id,
                User      = user,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa,
                CreatedOn = DateTime.Now
            };

            CardDetailsDto result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();

                result = await sut.GetCardDetailsByIdAsync(card.Id);
            }

            Assert.IsTrue(result.LastFourDigit == card.Number.Substring(12));
            Assert.IsInstanceOfType(result, typeof(CardDetailsDto));
        }