public void ValidGetAllShouldDisplayAllUsers() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginSuccessfullyTheUser))// "ValidGetAllShouldDisplayAllUsers") .Options; using (var context = new UsersDbContext(options)) { var usersService = new UsersService(context, config); var added = new examen_web_application.Viewmodels.RegisterPostModel { Email = "*****@*****.**", FirstName = "ovi1", LastName = "ovi1", Password = "******", Username = "******", }; usersService.Register(added); var result = usersService.GetAll(); Assert.IsNotEmpty(result); Assert.AreEqual(1, result.Count()); } }
public void AuthenticateShouldLoginSuccessfullyTheUser() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginSuccessfullyTheUser))// "ValidUsernameAndPasswordShouldLoginSuccessfully") .Options; using (var context = new UsersDbContext(options)) { var usersService = new UsersService(context, config); var added = new examen_web_application.Viewmodels.RegisterPostModel { Email = "*****@*****.**", FirstName = "ovi1", LastName = "ovi1", Password = "******", Username = "******", }; usersService.Register(added); var loggedIn = new examen_web_application.Viewmodels.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); } }
public void ValidDeleteShouldRemoveTheUser() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidDeleteShouldRemoveTheUser)) .Options; using (var context = new UsersDbContext(options)) { var usersService = new UsersService(context, config); var added = new examen_web_application.Viewmodels.RegisterPostModel { FirstName = "firstName1", LastName = "firstName1", Username = "******", Email = "*****@*****.**", Password = "******" }; var userCreated = usersService.Register(added); Assert.NotNull(userCreated); var userDeleted = usersService.Delete(1); Assert.IsNotNull(userDeleted); Assert.AreEqual(0, usersService.GetAll().Count()); } }
public void GetByIdShouldReturnAnValidUser() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnAnValidUser)) .Options; using (var context = new UsersDbContext(options)) { var usersService = new UsersService(context, config); var added1 = new examen_web_application.Viewmodels.RegisterPostModel { FirstName = "firstName", LastName = "lastName", Username = "******", Email = "*****@*****.**", Password = "******" }; usersService.Register(added1); var userById = usersService.GetById(1); Assert.NotNull(userById); Assert.AreEqual("firstName", userById.FirstName); } }
public void ValidRegisterShouldCreateANewUser() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser") .Options; using (var context = new UsersDbContext(options)) { UsersService usersService = new UsersService(context, config); var added = new examen_web_application.Viewmodels.RegisterPostModel { Email = "*****@*****.**", FirstName = "ovi", LastName = "ovi", Password = "******", Username = "******", }; var result = usersService.Register(added); Assert.IsNotNull(result); Assert.AreEqual(added.Username, result.Username); } }