|
1 | 1 | using System.Collections.Generic; |
| 2 | +using System.Text; |
2 | 3 | using System.Threading.Tasks; |
3 | 4 | using Momento.Sdk.Internal.ExtensionMethods; |
4 | 5 | using Momento.Sdk.Requests; |
| 6 | +using Xunit.Abstractions; |
5 | 7 |
|
6 | 8 | namespace Momento.Sdk.Tests.Integration.Cache; |
7 | 9 |
|
8 | 10 | [Collection("CacheClient")] |
9 | 11 | public class DictionaryTest : TestBase |
10 | 12 | { |
11 | | - public DictionaryTest(CacheClientFixture fixture) : base(fixture) |
| 13 | + private readonly ITestOutputHelper _output; |
| 14 | + |
| 15 | + public DictionaryTest(CacheClientFixture fixture, ITestOutputHelper output) : base(fixture) |
12 | 16 | { |
| 17 | + _output = output; |
13 | 18 | } |
14 | 19 |
|
15 | 20 | [Theory] |
@@ -913,18 +918,36 @@ public async Task DictionaryFetchAsync_HasContentByteArrayByteArray_HappyPath() |
913 | 918 | Assert.True(fetchResponse is CacheDictionaryFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); |
914 | 919 |
|
915 | 920 | var hitResponse = (CacheDictionaryFetchResponse.Hit)fetchResponse; |
916 | | - // Exercise byte array dictionary structural equality comparer |
917 | | - Assert.True(hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field1), $"Could not find key {field1} in dictionary byte array: {hitResponse.ValueDictionaryByteArrayByteArray!}"); |
918 | | - Assert.True(hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field2), $"Could not find key {field2} in dictionary byte array: {hitResponse.ValueDictionaryByteArrayByteArray!}"); |
919 | 921 | Assert.Equal(2, hitResponse.ValueDictionaryByteArrayByteArray!.Count); |
920 | 922 |
|
| 923 | + // Print dictionary content to output for debugging |
| 924 | + _output.WriteLine("Hit Response Dictionary Contents:"); |
| 925 | + foreach (var kvp in hitResponse.ValueDictionaryByteArrayByteArray!) |
| 926 | + { |
| 927 | + _output.WriteLine($"Key: {BitConverter.ToString(kvp.Key)} | Value: {BitConverter.ToString(kvp.Value)}"); |
| 928 | + } |
| 929 | + |
| 930 | + // Log if specific keys are missing |
| 931 | + if (!hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field1)) |
| 932 | + { |
| 933 | + _output.WriteLine($"Warning: Key {BitConverter.ToString(field1)} was not found in the dictionary."); |
| 934 | + } |
| 935 | + |
| 936 | + if (!hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field2)) |
| 937 | + { |
| 938 | + _output.WriteLine($"Warning: Key {BitConverter.ToString(field2)} was not found in the dictionary."); |
| 939 | + } |
| 940 | + |
921 | 941 | // Exercise DictionaryEquals extension |
922 | | - Assert.True(hitResponse.ValueDictionaryByteArrayByteArray!.DictionaryEquals(contentDictionary), $"Expected DictionaryEquals to return true for these dictionaries: {hitResponse.ValueDictionaryByteArrayByteArray!} AND {contentDictionary}"); |
| 942 | + var actualDictionaryString = DictionaryToString(hitResponse.ValueDictionaryByteArrayByteArray!); |
| 943 | + var expectedDictionaryString = DictionaryToString(contentDictionary); |
| 944 | + Assert.True(hitResponse.ValueDictionaryByteArrayByteArray!.DictionaryEquals(contentDictionary), |
| 945 | + $"Dictionary contents do not match. Actual dictionary: {actualDictionaryString} | Expected dictionary: {expectedDictionaryString}"); |
923 | 946 |
|
924 | 947 | // Test field caching behavior |
925 | 948 | Assert.Same(hitResponse.ValueDictionaryByteArrayByteArray, hitResponse.ValueDictionaryByteArrayByteArray); |
926 | 949 | } |
927 | | - |
| 950 | + |
928 | 951 | [Fact] |
929 | 952 | public async Task DictionaryDeleteAsync_DictionaryDoesNotExist_Noop() |
930 | 953 | { |
@@ -1161,4 +1184,14 @@ public async Task DictionaryLengthAsync_HappyPath() |
1161 | 1184 | var hitResponse = (CacheDictionaryLengthResponse.Hit)lengthResponse; |
1162 | 1185 | Assert.Equal(1, hitResponse.Length); |
1163 | 1186 | } |
| 1187 | + |
| 1188 | + private string DictionaryToString(IDictionary<byte[], byte[]> dictionary) |
| 1189 | + { |
| 1190 | + var sb = new StringBuilder(); |
| 1191 | + foreach (var kvp in dictionary) |
| 1192 | + { |
| 1193 | + sb.AppendLine($"Key: {BitConverter.ToString(kvp.Key)} | Value: {BitConverter.ToString(kvp.Value)}"); |
| 1194 | + } |
| 1195 | + return sb.ToString(); |
| 1196 | + } |
1164 | 1197 | } |
0 commit comments