public async Task Activate_User_Should_Activate_User() { var idUserTest = _jimmyUser.Id; User myUserDesactivated = null; using (var context = new DaOAuthContext(_dbContextOptions)) { myUserDesactivated = context.Users.FirstOrDefault(u => u.Id.Equals(idUserTest)); myUserDesactivated.IsValid = false; context.Update(myUserDesactivated); context.Commit(); } Assert.IsNotNull(myUserDesactivated); Assert.IsFalse(myUserDesactivated.IsValid); var activateOrDesactivateUserDto = new ActivateOrDesactivateUserDto() { UserName = _jimmyUser.UserName }; var httpResponseMessage = await _client.PutAsJsonAsync("users/activate", activateOrDesactivateUserDto); Assert.IsTrue(httpResponseMessage.IsSuccessStatusCode); User myUserActivated = null; using (var context = new DaOAuthContext(_dbContextOptions)) { myUserActivated = context.Users.FirstOrDefault(u => u.Id.Equals(idUserTest)); } Assert.IsNotNull(myUserActivated); Assert.IsTrue(myUserActivated.IsValid); }
public async Task Token_For_Grant_Type_Refresh_Token_Should_Return_Valid_Token() { var jwtService = new JwtService() { Configuration = OAuthApiTestStartup.Configuration, Logger = new FakeLogger(), RepositoriesFactory = null, StringLocalizerFactory = new FakeStringLocalizerFactory() }; var jwtTokenDto = jwtService.GenerateToken(new CreateTokenDto() { ClientPublicId = _sammyClientPublicIdConfidential, Scope = _sammyScopeWording, SecondsLifeTime = OAuthApiTestStartup.Configuration.RefreshTokenLifeTimeInSeconds, TokenName = OAuthConvention.RefreshToken, UserName = _sammyUserName }); using (var context = new DaOAuthContext(_dbContextOptions)) { var userClient = context.UsersClients. FirstOrDefault(uc => uc.User.UserName.Equals(_sammyUserName) && uc.Client.PublicId.Equals(_sammyClientPublicIdConfidential)); Assert.IsNotNull(userClient); userClient.RefreshToken = jwtTokenDto.Token; context.Update(userClient); context.Commit(); } var formContent = BuildFormContent( _sammyClientPublicIdConfidential, String.Empty, OAuthConvention.GrantTypeRefreshToken, jwtTokenDto.Token, String.Empty, _sammyReturnUrlConfidential, _sammyScopeWording, _sammyUserName); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Authorization = BuildAuthenticationHeaderValue(_sammyClientPublicIdConfidential, _sammyClientSecretConfidential); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/token"); request.Content = formContent; var httpResponseMessage = await _client.SendAsync(request); Assert.IsTrue(httpResponseMessage.IsSuccessStatusCode); await CheckResponseContentIsValid(httpResponseMessage); }