Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use count property over count method #1657

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/IdentityServer/Endpoints/TokenEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private async Task<TokenErrorResult> TryReadProofTokens(HttpContext context, Tok
// DPoP header value
if (context.Request.Headers.TryGetValue(OidcConstants.HttpHeaders.DPoP, out var dpopHeader))
{
if (dpopHeader.Count() > 1)
if (dpopHeader.Count > 1)
{
_logger.LogDebug("Too many DPoP headers provided.");
return Error(OidcConstants.TokenErrors.InvalidDPoPProof, "Too many DPoP headers provided.");
Expand Down
2 changes: 1 addition & 1 deletion src/IdentityServer/Extensions/TokenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static Dictionary<string, object> CreateJwtPayloadDictionary(this Token t
{
var claims = token.Claims.Where(c => c.Type == claimType).ToArray();

if (claims.Count() > 1)
if (claims.Length > 1)
{
payload.Add(claimType, AddObjects(claims));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public virtual async Task<bool> RequiresConsentAsync(ClaimsPrincipal subject, Cl
if (consent.Scopes != null)
{
var intersect = scopes.Intersect(consent.Scopes);
var different = scopes.Count() != intersect.Count();
var different = scopes.Length != intersect.Count();

if (different)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ internal bool IsKeyRotationRequired(IEnumerable<KeyContainer> allKeys)

var groupedKeys = allKeys.GroupBy(x => x.Algorithm).ToArray();

var success = groupedKeys.Count() == _options.KeyManagement.AllowedSigningAlgorithmNames.Count() &&
var success = groupedKeys.Length == _options.KeyManagement.AllowedSigningAlgorithmNames.Count() &&
groupedKeys.All(x => _options.KeyManagement.AllowedSigningAlgorithmNames.Contains(x.Key));

if (!success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,14 @@ private void AssertValidToken(TokenResponse response)

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be(ClientId);
payload.Keys.Should().Contain("iat");

var scopes = payload["scope"].EnumerateArray();
scopes.First().ToString().Should().Be("api1");


}

private Dictionary<string, JsonElement> GetPayload(TokenResponse response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task Valid_request_single_audience_should_return_expected_payload()

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client");
Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task Valid_request_multiple_audiences_should_return_expected_payloa

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["client_id"].GetString().Should().Be("client");
payload.Keys.Should().Contain("jti");
Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task Valid_request_with_confirmation_should_return_expected_payload

var payload = GetPayload(response);

payload.Count().Should().Be(9);
payload.Count.Should().Be(9);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.cnf");
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task Requesting_multiple_scopes_should_return_expected_payload()

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client");
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task Request_with_no_explicit_scopes_should_return_expected_payload

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["client_id"].GetString().Should().Be("client");
payload.Keys.Should().Contain("jti");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task Resource_owner_success_should_return_custom_response()

// token content
var payload = GetPayload(response);
payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["client_id"].GetString().Should().Be("roclient");
payload["sub"].GetString().Should().Be("bob");
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task Extension_grant_success_should_return_custom_response()

// token content
var payload = GetPayload(response);
payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["client_id"].GetString().Should().Be("client.custom");
payload["sub"].GetString().Should().Be("bob");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task Valid_client_should_succeed()

var payload = GetPayload(response);

payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.custom");
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task Valid_client_with_extra_claim_should_succeed()
exp.Should().BeLessThan(unixNow + 3620);
exp.Should().BeGreaterThan(unixNow + 3580);

payload.Count().Should().Be(13);
payload.Count.Should().Be(13);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.custom");
Expand Down Expand Up @@ -182,7 +182,7 @@ public async Task Valid_client_with_refreshed_extra_claim_should_succeed()
exp.Should().BeLessThan(unixNow + 3620);
exp.Should().BeGreaterThan(unixNow + 3580);

payload.Count().Should().Be(13);
payload.Count.Should().Be(13);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.custom");
Expand Down Expand Up @@ -227,7 +227,7 @@ public async Task Valid_client_no_subject_should_succeed()

var payload = GetPayload(response);

payload.Count().Should().Be(8);
payload.Count.Should().Be(8);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.custom");
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task Valid_client_with_default_scopes_should_succeed()

var payload = GetPayload(response);

payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.custom");
Expand Down Expand Up @@ -387,7 +387,7 @@ public async Task Dynamic_lifetime_should_succeed()
exp.Should().BeLessThan(unixNow + 5020);
exp.Should().BeGreaterThan(unixNow + 4980);

payload.Count().Should().Be(10);
payload.Count.Should().Be(10);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.dynamic");
Expand Down Expand Up @@ -527,7 +527,7 @@ public async Task Dynamic_client_claims_should_succeed()

var payload = GetPayload(response);

payload.Count().Should().Be(13);
payload.Count.Should().Be(13);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.dynamic");
Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task Dynamic_client_claims_no_sub_should_succeed()

var payload = GetPayload(response);

payload.Count().Should().Be(9);
payload.Count.Should().Be(9);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("client.dynamic");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task Valid_user_should_succeed_with_expected_response_payload()

var payload = GetPayload(response);

payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("roclient");
Expand Down Expand Up @@ -142,7 +142,7 @@ public async Task Request_containing_identity_scopes_should_return_expected_payl

var payload = GetPayload(response);

payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("roclient");
Expand Down Expand Up @@ -184,7 +184,7 @@ public async Task Request_for_refresh_token_should_return_expected_payload()

var payload = GetPayload(response);

payload.Count().Should().Be(12);
payload.Count.Should().Be(12);
payload["iss"].GetString().Should().Be("https://idsvr4");
payload["aud"].GetString().Should().Be("api");
payload["client_id"].GetString().Should().Be("roclient");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task Algorithms_supported_should_match_signing_key()
var algorithmsSupported = data["id_token_signing_alg_values_supported"].EnumerateArray()
.Select(x => x.GetString()).ToList();

algorithmsSupported.Count().Should().Be(2);
algorithmsSupported.Count.Should().Be(2);
algorithmsSupported.Should().Contain(SecurityAlgorithms.RsaSha256);
algorithmsSupported.Should().Contain(SecurityAlgorithms.EcdsaSha256);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Single_resource_no_allowed_algorithms_set_should_return_empty_list()

var allowedAlgorithms = new List<ApiResource> { resource }.FindMatchingSigningAlgorithms();

allowedAlgorithms.Count().Should().Be(0);
allowedAlgorithms.Count.Should().Be(0);
}

[Fact]
Expand All @@ -31,7 +31,7 @@ public void Two_resources_no_allowed_algorithms_set_should_return_empty_list()

var allowedAlgorithms = new List<ApiResource> { resource1, resource2 }.FindMatchingSigningAlgorithms();

allowedAlgorithms.Count().Should().Be(0);
allowedAlgorithms.Count.Should().Be(0);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ public async Task ProcessConsentAsync_NoPromptMode_ConsentServiceRequiresConsent
ScopesValuesConsented = new string[] { "openid", "read" }
};
var result = await _subject.ProcessConsentAsync(request, consent);
request.ValidatedResources.Resources.IdentityResources.Count().Should().Be(1);
request.ValidatedResources.Resources.ApiScopes.Count().Should().Be(1);
request.ValidatedResources.Resources.IdentityResources.Count.Should().Be(1);
request.ValidatedResources.Resources.ApiScopes.Count.Should().Be(1);
"openid".Should().Be(request.ValidatedResources.Resources.IdentityResources.Select(x => x.Name).First());
"read".Should().Be(request.ValidatedResources.Resources.ApiScopes.First().Name);
request.WasConsentShown.Should().BeTrue();
Expand Down Expand Up @@ -357,8 +357,8 @@ public async Task ProcessConsentAsync_PromptModeConsent_ConsentGranted_ScopesSel
ScopesValuesConsented = new string[] { "openid", "read" }
};
var result = await _subject.ProcessConsentAsync(request, consent);
request.ValidatedResources.Resources.IdentityResources.Count().Should().Be(1);
request.ValidatedResources.Resources.ApiScopes.Count().Should().Be(1);
request.ValidatedResources.Resources.IdentityResources.Count.Should().Be(1);
request.ValidatedResources.Resources.ApiScopes.Count.Should().Be(1);
"read".Should().Be(request.ValidatedResources.Resources.ApiScopes.First().Name);
request.WasConsentShown.Should().BeTrue();
result.IsConsent.Should().BeFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public async Task GetAllKeysInternalAsync_when_cache_empty_should_update_the_cac
allKeys.Count().Should().Be(1);
allKeys.Single().Id.Should().Be(key);
_mockKeyStoreCache.StoreKeysAsyncWasCalled.Should().BeTrue();
_mockKeyStoreCache.Cache.Count().Should().Be(1);
_mockKeyStoreCache.Cache.Count.Should().Be(1);
_mockKeyStoreCache.Cache.Single().Id.Should().Be(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public async Task FindApiResourcesByScopeNameAsync_should_populate_cache()

{
_apiCache.Items.Count.Should().Be(0);
_apiResourceNamesCache.Items.Count().Should().Be(0);
_apiResourceNamesCache.Items.Count.Should().Be(0);
var items = await _subject.FindApiResourcesByScopeNameAsync(new[] { "invalid" });
items.Count().Should().Be(0);
_apiCache.Items.Count.Should().Be(0);
_apiResourceNamesCache.Items.Count().Should().Be(1);
_apiResourceNamesCache.Items.Count.Should().Be(1);
}

{
Expand All @@ -115,36 +115,36 @@ public async Task FindApiResourcesByScopeNameAsync_should_populate_cache()
_resourceCache.Items.Clear();

_apiCache.Items.Count.Should().Be(0);
_apiResourceNamesCache.Items.Count().Should().Be(0);
_apiResourceNamesCache.Items.Count.Should().Be(0);
var items = await _subject.FindApiResourcesByScopeNameAsync(new[] { "foo1" });
items.Count().Should().Be(1);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo" });
_apiCache.Items.Count.Should().Be(1);
_apiResourceNamesCache.Items.Count().Should().Be(1);
_apiResourceNamesCache.Items.Count.Should().Be(1);
}

{
var items = await _subject.FindApiResourcesByScopeNameAsync(new[] { "foo2" });
items.Count().Should().Be(1);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo" });
_apiCache.Items.Count.Should().Be(1);
_apiResourceNamesCache.Items.Count().Should().Be(2);
_apiResourceNamesCache.Items.Count.Should().Be(2);
}

{
var items = await _subject.FindApiResourcesByScopeNameAsync(new[] { "foo1", "bar1" });
items.Count().Should().Be(2);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo", "bar" });
_apiCache.Items.Count.Should().Be(2);
_apiResourceNamesCache.Items.Count().Should().Be(3);
_apiResourceNamesCache.Items.Count.Should().Be(3);
}

{
var items = await _subject.FindApiResourcesByScopeNameAsync(new[] { "foo2", "foo1", "bar2", "bar1" });
items.Count().Should().Be(2);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo", "bar" });
_apiCache.Items.Count.Should().Be(2);
_apiResourceNamesCache.Items.Count().Should().Be(4);
_apiResourceNamesCache.Items.Count.Should().Be(4);
}

{
Expand All @@ -156,7 +156,7 @@ public async Task FindApiResourcesByScopeNameAsync_should_populate_cache()
items.Count().Should().Be(2);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo", "bar" });
_apiCache.Items.Count.Should().Be(2);
_apiResourceNamesCache.Items.Count().Should().Be(4);
_apiResourceNamesCache.Items.Count.Should().Be(4);
}

{
Expand All @@ -169,7 +169,7 @@ public async Task FindApiResourcesByScopeNameAsync_should_populate_cache()
items.Count().Should().Be(2);
items.Select(x => x.Name).Should().BeEquivalentTo(new[] { "foo", "bar" });
_apiCache.Items.Count.Should().Be(2);
_apiResourceNamesCache.Items.Count().Should().Be(4);
_apiResourceNamesCache.Items.Count.Should().Be(4);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public async Task JWT_Token_with_scopes_have_expected_claims(bool flag)

result.Claims.Count().Should().Be(9);
var scopes = result.Claims.Where(c => c.Type == "scope").Select(c => c.Value).ToArray();
scopes.Count().Should().Be(2);
scopes.Length.Should().Be(2);
scopes[0].Should().Be("read");
scopes[1].Should().Be("write");
}
Expand Down
Loading