Skip to content

Commit 074536e

Browse files
2 parents 1d3b98c + 3945a8c commit 074536e

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

tests/Integration/Momento.Sdk.Tests/Cache/DictionaryTest.cs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
using System.Collections.Generic;
2+
using System.Text;
23
using System.Threading.Tasks;
34
using Momento.Sdk.Internal.ExtensionMethods;
45
using Momento.Sdk.Requests;
6+
using Xunit.Abstractions;
57

68
namespace Momento.Sdk.Tests.Integration.Cache;
79

810
[Collection("CacheClient")]
911
public class DictionaryTest : TestBase
1012
{
11-
public DictionaryTest(CacheClientFixture fixture) : base(fixture)
13+
private readonly ITestOutputHelper _output;
14+
15+
public DictionaryTest(CacheClientFixture fixture, ITestOutputHelper output) : base(fixture)
1216
{
17+
_output = output;
1318
}
1419

1520
[Theory]
@@ -913,18 +918,36 @@ public async Task DictionaryFetchAsync_HasContentByteArrayByteArray_HappyPath()
913918
Assert.True(fetchResponse is CacheDictionaryFetchResponse.Hit, $"Unexpected response: {fetchResponse}");
914919

915920
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!}");
919921
Assert.Equal(2, hitResponse.ValueDictionaryByteArrayByteArray!.Count);
920922

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+
921941
// 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}");
923946

924947
// Test field caching behavior
925948
Assert.Same(hitResponse.ValueDictionaryByteArrayByteArray, hitResponse.ValueDictionaryByteArrayByteArray);
926949
}
927-
950+
928951
[Fact]
929952
public async Task DictionaryDeleteAsync_DictionaryDoesNotExist_Noop()
930953
{
@@ -1161,4 +1184,14 @@ public async Task DictionaryLengthAsync_HappyPath()
11611184
var hitResponse = (CacheDictionaryLengthResponse.Hit)lengthResponse;
11621185
Assert.Equal(1, hitResponse.Length);
11631186
}
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+
}
11641197
}

0 commit comments

Comments
 (0)