public async Task ListUserPaginatedFilterTest() { var userCount = 1; using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userSaved = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userSaved.PublicId); var userPaginated = await _userService.ListPaginate( new UserFilter { Query = UserMotherObject.ValidAdminUser().Name, Entity = new User { Name = UserMotherObject.ValidAdminUser().Name } }); Assert.Equal(userCount, userPaginated.Count); Assert.Contains(userPaginated.Items, x => x.Name == UserMotherObject.ValidAdminUser().Name); await _userService.DeleteAsync(userFound.PublicId); }
public async Task AddInvalidUserTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); await Assert.ThrowsAsync <BusinessException>(() => _userService.AddAsync(UserMotherObject.InvalidAdminUserWihoutPassword())); }
public async Task EditUserTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userSaved = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userSaved.PublicId); Assert.NotNull(userFound); userFound.Name = "Jane"; userFound.Email = "*****@*****.**"; userFound.Password = "******"; await _userService.UpdateAsync(userFound); await _userService.FindByIdAsync(userSaved.PublicId); var userEdited = await _userService.FindByIdAsync(userSaved.PublicId); Assert.Equal(userFound.Email, userEdited.Email); Assert.Equal(userFound.Password, userEdited.Password); Assert.Equal(userFound.Name, userEdited.Name); await _userService.DeleteAsync(userFound.PublicId); }
public async Task AddRefreshTokenValidTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userAdded = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userAdded.PublicId); Assert.NotNull(userFound); var refreshToken = Guid.NewGuid().ToString(); var refreshTokenAdded = await _userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); var userByRefreshToken = await _userService.GetUserByRefreshToken(refreshTokenAdded.Refreshtoken); Assert.NotNull(userByRefreshToken); Assert.Equal(userByRefreshToken.Email, userAdded.Email); Assert.Equal(userByRefreshToken.Password, userAdded.Password); Assert.Equal(userByRefreshToken.Name, userAdded.Name); await _userService.DeleteAsync(userFound.PublicId); }
public async Task DeleteUserValidTest() { var result = await _usersController.Delete(UserMotherObject.ValidAdminUser().PublicId); var contentResult = (NoContentResult)result; Assert.IsType <NoContentResult>(contentResult); Assert.Equal(204, contentResult.StatusCode); }
public async Task EditUserValidTest() { var result = await _usersController.Put(UserMotherObject.ValidAdminUser().PublicId, UserMotherObject.ValidAdminUserInput()); var contentResult = (AcceptedResult)result; Assert.IsType <AcceptedResult>(contentResult); Assert.Equal(202, contentResult.StatusCode); }
public async Task CreateUserValidTest() { var result = await _usersController.Post(UserMotherObject.ValidAdminUserInput()); var contentResult = (CreatedResult)result; Assert.IsType <CreatedResult>(contentResult); Assert.Equal(201, contentResult.StatusCode); }
private void SetupServiceMock() { var userServiceMock = new Mock <IUserService>(); userServiceMock.Setup(x => x.LoginAsync(UserMotherObject.ValidAdminUser().Email, UserMotherObject.ValidAdminUser().Password)) .ReturnsAsync(UserMotherObject.ValidAdminUser()); userServiceMock.Setup(x => x.AddRefreshToken(It.IsAny <RefreshToken>())).ReturnsAsync(RefreshTokenMotherObject.ValidRefreshToken()); userServiceMock.Setup(x => x.GetUserByRefreshToken(RefreshTokenMotherObject.ValidRefreshToken().Refreshtoken)).ReturnsAsync(UserMotherObject.ValidAdminUser()); authController = new AuthController(userServiceMock.Object, _mapper); }
public async Task GetUserValidTest() { var result = await _usersController.Get(UserMotherObject.ValidAdminUser().PublicId); var contentResult = (OkObjectResult)result; var user = (UserOutput)contentResult.Value; Assert.IsType <OkObjectResult>(contentResult); Assert.Equal(200, contentResult.StatusCode); Assert.IsType <UserOutput>(contentResult.Value); Assert.Equal(UserMotherObject.ValidAdminUser().Email, user.Email); Assert.Equal(UserMotherObject.ValidAdminUser().Name, user.Name); }
public async Task LoginInvalidPassTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userAdded = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userAdded.PublicId); Assert.NotNull(userFound); await Assert.ThrowsAsync <UnauthorizedUserException>(() => _userService.LoginAsync(userFound.Email, "wrong pass")); await _userService.DeleteAsync(userFound.PublicId); }
public async Task AddValidUserTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userSaved = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userSaved.PublicId); Assert.NotNull(userFound); Assert.Equal(UserMotherObject.ValidAdminUser().Password.ToSHA512(), userFound.Password); Assert.Equal(userFound.Name, UserMotherObject.ValidAdminUser().Name); Assert.True(userFound.UserId > 0); await _userService.DeleteAsync(userFound.PublicId); }
public async Task RemoveUserTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userSaved = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userSaved.PublicId); Assert.NotNull(userFound); await _userService.DeleteAsync(userFound.PublicId); var userDeleted = await _userService.FindByIdAsync(userSaved.PublicId); Assert.Null(userDeleted); }
public async Task LoginValidTest() { var result = await authController.Login( new UserLoginModel { Email = UserMotherObject.ValidAdminUser().Email, Password = UserMotherObject.ValidAdminUser().Password } ); var contentResult = (OkObjectResult)result; var userApiToken = (UserApiTokenModel)contentResult.Value; Assert.IsType <OkObjectResult>(contentResult); Assert.Equal(200, contentResult.StatusCode); Assert.IsType <UserApiTokenModel>(contentResult.Value); Assert.NotNull(userApiToken.Token); Assert.True(userApiToken.Expiration > DateTime.Now); }
public async Task LoginValidTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var userAdded = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userAdded.PublicId); Assert.NotNull(userFound); var userLoged = await _userService.LoginAsync(userFound.Email, UserMotherObject.ValidAdminUser().Password); Assert.NotNull(userLoged); Assert.Equal(userLoged.Email, userAdded.Email); Assert.Equal(userLoged.Password, userAdded.Password); Assert.Equal(userLoged.Name, userAdded.Name); await _userService.DeleteAsync(userFound.PublicId); }
public async Task RefreshTokenInvalidTest() { using var scope = _serviceProvider.CreateScope(); var _userService = scope.ServiceProvider.GetService <IUserService>(); var messages = scope.ServiceProvider.GetService <IStringLocalizer <VBaseProjectResources> >(); var userAdded = await _userService.AddAsync(UserMotherObject.ValidAdminUser()); var userFound = await _userService.FindByIdAsync(userAdded.PublicId); Assert.NotNull(userFound); var refreshToken = Guid.NewGuid().ToString(); await _userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken }); var exeption = await Assert.ThrowsAsync <UnauthorizedUserException>(() => _userService.GetUserByRefreshToken("wrong refresh token")); Assert.Equal(exeption.Message, messages[UserMessages.InvalidRefreshToken]); await _userService.DeleteAsync(userFound.PublicId); }
private void SetupServiceMock() { var userServiceMock = new Mock <IUserService>(); var userList = new List <User> { UserMotherObject.ValidAdminUser(), UserMotherObject.ValidAdminUser(), UserMotherObject.ValidAdminUser(), UserMotherObject.ValidAdminUser() }; var userListPaginated = new PagedList <User>(userList, 4); userServiceMock.Setup(x => x.FindByIdAsync(UserMotherObject.ValidAdminUser().PublicId)).ReturnsAsync(UserMotherObject.ValidAdminUser()); userServiceMock.Setup(x => x.AddAsync(It.IsAny <User>())).ReturnsAsync(UserMotherObject.ValidAdminUser()); userServiceMock.Setup(x => x.UpdateAsync(It.IsAny <User>())).Verifiable(); userServiceMock.Setup(x => x.DeleteAsync(UserMotherObject.ValidAdminUser().PublicId)).Verifiable(); userServiceMock.Setup(x => x.ListPaginate(It.IsAny <UserFilter>())). ReturnsAsync(userListPaginated); _usersController = new UsersController(userServiceMock.Object, _mapper); }