@@ -20,12 +20,9 @@ namespace Microsoft.Identity.Web.Test
2020{
2121 public class CacheEncryptionTests
2222 {
23- #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2423 // These fields won't be null in tests, as tests call BuildTheRequiredServices()
25- private TestMsalDistributedTokenCacheAdapter _testCacheAdapter ;
26- private IServiceProvider _provider ;
27-
28- #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
24+ private TestMsalDistributedTokenCacheAdapter ? _testCacheAdapter ;
25+ private IServiceProvider ? _provider ;
2926
3027 [ Theory ]
3128 [ InlineData ( true ) ]
@@ -35,7 +32,7 @@ public async Task EncryptionTestAsync(bool isEncrypted)
3532 // Arrange
3633 byte [ ] cache = new byte [ ] { 1 , 2 , 3 , 4 } ;
3734 BuildTheRequiredServices ( isEncrypted ) ;
38- _testCacheAdapter = ( _provider . GetRequiredService < IMsalTokenCacheProvider > ( ) as TestMsalDistributedTokenCacheAdapter ) ! ;
35+ _testCacheAdapter = ( _provider ! . GetRequiredService < IMsalTokenCacheProvider > ( ) as TestMsalDistributedTokenCacheAdapter ) ! ;
3936 TestTokenCache tokenCache = new TestTokenCache ( ) ;
4037 TokenCacheNotificationArgs args = InstantiateTokenCacheNotificationArgs ( tokenCache ) ;
4138 _testCacheAdapter . Initialize ( tokenCache ) ;
@@ -54,7 +51,12 @@ public async Task EncryptionTestAsync(bool isEncrypted)
5451 private byte [ ] GetFirstCacheValue ( MemoryCache memoryCache )
5552 {
5653 IDictionary memoryCacheContent ;
57- #if NET7_0_OR_GREATER
54+ # if NET6_0
55+ memoryCacheContent = ( memoryCache
56+ . GetType ( )
57+ . GetProperty ( "StringKeyEntriesCollection" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
58+ . GetValue ( _testCacheAdapter ! . _memoryCache ) as IDictionary ) ! ;
59+ #elif NET7_0
5860 dynamic content1 = memoryCache
5961 . GetType ( )
6062 . GetField ( "_coherentState" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
@@ -63,11 +65,20 @@ private byte[] GetFirstCacheValue(MemoryCache memoryCache)
6365 . GetType ( )
6466 . GetField ( "_entries" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic )
6567 . GetValue ( content1 ) as IDictionary ) ! ;
68+ #elif NET8_0_OR_GREATER
69+ dynamic content1 = memoryCache
70+ . GetType ( )
71+ . GetField ( "_coherentState" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
72+ . GetValue ( memoryCache ) ! ;
73+ memoryCacheContent = ( content1 ?
74+ . GetType ( )
75+ . GetField ( "_stringEntries" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic )
76+ . GetValue ( content1 ) as IDictionary ) ! ;
6677#else
6778 memoryCacheContent = ( memoryCache
6879 . GetType ( )
6980 . GetField ( "_entries" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
70- . GetValue ( _testCacheAdapter . _memoryCache ) as IDictionary ) ! ;
81+ . GetValue ( _testCacheAdapter ! . _memoryCache ) as IDictionary ) ! ;
7182#endif
7283 var firstEntry = memoryCacheContent . Values . OfType < object > ( ) . First ( ) ;
7384 var firstEntryValue = firstEntry . GetType ( )
0 commit comments