diff --git a/Directory.Build.props b/Directory.Build.props index f35d47cab..9576ee70a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -116,7 +116,7 @@ 8.0.0 8.0.0 - 8.0.0 + 8.0.1 8.0.0 8.0.1 8.0.0 @@ -144,7 +144,7 @@ 6.0.12 6.0.12 - 6.0.0 + 6.0.2 6.0.0 6.0.0 6.0.1 diff --git a/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs b/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs index e664ee318..c2db4653b 100644 --- a/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs +++ b/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs @@ -20,12 +20,9 @@ namespace Microsoft.Identity.Web.Test { public class CacheEncryptionTests { -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. // These fields won't be null in tests, as tests call BuildTheRequiredServices() - private TestMsalDistributedTokenCacheAdapter _testCacheAdapter; - private IServiceProvider _provider; - -#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + private TestMsalDistributedTokenCacheAdapter? _testCacheAdapter; + private IServiceProvider? _provider; [Theory] [InlineData(true)] @@ -35,7 +32,7 @@ public async Task EncryptionTestAsync(bool isEncrypted) // Arrange byte[] cache = new byte[] { 1, 2, 3, 4 }; BuildTheRequiredServices(isEncrypted); - _testCacheAdapter = (_provider.GetRequiredService() as TestMsalDistributedTokenCacheAdapter)!; + _testCacheAdapter = (_provider!.GetRequiredService() as TestMsalDistributedTokenCacheAdapter)!; TestTokenCache tokenCache = new TestTokenCache(); TokenCacheNotificationArgs args = InstantiateTokenCacheNotificationArgs(tokenCache); _testCacheAdapter.Initialize(tokenCache); @@ -54,7 +51,12 @@ public async Task EncryptionTestAsync(bool isEncrypted) private byte[] GetFirstCacheValue(MemoryCache memoryCache) { IDictionary memoryCacheContent; -#if NET7_0_OR_GREATER +# if NET6_0 + memoryCacheContent = (memoryCache + .GetType() + .GetProperty("StringKeyEntriesCollection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! + .GetValue(_testCacheAdapter!._memoryCache) as IDictionary)!; +#elif NET7_0 dynamic content1 = memoryCache .GetType() .GetField("_coherentState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! @@ -63,11 +65,20 @@ private byte[] GetFirstCacheValue(MemoryCache memoryCache) .GetType() .GetField("_entries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .GetValue(content1) as IDictionary)!; +#elif NET8_0_OR_GREATER + dynamic content1 = memoryCache + .GetType() + .GetField("_coherentState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! + .GetValue(memoryCache)!; + memoryCacheContent = (content1? + .GetType() + .GetField("_stringEntries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) + .GetValue(content1) as IDictionary)!; #else memoryCacheContent = (memoryCache .GetType() .GetField("_entries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! - .GetValue(_testCacheAdapter._memoryCache) as IDictionary)!; + .GetValue(_testCacheAdapter!._memoryCache) as IDictionary)!; #endif var firstEntry = memoryCacheContent.Values.OfType().First(); var firstEntryValue = firstEntry.GetType() diff --git a/tests/Microsoft.Identity.Web.Test/DownstreamWebApiSupport/DownstreamApiTests.cs b/tests/Microsoft.Identity.Web.Test/DownstreamWebApiSupport/DownstreamApiTests.cs index f2faf6038..8be2e99b0 100644 --- a/tests/Microsoft.Identity.Web.Test/DownstreamWebApiSupport/DownstreamApiTests.cs +++ b/tests/Microsoft.Identity.Web.Test/DownstreamWebApiSupport/DownstreamApiTests.cs @@ -291,7 +291,7 @@ public async Task SerializeInput_WithSerializer_ReturnsSerializedContent_WhenJso // Assert Assert.NotNull(result); - Assert.Equal("serialized", await (result?.ReadAsStringAsync())); + Assert.Equal("serialized", await (result?.ReadAsStringAsync()!)); } [Fact] diff --git a/tests/Microsoft.Identity.Web.Test/ServiceCollectionExtensionsTests.cs b/tests/Microsoft.Identity.Web.Test/ServiceCollectionExtensionsTests.cs index e94725e8a..cbd9737d5 100644 --- a/tests/Microsoft.Identity.Web.Test/ServiceCollectionExtensionsTests.cs +++ b/tests/Microsoft.Identity.Web.Test/ServiceCollectionExtensionsTests.cs @@ -132,7 +132,7 @@ public void AddTokenAcquisition_AbleToOverrideICredentialsLoader() ServiceDescriptor[] orderedServices = services.OrderBy(s => s.ServiceType.FullName).ToArray(); - Assert.Single(orderedServices.Where(s => s.ServiceType == typeof(ICredentialsLoader))); + Assert.Single(orderedServices, s => s.ServiceType == typeof(ICredentialsLoader)); } [Fact]