Skip to content

Commit

Permalink
fix: improve logging in disctionary test
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta committed Sep 6, 2024
1 parent 3945a8c commit 31ef2ed
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions tests/Integration/Momento.Sdk.Tests/Cache/DictionaryTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using Momento.Sdk.Internal.ExtensionMethods;
using Momento.Sdk.Requests;
Expand Down Expand Up @@ -920,24 +920,6 @@ public async Task DictionaryFetchAsync_HasContentByteArrayByteArray_HappyPath()
var hitResponse = (CacheDictionaryFetchResponse.Hit)fetchResponse;
Assert.Equal(2, hitResponse.ValueDictionaryByteArrayByteArray!.Count);

// Print dictionary content to output for debugging
_output.WriteLine("Hit Response Dictionary Contents:");
foreach (var kvp in hitResponse.ValueDictionaryByteArrayByteArray!)
{
_output.WriteLine($"Key: {BitConverter.ToString(kvp.Key)} | Value: {BitConverter.ToString(kvp.Value)}");
}

// Log if specific keys are missing
if (!hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field1))
{
_output.WriteLine($"Warning: Key {BitConverter.ToString(field1)} was not found in the dictionary.");
}

if (!hitResponse.ValueDictionaryByteArrayByteArray!.ContainsKey(field2))
{
_output.WriteLine($"Warning: Key {BitConverter.ToString(field2)} was not found in the dictionary.");
}

// Exercise DictionaryEquals extension
var actualDictionaryString = DictionaryToString(hitResponse.ValueDictionaryByteArrayByteArray!);
var expectedDictionaryString = DictionaryToString(contentDictionary);
Expand Down Expand Up @@ -1187,11 +1169,7 @@ public async Task DictionaryLengthAsync_HappyPath()

private string DictionaryToString(IDictionary<byte[], byte[]> dictionary)
{
var sb = new StringBuilder();
foreach (var kvp in dictionary)
{
sb.AppendLine($"Key: {BitConverter.ToString(kvp.Key)} | Value: {BitConverter.ToString(kvp.Value)}");
}
return sb.ToString();
return string.Join("; ", dictionary.Select(kvp =>
$"Key: {BitConverter.ToString(kvp.Key)} | Value: {BitConverter.ToString(kvp.Value)}"));
}
}

0 comments on commit 31ef2ed

Please sign in to comment.