Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public OrderService(ATZBDbContext dbContext
                     , IPasswordValidatorService passwordValidator
                     , ITokenGeneratorService tokenGeneratorService)
 {
     _dbContext             = dbContext;
     _passwordValidator     = passwordValidator;
     _tokenGeneratorService = tokenGeneratorService;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
 public void SeedDbWithUsers(ATZBDbContext context, List <ATZBUser> users)
 {
     context.Users.AddRange(users);
     context.SaveChanges();
 }
Ejemplo n.º 7
0
 public OrderService(ATZBDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 8
0
 public void SeedDbWithOrders(ATZBDbContext context)
 {
     context.AddRange();
     context.SaveChanges();
 }
Ejemplo n.º 9
0
 public OffertService(ATZBDbContext dbContext)
 {
     _dbContext = dbContext;
 }