Example #1
0
        public async Task GetUserByEmailAndPasswordTest()
        {
            DbContextOptions <ATZBDbContext> options = new DbContextOptionsBuilder <ATZBDbContext>()
                                                       .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                       .Options;
            ATZBDbContext         context               = new ATZBDbContext(options);
            UserService           userService           = new UserService(context);
            PasswordHasherService passwordHasherService = new PasswordHasherService();
            string emailForTest    = "*****@*****.**";
            string passwordForTest = "testpassword1";
            var    passwordHashed  = await passwordHasherService.HashPasswordAsync(passwordForTest);


            ATZBUser expectedUser = new ATZBUser()
            {
                Email          = emailForTest
                , PasswordHash = passwordHashed.Key
                , PasswordSalt = passwordHashed.Value
            };

            SeedDbWithUsers(context, DataForSeedUsers);
            await userService.CreateUserAsync(expectedUser);

            var actualUser = userService.GetUserByUsernameAndPasswordAsync(emailForTest, passwordForTest).Result.Key;

            Assert.Equal(expectedUser, actualUser);
        }
Example #2
0
        public void TheEmailAlreadyExistTest()
        {
            DbContextOptions <ATZBDbContext> options = new DbContextOptionsBuilder <ATZBDbContext>()
                                                       .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                       .Options;
            ATZBDbContext context = new ATZBDbContext(options);

            UserService userService   = new UserService(context);
            string      emailForCheck = "*****@*****.**";

            SeedDbWithUsers(context, DataForSeedUsers);

            context.Users
            .AddRange(
                new List <ATZBUser>()
            {
                new ATZBUser()
                {
                    Email = emailForCheck
                },
                new ATZBUser()
                {
                    Email = emailForCheck
                }
            });
            context.SaveChanges();


            Assert.True(userService.EmailAlreadyExistAsync(emailForCheck).Result);
        }
Example #3
0
 public OrderService(ATZBDbContext dbContext
                     , IPasswordValidatorService passwordValidator
                     , ITokenGeneratorService tokenGeneratorService)
 {
     _dbContext             = dbContext;
     _passwordValidator     = passwordValidator;
     _tokenGeneratorService = tokenGeneratorService;
 }
Example #4
0
        public void GetAllUsersTest()
        {
            DbContextOptions <ATZBDbContext> options = new DbContextOptionsBuilder <ATZBDbContext>()
                                                       .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                       .Options;
            ATZBDbContext context = new ATZBDbContext(options);

            UserService userService = new UserService(context);

            SeedDbWithUsers(context, DataForSeedUsers);

            int expectedUserCount = context.Users.Count();
            int actualUserCount   = userService.GetAllUsersAsync().Result.Count;

            Assert.Equal(expectedUserCount, actualUserCount);
        }
Example #5
0
        public async Task CreateUserTest()
        {
            DbContextOptions <ATZBDbContext> options = new DbContextOptionsBuilder <ATZBDbContext>()
                                                       .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                       .Options;
            ATZBDbContext context = new ATZBDbContext(options);

            UserService userService = new UserService(context);

            int expectedUsersCount = context.Users.Count() + 1;

            await userService.CreateUserAsync(new ATZBUser());

            int actualUsersCount = context.Users.Count();

            Assert.Equal(expectedUsersCount, actualUsersCount);
        }
Example #6
0
 public void SeedDbWithUsers(ATZBDbContext context, List <ATZBUser> users)
 {
     context.Users.AddRange(users);
     context.SaveChanges();
 }
Example #7
0
 public OrderService(ATZBDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #8
0
 public void SeedDbWithOrders(ATZBDbContext context)
 {
     context.AddRange();
     context.SaveChanges();
 }
Example #9
0
 public OffertService(ATZBDbContext dbContext)
 {
     _dbContext = dbContext;
 }