Example #1
0
        public void ReturnEmptyCollectionUsers_WhenInvoked()
        {
            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: "ReturnEmptyCollectionUsers_WhenInvoked")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var transactionServiceMock = new Mock <ITransactionService>();

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Roles.Add(new IdentityRole("User"));
                bedeSlotsContext.SaveChanges();
            }

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

                Assert.IsTrue(sut.GetAllUsers().Count() == 0);
            }
        }
        public async Task ReturnUser_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: "ReturnUser_WhenValidIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User()
            {
                UserName = "******"
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }

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

                var result = await sut.GetUserByIdAsync(user.Id);

                Assert.IsTrue(result != null);
            }
        }
Example #3
0
        public async Task ThrowServiceException_WhenAmountParameterIsBiggerThanUserBalance()
        {
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReduceUserBalance_WhenValidParametersArePassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var tenDollars = 10;

            var amountBiggerThanUserBalance = 5000;

            var user = new User()
            {
                Balance = tenDollars, Currency = Currency.USD
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var currencyConverterMock = new Mock <ICurrencyConverterService>();

                var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object);

                await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.ReduceMoneyAsync(amountBiggerThanUserBalance, user.Id));
            }
        }
        public async Task ReturnCollectionOfAllRoles_WhenInvoked()
        {
            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: "ReturnCollectionOfAllRoles_WhenInvoked")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var role = new IdentityRole("User");

                bedeSlotsContext.Roles.Add(role);
                bedeSlotsContext.SaveChanges();
            }

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

                var result = await sut.GetAllRolesAsync();

                Assert.IsInstanceOfType(result, typeof(ICollection <IdentityRole>));
                Assert.IsTrue(result.Count == 1);
            }
        }
        public async Task ReturnCollectionOfAllTransaction_WhenValidParametersArePassed()
        {
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfAllTransaction_WhenValidParametersArePassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Transactions.Add(new Transaction()
                {
                    User = new User()
                    {
                        Email = "test"
                    }
                });
                bedeSlotsContext.SaveChanges();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var currencyConverterMock = new Mock <ICurrencyConverterService>();
                var sut    = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object);
                var result = sut.GetAllTransactions();

                Assert.IsTrue(await result.CountAsync() == 1);
            }
        }
Example #6
0
        public async Task ReduceUserBalance_WhenValidParametersArePassed()
        {
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReduceUserBalance_WhenValidParametersArePassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var tenDollars = 10;

            var user = new User()
            {
                Balance = tenDollars + tenDollars, Currency = Currency.USD
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var currencyConverterMock = new Mock <ICurrencyConverterService>();

                var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object);

                var result = await sut.ReduceMoneyAsync(tenDollars, user.Id);

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

            var expectedBalance = 100;

            var user = new User()
            {
                Balance = expectedBalance, Currency = Currency.USD
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var currencyConverterMock = new Mock <ICurrencyConverterService>();

                var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object);

                var result = await sut.GetUserBalanceByIdAsync(user.Id);

                Assert.IsTrue(result == expectedBalance);
            }
        }
Example #8
0
        public async Task ReturnEmptyCollectionOfCardNumberAssociatedWithUserId_WhenValidUserIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            ICollection <CardNumberDto> cards;

            Data.CardService cardService;

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

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

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                cardService = new Data.CardService(bedeSlotsContext, userManager);
                cards       = await cardService.GetUserCardsAllNumbersAsync(user.Id);

                Assert.IsTrue(cards.Count == 0);
            }
        }
Example #9
0
        public async Task ReturnUserRole_WhenValidParameterIsPassed()
        {
            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: "ReturnUserRole_WhenValidParameterIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var transactionServiceMock = new Mock <ITransactionService>();

            var user = new User();

            var role = new IdentityRole("User");

            IdentityUserRole <string> userRole;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Roles.Add(role);
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();

                userRole = new IdentityUserRole <string>()
                {
                    UserId = user.Id, RoleId = role.Id
                };

                bedeSlotsContext.UserRoles.Add(userRole);
                bedeSlotsContext.SaveChanges();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.UserService(bedeSlotsContext,
                                               userManager);

                var result = await sut.GetUserRoleAsync(user.Id);

                Assert.IsTrue(result.RoleId == userRole.RoleId);
            }
        }
Example #10
0
        public async Task ThrowServiceException_WhenInvalidNewRoleIsPassed()
        {
            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: "ThrowServiceException_WhenInvalidNewRoleIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var user = new User();

            var role = new IdentityRole("User");

            var newRole = new IdentityRole("newRole");

            var notExistingRoleId = "not existing role";

            IdentityUserRole <string> userRole;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Roles.Add(role);
                bedeSlotsContext.Roles.Add(newRole);
                bedeSlotsContext.Users.Add(user);

                userRole = new IdentityUserRole <string>()
                {
                    UserId = user.Id, RoleId = role.Id
                };

                bedeSlotsContext.UserRoles.Add(userRole);
                bedeSlotsContext.SaveChanges();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.UserService(bedeSlotsContext, userManager);

                await Assert.ThrowsExceptionAsync <ServiceException>(async() =>
                                                                     await sut.EditUserRoleAsync(user.Id, notExistingRoleId));
            }
        }
Example #11
0
        public async Task ReturnCollectionOfCardNumbersLastFourDigitsInDatabase_WhenValidUserIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            ICollection <CardNumberDto> cards;

            Data.CardService cardService;

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

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

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.BankCards.Add(card);
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();

                cardService = new Data.CardService(bedeSlotsContext, userManager);
                cards       = await cardService.GetUserCardsLastNumbersAsync(user.Id);
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                Assert.IsTrue(cards.Count == 1);
                Assert.IsInstanceOfType(cards, typeof(ICollection <CardNumberDto>));
                Assert.IsTrue(cards.First().Number == card.Number.Substring(12));
            }
        }
Example #12
0
        public async Task SuccessfullyChangeUserCurrentRole_WhenValidParametersArePassed()
        {
            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: "SuccessfullyChangeUserCurrentRole_WhenValidParametersArePassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            var user = new User();

            var role = new IdentityRole("User");

            var newRole = new IdentityRole("newRole");

            IdentityRole result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Roles.Add(role);
                bedeSlotsContext.Roles.Add(newRole);
                bedeSlotsContext.Users.Add(user);

                var userRole = new IdentityUserRole <string>()
                {
                    UserId = user.Id, RoleId = role.Id
                };

                bedeSlotsContext.UserRoles.Add(userRole);
                bedeSlotsContext.SaveChanges();

                var sut = new Data.UserService(bedeSlotsContext, userManager);

                result = await sut.EditUserRoleAsync(user.Id, newRole.Id);
            }

            Assert.IsTrue(result.Name == newRole.Name);
        }
Example #13
0
        public async Task ReturnUserCards_WhenExistingUserIdIsPassed()
        {
            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: "ReturnUserCards_WhenExistingUserIdIsPassed")
                                 .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
            };

            Data.CardService cardService;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.BankCards.Add(card);
                bedeSlotsContext.SaveChanges();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                cardService = new Data.CardService(bedeSlotsContext, userManager);
                var result = await cardService.GetUserCardsAsync(user.Id);

                Assert.IsTrue(result.Count == 1);
            }
        }