public void AuthenticateShouldLoginSuccessfullyTheUser() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginSuccessfullyTheUser))// "ValidUsernameAndPasswordShouldLoginSuccessfully") .Options; using (var context = new ExpensesDbContext(options)) { var usersService = new UsersService(context, config); var added = new LabII.DTOs.RegisterPostModel { Email = "*****@*****.**", FirstName = "Petre", LastName = "Popica", Password = "******", Username = "******", }; usersService.Register(added); var loggedIn = new LabII.DTOs.LoginPostModel { Username = "******", Password = "******" }; var authoresult = usersService.Authenticate(added.Username, added.Password); Assert.IsNotNull(authoresult); Assert.AreEqual(1, authoresult.Id); Assert.AreEqual(loggedIn.Username, authoresult.Username); //Assert.AreEqual(loggedIn.Password, UsersService.); } }
public void ValidGetAllShouldDisplayAllUsers() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginSuccessfullyTheUser))// "ValidGetAllShouldDisplayAllUsers") .Options; using (var context = new ExpensesDbContext(options)) { var usersService = new UsersService(context, config); var added = new LabII.DTOs.RegisterPostModel { Email = "*****@*****.**", FirstName = "Petre", LastName = "Popescu", Password = "******", Username = "******", }; usersService.Register(added); // Act var result = usersService.GetAll(); // Assert Assert.IsNotEmpty(result); Assert.AreEqual(1, result.Count()); } }
public void ValidRegisterShouldCreateANewUser() { var options = new DbContextOptionsBuilder <LabII.Models.ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser") .Options; using (var context = new ExpensesDbContext(options)) { var usersService = new UsersService(context, config); var added = new LabII.DTOs.RegisterPostModel { Email = "*****@*****.**", FirstName = "Petre", LastName = "Popescu", Password = "******", Username = "******", }; var result = usersService.Register(added); Assert.IsNotNull(result); Assert.AreEqual(added.Username, result.Username); } }