コード例 #1
0
        public void GetTransactions_ShouldReturn_ListOfTransactions()
        {
            // Arrange
            // Read in response data from file
            var dataPath = Path.Combine(_executingLocation, "..", "..", "..", "..", "..", "data",
                                        "mock-transaction-response.json");
            var responseJson = File.ReadAllText(dataPath);

            // Fake acount id
            const string accountId = "fake-account-id";

            // Setup mocks
            var mockHttpClient = SetupMockHttpClient($"accounts/{accountId}/transactions", responseJson);
            var mockCache      = SetupNullMockCache();

            // Instansiate TrueLayer DataApiClient
            var dataApiClient = new DataApiClient(mockHttpClient.Object, mockCache.Object);

            // Act
            var transactions = dataApiClient.GetAccountTransactions("token", accountId).GetAwaiter().GetResult();

            // Assert
            // HttpClient should be called
            mockHttpClient.Verify(m => m.GetData(It.IsAny <Uri>(), It.IsAny <string>()), Times.AtLeastOnce);
            // Cache get should be called
            mockCache.Verify(m => m.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.AtLeastOnce);
            // Cache set should be called
            mockCache.Verify(
                m => m.SetAsync(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>(),
                                It.IsAny <CancellationToken>()), Times.AtLeastOnce);

            Assert.AreEqual(6, transactions.Count);
            Assert.AreEqual("c9ce76686887de57c5fdf67451303ed1", transactions[0].TransactionId);
            Assert.AreEqual("039ccc24c3", transactions[0].MetaData.BankTransactionId);
        }