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