in DeviceBridgeTests/Providers/StorageProviderTests.cs [36:82]
public async Task ListAllSubscriptionsOrderedByDeviceId()
{
using (ShimsContext.Create())
{
_encriptionServiceMock.Invocations.Clear();
// Return 55 subscriptions.
var testDateTime = DateTime.Now;
var testSub = GetTestSubscription(testDateTime);
var allSubs = Enumerable.Repeat(testSub, 55).ToList();
List<Dictionary<string, object>> currentPage = null;
Dictionary<string, object> currentSub = null;
ShimOpen();
// Get the next page of 10 items when ExecuteReaderAsync is called.
ShimExecuteReader("getDeviceSubscriptionsPaged", null, cmd =>
{
var nextPageSize = allSubs.Count < 10 ? allSubs.Count : 10;
currentPage = allSubs.Take(nextPageSize).ToList();
allSubs.RemoveRange(0, nextPageSize);
Assert.AreEqual(CommandType.StoredProcedure, cmd.CommandType);
});
// Get the next item when ReadAsync is called.
ShimRead(() =>
{
if (currentPage.Count > 0)
{
currentSub = currentPage[0];
currentPage.RemoveAt(0);
return true;
}
else
{
return false;
}
});
ShimItemGetString(() => currentSub);
var result = await _storageProvider.ListAllSubscriptionsOrderedByDeviceId(LogManager.GetCurrentClassLogger());
Assert.AreEqual(55, result.FindAll(s => s.DeviceId == "test-device" && s.CallbackUrl == "http://test" && s.SubscriptionType == DeviceSubscriptionType.DesiredProperties && s.CreatedAt == testDateTime).Count);
_encriptionServiceMock.Verify(p => p.Decrypt(It.IsAny<Logger>(), It.IsAny<string>()), Times.Exactly(55));
}
}