public async Task TestGetTransactionsWithoutCallingAccountsFirst() { // Arrange int count = 0; mockCacheService.Setup(_ => _.GetCache()) .Returns(() => count++ <= 3 ? dummyCacheWithCodeAndAccessToken : dummyCacheWithAccounts); Cache cacheThatWasSet = null; mockCacheService.Setup(_ => _.SetCache(It.IsAny <Cache>())) .Callback <Cache>((cache) => cacheThatWasSet = cache); SetupHttpClientForGetTransactions(); SetupHttpClientFactory(); SetupHttpRequestService(); // Act List <Transaction> transactions = await httpRequestService.GetTransactionsAsync(); // Assert Assert.True(IsEqual(cacheThatWasSet.Transactions[0], dummyTransactions[0])); Assert.True(IsEqual(cacheThatWasSet.Transactions[1], dummyTransactions[1])); Assert.True(IsEqual(cacheThatWasSet.Transactions[2], dummyTransactions[0])); Assert.True(IsEqual(cacheThatWasSet.Transactions[3], dummyTransactions[1])); Assert.True(IsEqual(transactions[0], dummyTransactions[0])); Assert.True(IsEqual(transactions[1], dummyTransactions[1])); Assert.True(IsEqual(transactions[2], dummyTransactions[0])); Assert.True(IsEqual(transactions[3], dummyTransactions[1])); }