diff --git a/src/ConfigCat.Client.Tests/ConfigCacheTests.cs b/src/ConfigCat.Client.Tests/ConfigCacheTests.cs index 5631c51a..8c46a2fc 100644 --- a/src/ConfigCat.Client.Tests/ConfigCacheTests.cs +++ b/src/ConfigCat.Client.Tests/ConfigCacheTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -227,6 +228,25 @@ public async Task ConfigCache_ShouldHandleWhenExternalCacheFails(bool isAsync) loggerMock.Verify(l => l.Log(LogLevel.Error, 2200, ref It.Ref.IsAny, It.Is(ex => ex is ApplicationException)), Times.Once); } + [DataRow("test1", "147c5b4c2b2d7c77e1605b1a4309f0ea6684a0c6")] + [DataRow("test2", "c09513b1756de9e4bc48815ec7a142b2441ed4d5")] + [DataTestMethod] + public void CacheKeyGeneration_ShouldBePlatformIndependent(string sdkKey, string expectedCacheKey) + { + Assert.AreEqual(expectedCacheKey, ConfigCatClient.GetCacheKey(sdkKey)); + } + + private const string PayloadTestConfigJson = "{\"p\":{\"u\":\"https://cdn-global.configcat.com\",\"r\":0},\"f\":{\"testKey\":{\"v\":\"testValue\",\"t\":1,\"p\":[],\"r\":[]}}}"; + [DataRow(PayloadTestConfigJson, "2023-06-14T15:27:15.8440000Z", "test-etag", "1686756435844\ntest-etag\n" + PayloadTestConfigJson)] + [DataTestMethod] + public void CachePayloadSerialization_ShouldBePlatformIndependent(string configJson, string timeStamp, string httpETag, string expectedPayload) + { + var timeStampDateTime = DateTimeOffset.ParseExact(timeStamp, "o", CultureInfo.InvariantCulture).UtcDateTime; + var pc = new ProjectConfig(configJson, configJson.Deserialize(), timeStampDateTime, httpETag); + + Assert.AreEqual(expectedPayload, ProjectConfig.Serialize(pc)); + } + private sealed class FakeExternalCache : IConfigCatCache { public volatile string? CachedValue = null; diff --git a/src/ConfigCatClient/ConfigCatClient.cs b/src/ConfigCatClient/ConfigCatClient.cs index e98812ae..2cd7cba9 100644 --- a/src/ConfigCatClient/ConfigCatClient.cs +++ b/src/ConfigCatClient/ConfigCatClient.cs @@ -664,7 +664,7 @@ private static IConfigService DetermineConfigService(PollingMode pollingMode, Ht }; } - private static string GetCacheKey(string sdkKey) + internal static string GetCacheKey(string sdkKey) { var key = $"{sdkKey}_{ConfigCatClientOptions.ConfigFileName}_{ProjectConfig.SerializationFormatVersion}"; return key.Hash();