Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak committed Jan 5, 2021
1 parent 672d9f7 commit 7883d6b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client/Microsoft.Identity.Client/TokenCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public sealed partial class TokenCache : ITokenCacheInternal
private ICoreLogger Logger => ServiceBundle.DefaultLogger;

internal IServiceBundle ServiceBundle { get; }
internal ILegacyCachePersistence LegacyCachePersistence { get; }
internal ILegacyCachePersistence LegacyCachePersistence { get; set; }
internal string ClientId => ServiceBundle.Config.ClientId;

ITokenCacheAccessor ITokenCacheInternal.Accessor => _accessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,17 @@ public void TestConstructor_BadInstanceMetadata()

Assert.AreEqual(ex.ErrorCode, MsalError.InvalidUserInstanceMetadata);
}

[TestMethod]
public void TestConstructor_WithAdalCacheCompatibility()
{
var cca = ConfidentialClientApplicationBuilder
.Create(TestConstants.ClientId)
.WithClientSecret(TestConstants.ClientSecret)
.WithAdalCacheCompatibility(true)
.Build();

Assert.AreEqual(true, cca.AppConfig.AdalCacheCompatibilityEnabled);
}
}
}
39 changes: 39 additions & 0 deletions tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,45 @@ public override void TestInitialize()
base.TestInitialize();
}

[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
public async Task WithAdalCacheCompatibilityTest_Async(bool enableAdalCacheCompatibility)
{
// Arrange
var legacyCachePersistence = Substitute.For<ILegacyCachePersistence>();
var serviceBundle = TestCommon.CreateServiceBundleWithCustomHttpManager(null, isAdalCacheEnabled: enableAdalCacheCompatibility);
var requestContext = new RequestContext(serviceBundle, Guid.NewGuid());
var response = TestConstants.CreateMsalTokenResponse();

ITokenCacheInternal cache = new TokenCache(serviceBundle, false);
((TokenCache)cache).LegacyCachePersistence = legacyCachePersistence;

var requestParams = TestCommon.CreateAuthenticationRequestParameters(serviceBundle);
requestParams.TenantUpdatedCanonicalAuthority = Authority.CreateAuthorityWithTenant(
requestParams.AuthorityInfo,
TestConstants.Utid);
requestParams.Account = new Account(TestConstants.s_userIdentifier, $"1{TestConstants.DisplayableId}", TestConstants.ProductionPrefNetworkEnvironment);

// Act
await cache.FindRefreshTokenAsync(requestParams).ConfigureAwait(true);
await cache.SaveTokenResponseAsync(requestParams, response).ConfigureAwait(true);
await cache.GetAccountsAsync(requestParams).ConfigureAwait(true);
await cache.RemoveAccountAsync(requestParams.Account, requestContext).ConfigureAwait(true);

// Assert
if (enableAdalCacheCompatibility)
{
legacyCachePersistence.ReceivedWithAnyArgs().LoadCache();
legacyCachePersistence.ReceivedWithAnyArgs().WriteCache(Arg.Any<byte[]>());
}
else
{
legacyCachePersistence.DidNotReceiveWithAnyArgs().LoadCache();
legacyCachePersistence.DidNotReceiveWithAnyArgs().WriteCache(Arg.Any<byte[]>());
}
}

[TestMethod]
public void GetExactScopesMatchedAccessTokenTest()
{
Expand Down

0 comments on commit 7883d6b

Please sign in to comment.