Skip to content

Commit

Permalink
chore: removing encoding from get response (#87)
Browse files Browse the repository at this point in the history
We have decided that the convenience methods will use UTF-8.
  • Loading branch information
malandis authored Jul 25, 2022
1 parent 781748c commit 37bec19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Momento/Responses/CacheGetMultiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public List<CacheGetStatus> Status
get => Responses.Select(response => response.Status).ToList();
}

public List<string?> Strings
public List<string?> Strings()
{
get => Responses.Select(response => response.String()).ToList();
return Responses.Select(response => response.String()).ToList();
}

public List<byte[]?> Bytes
Expand Down
5 changes: 2 additions & 3 deletions Momento/Responses/CacheGetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ public CacheGetResponse(_GetResponse response)
Bytes = (Status == CacheGetStatus.HIT) ? response.CacheBody.ToByteArray() : null;
}

public string? String(Encoding? encoding = null)
public string? String()
{
encoding ??= Encoding.UTF8;
if (Bytes == null)
{
return null;
}
return encoding.GetString(Bytes);
return Encoding.UTF8.GetString(Bytes);
}

private static CacheGetStatus From(ECacheResult result)
Expand Down
20 changes: 10 additions & 10 deletions MomentoIntegrationTest/SimpleCacheDataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public async void GetMultiAsync_KeysAreBytes_HappyPath()
List<byte[]> keys = new() { Utils.Utf8ToBytes(key1), Utils.Utf8ToBytes(key2) };

CacheGetMultiResponse result = await client.GetMultiAsync(CacheName, keys);
string? stringResult1 = result.Strings[0];
string? stringResult2 = result.Strings[1];
string? stringResult1 = result.Strings()[0];
string? stringResult2 = result.Strings()[1];
Assert.Equal(value1, stringResult1);
Assert.Equal(value2, stringResult2);
}
Expand All @@ -157,8 +157,8 @@ public async void GetMultiAsync_KeysAreBytes_HappyPath2()
client.Set(CacheName, key2, value2);

CacheGetMultiResponse result = await client.GetMultiAsync(CacheName, key1, key2);
string? stringResult1 = result.Strings[0];
string? stringResult2 = result.Strings[1];
string? stringResult1 = result.Strings()[0];
string? stringResult2 = result.Strings()[1];
Assert.Equal(value1, stringResult1);
Assert.Equal(value2, stringResult2);
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public async void GetMultiAsync_KeysAreString_HappyPath()
List<string> keys = new() { key1, key2, "key123123" };
CacheGetMultiResponse result = await client.GetMultiAsync(CacheName, keys);

Assert.Equal(result.Strings, new string[] { value1, value2, null! });
Assert.Equal(result.Strings(), new string[] { value1, value2, null! });
Assert.Equal(result.Status, new CacheGetStatus[] { CacheGetStatus.HIT, CacheGetStatus.HIT, CacheGetStatus.MISS });
}

Expand Down Expand Up @@ -420,8 +420,8 @@ public void GetMulti_KeysAreBytes_HappyPath()
List<byte[]> keys = new() { Utils.Utf8ToBytes(key1), Utils.Utf8ToBytes(key2) };

CacheGetMultiResponse result = client.GetMulti(CacheName, keys);
string? stringResult1 = result.Strings[0];
string? stringResult2 = result.Strings[1];
string? stringResult1 = result.Strings()[0];
string? stringResult2 = result.Strings()[1];
Assert.Equal(value1, stringResult1);
Assert.Equal(value2, stringResult2);
}
Expand All @@ -437,8 +437,8 @@ public void GetMulti_KeysAreBytes_HappyPath2()
client.Set(CacheName, key2, value2);

CacheGetMultiResponse result = client.GetMulti(CacheName, key1, key2);
string? stringResult1 = result.Strings[0];
string? stringResult2 = result.Strings[1];
string? stringResult1 = result.Strings()[0];
string? stringResult2 = result.Strings()[1];
Assert.Equal(value1, stringResult1);
Assert.Equal(value2, stringResult2);
}
Expand Down Expand Up @@ -468,7 +468,7 @@ public void GetMulti_KeysAreString_HappyPath()
List<string> keys = new() { key1, key2, "key123123" };
CacheGetMultiResponse result = client.GetMulti(CacheName, keys);

Assert.Equal(result.Strings, new string[] { value1, value2, null! });
Assert.Equal(result.Strings(), new string[] { value1, value2, null! });
Assert.Equal(result.Status, new CacheGetStatus[] { CacheGetStatus.HIT, CacheGetStatus.HIT, CacheGetStatus.MISS });
}

Expand Down

0 comments on commit 37bec19

Please sign in to comment.