Example #1
0
        public void GetTransactionsGroupedByAccount_Should_ReturnGroupedTransactions()
        {
            // Arrange
            // Read in response data from file
            var accountDataPath = Path.Combine(_executingLocation, "..", "..", "..", "..", "..", "data",
                                               "mock-accounts-response.json");
            var accountsJson        = File.ReadAllText(accountDataPath);
            var transactionDataPath = Path.Combine(_executingLocation, "..", "..", "..", "..", "..", "data",
                                                   "mock-transaction-response.json");
            var transactionJson = File.ReadAllText(transactionDataPath);

            // Deserialise test data to objects
            var accounts = TrueLayerResults <Account> .FromJson(accountsJson).Results;

            var transactions = TrueLayerResults <Transaction> .FromJson(transactionJson).Results;

            // Setup mock TrueLayer DataApiClient
            var mockClient = new Mock <IDataApiClient>();

            mockClient.Setup(m => m.GetAccounts("token")).ReturnsAsync(accounts);
            mockClient.Setup(m => m.GetAccountTransactions("token", It.IsAny <string>())).ReturnsAsync(transactions);

            var resultsModel = new Results(mockClient.Object);

            // Act
            var result = resultsModel.GetTransactionsGroupedByAccount("token").GetAwaiter().GetResult();

            // Assert
            Assert.AreEqual(2, result.Results.Count);
            Assert.AreEqual(6, result.Results[0].Count);
        }
Example #2
0
        public void GetTransactionSummaryGroupedByCategory_Should_ReturnGroupedTransactionSummaries()
        {
            // Arrange
            // Read in response data from file
            var accountDataPath = Path.Combine(_executingLocation, "..", "..", "..", "..", "..", "data",
                                               "mock-accounts-response.json");
            var accountsJson        = File.ReadAllText(accountDataPath);
            var transactionDataPath = Path.Combine(_executingLocation, "..", "..", "..", "..", "..", "data",
                                                   "mock-transaction-response.json");
            var transactionJson = File.ReadAllText(transactionDataPath);

            // Deserialise test data to objects
            var accounts = TrueLayerResults <Account> .FromJson(accountsJson).Results;

            var transactions = TrueLayerResults <Transaction> .FromJson(transactionJson).Results;

            // Setup mock TrueLayer DataApiClient
            var mockClient = new Mock <IDataApiClient>();

            mockClient.Setup(m => m.GetAccounts("token")).ReturnsAsync(accounts);
            mockClient.Setup(m => m.GetAccountTransactions("token", It.IsAny <string>())).ReturnsAsync(transactions);

            var resultsModel = new Results(mockClient.Object);

            // Act
            var result = resultsModel.GetTransactionSummaryGroupedByCategory("token").GetAwaiter().GetResult();

            Console.WriteLine(result.ToJson());

            // Assert
            Assert.AreEqual(4, result.Results.Count);
            Assert.AreEqual(-68.73,
                            result.Results.FirstOrDefault(e => e.TransactionCategory == "DIRECT_DEBIT").AverageAmount);
        }
        public async Task <List <Transaction> > GetAccountTransactions(string token, string accountId)
        {
            var endpoint = new Uri(HttpClient.BaseAddress, $"accounts/{accountId}/transactions");
            // Try getting the accounts from the cache
            var response = await Cache.GetStringAsync(endpoint + token);

            // If the cache response is null, then get the data from true layer api
            if (response == null)
            {
                response = await HttpClient.GetData(endpoint, token);

                // Store the result in the cache using the endpoint+token as the key
                await Cache.SetStringAsync(endpoint + token, response,
                                           new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15) });
            }

            return(TrueLayerResults <Transaction> .FromJson(response).Results);
        }