Skip to content

Commit

Permalink
Adding context to unit test (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarpayan authored Aug 25, 2022
1 parent d4977c2 commit 0aa5338
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ public void ValidateTokenValidationResult(JsonWebTokenTheoryData theoryData)
[Theory, MemberData(nameof(TokenValidationClaimsTheoryData))]
public void ValidateTokenDerivedHandlerValidationResult(JsonWebTokenTheoryData theoryData)
{
TestUtilities.WriteHeader($"{this}.ValidateTokenDerivedHandlerValidationResult");
var derivedJsonWebTokenHandler = new DerivedJsonWebTokenHandler();
var context = TestUtilities.WriteHeader($"{this}.ValidateTokenDerivedHandlerValidationResult", theoryData);
var derivedJsonWebTokenHandler = new DerivedJsonWebTokenHandler();
var tokenValidationResult = theoryData.TokenHandler.ValidateToken(theoryData.AccessToken, theoryData.ValidationParameters);
var tokenValidationDerivedResult = derivedJsonWebTokenHandler.ValidateToken(theoryData.AccessToken, theoryData.ValidationParameters);
IdentityComparer.AreEqual(tokenValidationResult.Claims, TokenUtilities.CreateDictionaryFromClaims(tokenValidationResult.ClaimsIdentity.Claims));
IdentityComparer.AreEqual(tokenValidationDerivedResult.Claims, TokenUtilities.CreateDictionaryFromClaims(tokenValidationDerivedResult.ClaimsIdentity.Claims));
IdentityComparer.AreEqual(tokenValidationResult.Claims, tokenValidationDerivedResult.Claims);
IdentityComparer.AreEqual(tokenValidationResult.ClaimsIdentity.Claims, tokenValidationDerivedResult.ClaimsIdentity.Claims);
IdentityComparer.AreEqual(tokenValidationResult.Claims, TokenUtilities.CreateDictionaryFromClaims(tokenValidationResult.ClaimsIdentity.Claims), context);
IdentityComparer.AreEqual(tokenValidationDerivedResult.Claims, TokenUtilities.CreateDictionaryFromClaims(tokenValidationDerivedResult.ClaimsIdentity.Claims), context);
IdentityComparer.AreEqual(tokenValidationResult.Claims, tokenValidationDerivedResult.Claims, context);
IdentityComparer.AreEqual(tokenValidationResult.ClaimsIdentity.Claims, tokenValidationDerivedResult.ClaimsIdentity.Claims, context);
TestUtilities.AssertFailIfErrors(context);
}

public static TheoryData<JsonWebTokenTheoryData> TokenValidationClaimsTheoryData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.IdentityModel.TestUtils;
using Microsoft.IdentityModel.Tokens;

namespace Microsoft.IdentityModel.JsonWebTokens.Tests
{
public class JsonWebTokenTheoryData
public class JsonWebTokenTheoryData : TheoryDataBase
{
public TokenValidationParameters ValidationParameters { get; set; }

Expand Down

0 comments on commit 0aa5338

Please sign in to comment.