public void InvalidRegisterShouldNotCerateANewUserWithTheSameUsername() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(InvalidRegisterShouldNotCerateANewUserWithTheSameUsername)) .Options; using (var context = new MoviesDbContext(options)) { var userService = new UserService(context, config); var added1 = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdf", LastName = "asdfgh", Password = "******", Username = "******" }; var added2 = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdfg", LastName = "asdsdfgfgh", Password = "******", Username = "******" }; userService.Register(added1); var result = userService.Register(added2); Assert.AreEqual(null, result); } }
public void ValidRegisterShouldCerateANewUser() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCerateANewUser)) .Options; using (var context = new MoviesDbContext(options)) { var userService = new UserService(context, config); var added = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdf", LastName = "asdfgh", Password = "******", Username = "******" }; var result = userService.Register(added); Assert.IsNotNull(result); Assert.AreEqual(added.Username, result.Username); } }
public void InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword)) .Options; using (var context = new MoviesDbContext(options)) { var userService = new UserService(context, config); var addedUser = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdfg", LastName = "asdsdfgfgh", Password = "******", Username = "******" }; var addResult = userService.Register(addedUser); Assert.IsNotNull(addResult); Assert.AreEqual(addedUser.Username, addResult.Username); var authentificate = new Lab2.ViewModels.UserGetModel { Email = "[email protected]", Username = "******" }; var result = userService.Authenticate(addedUser.Username, "11111111"); Assert.AreEqual(null, result); } }
public void ValidGetAllShouldReturnAllUsers() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidGetAllShouldReturnAllUsers)) .Options; using (var context = new MoviesDbContext(options)) { var userService = new UserService(context, config); var addedUser1 = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdfg", LastName = "asdsdfgfgh", Password = "******", Username = "******" }; var addedUser2 = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdfgh", LastName = "asdsdfgfgh", Password = "******", Username = "******" }; var addedUser3 = new Lab2.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "asdfgh", LastName = "asdsdfgfgh", Password = "******", Username = "******" }; UserGetModel user1 = userService.Register(addedUser1); UserGetModel user2 = userService.Register(addedUser2); UserGetModel user3 = userService.Register(addedUser3); List <UserGetModel> actual = new List <UserGetModel>(); user1.Token = null; user2.Token = null; user3.Token = null; actual.Add(user1); actual.Add(user2); actual.Add(user3); IEnumerable <UserGetModel> result = userService.GetAll(); IEnumerable <UserGetModel> expected = actual.AsEnumerable(); Assert.IsTrue(expected.SequenceEqual(actual)); } }