From 3a893decc893b9a574f127237f2a40c1f79d3226 Mon Sep 17 00:00:00 2001 From: Bart Koelman <104792814+bart-vmware@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:04:37 +0200 Subject: [PATCH] Fix for breaking changes in Redis API usage --- ...edisDataProtectionBuilderExtensionsTest.cs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Security/test/DataProtection.Redis.Test/RedisDataProtectionBuilderExtensionsTest.cs b/src/Security/test/DataProtection.Redis.Test/RedisDataProtectionBuilderExtensionsTest.cs index 86d6a84caa..340ab5a9b4 100644 --- a/src/Security/test/DataProtection.Redis.Test/RedisDataProtectionBuilderExtensionsTest.cs +++ b/src/Security/test/DataProtection.Redis.Test/RedisDataProtectionBuilderExtensionsTest.cs @@ -109,9 +109,30 @@ private static object GetMockedConnectionMultiplexer(string? connectionString) databaseMock.Setup(database => database.HashGetAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns( (RedisKey key, RedisValue[] _, CommandFlags _) => Task.FromResult(GetRedisValues(key))); +#if NET9_0_OR_GREATER + databaseMock.Setup(database => database.HashSetAsync(It.IsAny(), It.IsAny(), It.IsAny())).Returns( + (RedisKey key, HashEntry[] hashFields, CommandFlags _) => + { + byte[] data = hashFields[2].Value!; + innerStore[key!] = data; + return Task.CompletedTask; + }); +#else + // Use the following for .NET 8 and below. + /* databaseMock.Setup(database => database.ScriptEvaluateAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns( - (string _, RedisKey[]? keys, RedisValue[]? values, CommandFlags _) => Task.FromResult(SetRedisValues(keys, values))); + (string _, RedisKey[]? keys, RedisValue[]? values, CommandFlags _) => + { + RedisKey key = keys![0]; + byte[] data = values![3]!; + innerStore[key!] = data; + + var result = RedisResult.Create(key); + return Task.FromResult(result); + }); + */ +#endif var connectionMultiplexerMock = new Mock(); connectionMultiplexerMock.Setup(connectionMultiplexer => connectionMultiplexer.Configuration).Returns(connectionString!); @@ -139,11 +160,5 @@ RedisValue[] GetRedisValues(RedisKey key) default ]; } - - RedisResult SetRedisValues(RedisKey[]? keys, RedisValue[]? values) - { - innerStore[keys![0]!] = values![3]!; - return RedisResult.Create(keys[0]); - } } }