public void AuthenticateShouldLogTheRegisteredUser() { var options = new DbContextOptionsBuilder <FilmeDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogTheRegisteredUser)) .Options; using (var context = new FilmeDbContext(options)) { var usersService = new UsersService(context, config); var added = new Lab3.ViewModels.RegisterPostModel { FirstName = "firstName1", LastName = "lastName1", UserName = "******", Email = "*****@*****.**", Password = "******" }; var result = usersService.Register(added); var authenticated = new Lab3.ViewModels.LoginPostModel { Username = "******", Password = "******" }; var authresult = usersService.Authenticate(added.UserName, added.Password); Assert.IsNotNull(authresult); Assert.AreEqual(1, authresult.Id); Assert.AreEqual(authenticated.Username, authresult.UserName); } }
public void AuthenticateShouldLogTheRegisteredUser() { var options = new DbContextOptionsBuilder <FilmeDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogTheRegisteredUser)) .Options; using (var context = new FilmeDbContext(options)) { var validator = new RegisterValidator(); var validatorUser = new UserRoleValidator(); var userUserRoleService = new UserUserRolesService(validatorUser, context); var usersService = new UsersService(context, validator, userUserRoleService, config); UserRole addUserRoleRegular = new UserRole { Name = "Regular", Description = "Creat pentru testare" }; context.UserRoles.Add(addUserRoleRegular); context.SaveChanges(); var added = new Lab3.ViewModels.RegisterPostModel { FirstName = "firstName1", LastName = "lastName1", UserName = "******", Email = "*****@*****.**", Password = "******" }; var result = usersService.Register(added); var authenticated = new Lab3.ViewModels.LoginPostModel { Username = "******", Password = "******" }; //valid authentification var authresult = usersService.Authenticate(added.UserName, added.Password); Assert.IsNotNull(authresult); Assert.AreEqual(1, authresult.Id); Assert.AreEqual(authenticated.Username, authresult.UserName); //invalid user authentification var authresult1 = usersService.Authenticate("unknown", "abcdefg"); Assert.IsNull(authresult1); } }
public void GetCurentUserShouldReturnAccesToKlaims() { var options = new DbContextOptionsBuilder <FilmeDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetCurentUserShouldReturnAccesToKlaims)) .Options; using (var context = new FilmeDbContext(options)) { var validator = new RegisterValidator(); var validatorUser = new UserRoleValidator(); var userUserRoleService = new UserUserRolesService(validatorUser, context); var usersService = new UsersService(context, validator, userUserRoleService, config); UserRole addUserRoleRegular = new UserRole { Name = "Regular", Description = "Creat pentru testare" }; context.UserRoles.Add(addUserRoleRegular); context.SaveChanges(); var added = new Lab3.ViewModels.RegisterPostModel { FirstName = "firstName1", LastName = "lastName1", UserName = "******", Email = "*****@*****.**", Password = "******" }; var result = usersService.Register(added); var authenticated = new Lab3.ViewModels.LoginPostModel { Username = "******", Password = "******" }; var authresult = usersService.Authenticate(added.UserName, added.Password); //nu stiu sa instantiez un HttpContext //usersService.GetCurentUser(httpContext); Assert.IsNotNull(authresult); } }