public void PopulateProviderCredentials_Facebook_CreatesExpectedCredentials() { const string UserIdClaimValue = "FacebookId"; FacebookCredentials credentials = new FacebookCredentials(); TokenResult tokenResult = new TokenResult(); tokenResult.Properties.Add(TokenResult.Authentication.AccessTokenName, "TestAccessToken"); Dictionary<string, string> claims = new Dictionary<string, string> { { "Claim1", "Value1" }, { "Claim2", "Value1" }, { "Claim3", "Value1" }, { ClaimTypes.NameIdentifier, UserIdClaimValue } }; tokenResult.Claims = claims; MobileAppUser.PopulateProviderCredentials(tokenResult, credentials); Assert.Equal("TestAccessToken", credentials.AccessToken); Assert.Equal(UserIdClaimValue, credentials.UserId); Assert.Equal(claims.Count, credentials.Claims.Count); }
private static HttpResponseMessage CreateResponse(TokenResult tokenResult) { HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StringContent(JsonConvert.SerializeObject(tokenResult)); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return response; }
public void PopulateProviderCredentials_Google_CreatesExpectedCredentials() { const string UserIdClaimValue = "GoogleId"; GoogleCredentials credentials = new GoogleCredentials(); TokenResult tokenResult = new TokenResult(); tokenResult.Properties.Add(TokenResult.Authentication.AccessTokenName, "TestAccessToken"); tokenResult.Properties.Add(TokenResult.Authentication.RefreshTokenName, "TestRefreshToken"); tokenResult.Properties.Add("AccessTokenExpiration", "2015-03-12T16:49:28.504Z"); Dictionary<string, string> claims = new Dictionary<string, string> { { "Claim1", "Value1" }, { "Claim2", "Value1" }, { "Claim3", "Value1" }, { ClaimTypes.NameIdentifier, UserIdClaimValue } }; tokenResult.Claims = claims; MobileAppUser.PopulateProviderCredentials(tokenResult, credentials); Assert.Equal("TestAccessToken", credentials.AccessToken); Assert.Equal("TestRefreshToken", credentials.RefreshToken); Assert.Equal(DateTimeOffset.Parse("2015-03-12T16:49:28.504Z"), credentials.AccessTokenExpiration); Assert.Equal(UserIdClaimValue, credentials.UserId); Assert.Equal(claims.Count, credentials.Claims.Count); }
public void IsTokenValid_ReturnsTrue_WhenTokenIsValid() { // Arrange TokenResult tokenResult = new TokenResult(); // Act bool result = MobileAppUser.IsTokenValid(tokenResult); // Assert Assert.True(result); }
public void IsTokenValid_ReturnsFalse_WhenTokenIsInvalid() { // Arrange // This is what is returned when a token is not found. TokenResult tokenResult = new TokenResult() { Diagnostics = "Token not found in store. id=sid:90BF712CA4464DDCADED130D8E5D1D8E, name=Twitter" }; // Act bool result = MobileAppUser.IsTokenValid(tokenResult); // Assert Assert.False(result); }
public void PopulateProviderCredentials_Twitter_CreatesExpectedCredentials() { TwitterCredentials credentials = new TwitterCredentials(); TokenResult tokenResult = new TokenResult(); tokenResult.Properties.Add(TokenResult.Authentication.AccessTokenName, "TestAccessToken"); tokenResult.Properties.Add("AccessTokenSecret", "TestAccessTokenSecret"); Dictionary<string, string> claims = new Dictionary<string, string> { { "Claim1", "Value1" }, { "Claim2", "Value1" }, { "Claim3", "Value1" } }; tokenResult.Claims = claims; MobileAppUser.PopulateProviderCredentials(tokenResult, credentials); Assert.Equal("TestAccessToken", credentials.AccessToken); Assert.Equal("TestAccessTokenSecret", credentials.AccessTokenSecret); Assert.Equal(claims.Count, credentials.Claims.Count); }