From 0aa5338a0dcb3667405e80e1b9e5b142771f11eb Mon Sep 17 00:00:00 2001 From: cesarpayan <86634096+cesarpayan@users.noreply.github.com> Date: Thu, 25 Aug 2022 09:38:27 -0700 Subject: [PATCH] Adding context to unit test (#1936) --- .../JsonWebTokenHandlerTests.cs | 13 +++++++------ .../JsonWebTokenTheoryData.cs | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandlerTests.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandlerTests.cs index 7d9fcb8b2f..babf9be5f6 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandlerTests.cs +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenHandlerTests.cs @@ -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 TokenValidationClaimsTheoryData() diff --git a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTheoryData.cs b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTheoryData.cs index 13bd9e1024..05eb59b170 100644 --- a/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTheoryData.cs +++ b/test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTheoryData.cs @@ -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; }