@@ -20,12 +20,9 @@ namespace Microsoft.Identity.Web.Test
20
20
{
21
21
public class CacheEncryptionTests
22
22
{
23
- #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
24
23
// 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 ;
29
26
30
27
[ Theory ]
31
28
[ InlineData ( true ) ]
@@ -35,7 +32,7 @@ public async Task EncryptionTestAsync(bool isEncrypted)
35
32
// Arrange
36
33
byte [ ] cache = new byte [ ] { 1 , 2 , 3 , 4 } ;
37
34
BuildTheRequiredServices ( isEncrypted ) ;
38
- _testCacheAdapter = ( _provider . GetRequiredService < IMsalTokenCacheProvider > ( ) as TestMsalDistributedTokenCacheAdapter ) ! ;
35
+ _testCacheAdapter = ( _provider ! . GetRequiredService < IMsalTokenCacheProvider > ( ) as TestMsalDistributedTokenCacheAdapter ) ! ;
39
36
TestTokenCache tokenCache = new TestTokenCache ( ) ;
40
37
TokenCacheNotificationArgs args = InstantiateTokenCacheNotificationArgs ( tokenCache ) ;
41
38
_testCacheAdapter . Initialize ( tokenCache ) ;
@@ -54,7 +51,12 @@ public async Task EncryptionTestAsync(bool isEncrypted)
54
51
private byte [ ] GetFirstCacheValue ( MemoryCache memoryCache )
55
52
{
56
53
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
58
60
dynamic content1 = memoryCache
59
61
. GetType ( )
60
62
. GetField ( "_coherentState" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
@@ -63,11 +65,20 @@ private byte[] GetFirstCacheValue(MemoryCache memoryCache)
63
65
. GetType ( )
64
66
. GetField ( "_entries" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic )
65
67
. 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 ) ! ;
66
77
#else
67
78
memoryCacheContent = ( memoryCache
68
79
. GetType ( )
69
80
. GetField ( "_entries" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) !
70
- . GetValue ( _testCacheAdapter . _memoryCache ) as IDictionary ) ! ;
81
+ . GetValue ( _testCacheAdapter ! . _memoryCache ) as IDictionary ) ! ;
71
82
#endif
72
83
var firstEntry = memoryCacheContent . Values . OfType < object > ( ) . First ( ) ;
73
84
var firstEntryValue = firstEntry . GetType ( )
0 commit comments