in DeviceBridgeTests/Providers/StorageProviderTests.cs [235:281]
public async Task ListHubCacheEntries()
{
using (ShimsContext.Create())
{
// Return 55 hubs.
var testSub = new Dictionary<string, object>()
{
{ "DeviceId", "test-device" },
{ "Hub", "test-hub" },
};
var allHubs = Enumerable.Repeat(testSub, 55).ToList();
List<Dictionary<string, object>> currentPage = null;
Dictionary<string, object> currentHub = null;
ShimOpen();
// Get the next page of 10 items when ExecuteReaderAsync is called.
ShimExecuteReader("getHubCacheEntriesPaged", null, cmd =>
{
var nextPageSize = allHubs.Count < 10 ? allHubs.Count : 10;
currentPage = allHubs.Take(nextPageSize).ToList();
allHubs.RemoveRange(0, nextPageSize);
Assert.AreEqual(CommandType.StoredProcedure, cmd.CommandType);
});
// Get the next item when ReadAsync is called.
ShimRead(() =>
{
if (currentPage.Count > 0)
{
currentHub = currentPage[0];
currentPage.RemoveAt(0);
return true;
}
else
{
return false;
}
});
ShimItemGetString(() => currentHub);
var result = await _storageProvider.ListHubCacheEntries(LogManager.GetCurrentClassLogger());
Assert.AreEqual(55, result.FindAll(s => s.DeviceId == "test-device" && s.Hub == "test-hub").Count);
}
}