public void Register_ValidData_RegisteredUser() { // Arrange IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings() { Secret = "SECRET FOR TESTING" }); IUserService userService = new UserService(new FakeUserRepository(), mockOptions); RegisterModel model = new RegisterModel() { FirstName = "Greg", LastName = "Gregsky", Password = "******", ConfirmPassword = "******", Username = "******" }; // Act userService.Register(model); // Assert UserModel newUser = userService.Authenticate(model.Username, model.Password); Assert.AreEqual(model.FirstName, newUser.FirstName); Assert.AreEqual(model.LastName, newUser.LastName); }
public void InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword() { var options = new DbContextOptionsBuilder <UserDbContext>() .UseInMemoryDatabase(databaseName: nameof(InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword)) .Options; using (var context = new UserDbContext(options)) { var userService = new UserService(context, config); var addedUser = new Examen.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 Examen.ViewModels.UserGetModel { Email = "[email protected]", Username = "******" }; var result = userService.Authenticate(addedUser.Username, "11111111"); Assert.AreEqual(null, result); } }
public void Login() { var options = new DbContextOptionsBuilder <UsersDbContext>() .UseInMemoryDatabase(databaseName: nameof(Login)) .Options; using (var context = new UsersDbContext(options)) { var userService = new UserService(context, config); var added = new RegisterPostModel { Email = "*****@*****.**", FirstName = "Gavrilut", LastName = "Lucian", Password = "******", Username = "******" }; userService.Register(added); var loggedIn = new LoginPostModel { Username = "******", Password = "******" }; var result = userService.Authenticate(added.Username, added.Password); Assert.IsNotNull(result); //Assert.AreEqual(7, result.Id); Assert.AreEqual(loggedIn.Username, result.Username); } }
public void AuthenticateShouldLoginAUser() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginAUser)) .Options; using (var context = new ExpensesDbContext(options)) { var usersService = new UserService(context, config); var added = new RegisterUserPostDto // { FullName = "codruta", Username = "******", Email = "*****@*****.**", Password = "******" }; var result = usersService.Register(added); var authenticated = new LoginPostDto { 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 AuthenticateShouldLoginAUser() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginAUser)) .Options; using (var context = new MoviesDbContext(options)) { var usersService = new UserService(context, config); var added = new RegisterPostModel { FirstName = "alina", LastName = "demian", Username = "******", Email = "*****@*****.**", Password = "******" }; var result = usersService.Register(added); var authenticated = new 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 async Task DoesNotExistTest() { const string mockUserName = "******"; const string mockOtherUserName = "******"; var mockStorageService = new Mock <IStorageService>(); mockStorageService.Setup(o => o.GetUser(mockUserName)).Returns(Task.FromResult <User>(null)); var userService = new UserService(mockStorageService.Object); var result = await userService.Authenticate(mockOtherUserName, ""); Assert.AreEqual(null, result); }
public void Authenticate_InvalidUsernamePassword_Null() { // Arrange IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings() { Secret = "SECRET FOR TESTING" }); IUserService userService = new UserService(new FakeUserRepository(), mockOptions); string username = "******"; string password = "******"; // Act UserModel result = userService.Authenticate(username, password); // Assert Assert.IsNull(result); }
public async Task IsAuthenticatedTest() { const string mockUserName = "******"; const string mockPassword = "******"; var mockUser = new User { Username = mockUserName, Password = mockPassword }; var mockStorageService = new Mock <IStorageService>(); mockStorageService.Setup(o => o.GetUser(mockUserName)).Returns(Task.FromResult(mockUser)); var userService = new UserService(mockStorageService.Object); var result = await userService.Authenticate(mockUserName, mockPassword); Assert.AreEqual(mockUser, result); }
public void Authenticate_ValidUsernamePassword_ValidToken() { // Arrange IOptions <AppSettings> mockOptions = Options.Create <AppSettings>(new AppSettings() { Secret = "SECRET FOR TESTING" }); IUserService userService = new UserService(MockHelper.MockUserRepository(), mockOptions); string username = "******"; string password = "******"; // Act UserModel result = userService.Authenticate(username, password); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Token != string.Empty && result.Token != null); }
public void AuthenticateShouldLoginAUser() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLoginAUser)) .Options; using (var context = new AppDbContext(options)) { var usersService = new UserService(context, config); var result = usersService.Register(user); var authenticated = new LoginPostModel { Username = "******", Password = "******" }; var authresult = usersService.Authenticate(user.Username, user.Password); Assert.IsNotNull(authresult); Assert.AreEqual(1, authresult.Id); Assert.AreEqual(authenticated.Username, authresult.Username); } }
public void ValidAuthentificationShouldAuthenticateValidUser() { var options = new DbContextOptionsBuilder <MoviesDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidAuthentificationShouldAuthenticateValidUser)) .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, addedUser.Password); Assert.IsNotNull(result); Assert.AreEqual(authentificate.Username, result.Username); } }