Esempio n. 1
0
        public void TestGetUserMetrics_CalculatesAverageCorrectlyForSingleCategory()
        {
            var accountRepo       = new Mock <IAccountRepository>();
            var transactionRepo   = new Mock <ITransactionRepository>();
            var fakeToken         = "fake";
            var fakeAccountId     = "123";
            var fakeTransactionId = "456";
            var fakeCategory      = "cat1";
            var fakeAccount       = new Account {
                account_id = fakeAccountId
            };
            var fakeAccountResponse = new AccountRootObject {
                results = new List <Account> {
                    fakeAccount
                }
            };
            var accountTransactionObject = new AccountTransaction
            {
                AccountId     = fakeAccountId,
                TransactionId = fakeTransactionId,
                Amount        = 10,
                Category      = fakeCategory
            };

            var accountTransactionObject2 = new AccountTransaction
            {
                AccountId     = fakeAccountId,
                TransactionId = fakeTransactionId,
                Amount        = 20,
                Category      = fakeCategory
            };

            var listOfAccountTransactions = new List <AccountTransaction>();

            listOfAccountTransactions.Add(accountTransactionObject);
            listOfAccountTransactions.Add(accountTransactionObject2);

            var mockResponse = new RestResponse
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = JsonConvert.SerializeObject(fakeAccountResponse)
            };

            accountRepo.Setup(a => a.GetAllAccounts(fakeToken)).Returns(mockResponse);
            transactionRepo.Setup(t => t.GetAccountTransactionsByAccounts(new List <string> {
                fakeAccountId
            })).Returns(listOfAccountTransactions);

            var controller  = new TransactionController(accountRepo.Object, transactionRepo.Object);
            var result      = controller.UserMetrics(fakeToken);
            var metricsList = result.Result as OkObjectResult;
            var final       = (List <UserTransactionMetrics>)metricsList.Value;

            Assert.AreEqual(1, final.Count);
            Assert.AreEqual(20, final[0].MaximumTransaction);
            Assert.AreEqual(10, final[0].MinimumTransaction);
            Assert.AreEqual(15, final[0].AverageTransaction);
        }
Esempio n. 2
0
        public void TestGetTransactions_RecordExistsInDb_DoesNotGetAdded()
        {
            var accountRepo       = new Mock <IAccountRepository>();
            var transactionRepo   = new Mock <ITransactionRepository>();
            var fakeToken         = "fake";
            var fakeAccountId     = "123";
            var fakeTransactionId = "456";
            var fakeAccount       = new Account {
                account_id = fakeAccountId
            };
            var fakeTransaction = new Transaction {
                transaction_id = fakeTransactionId
            };
            var fakeAccountResponse = new AccountRootObject {
                results = new List <Account> {
                    fakeAccount
                }
            };
            var fakeTransactionResponse = new TransactionRootObject {
                results = new List <Transaction> {
                    fakeTransaction
                }
            };
            var fakeAccountTransaction = new AccountTransaction
            {
                Id            = new System.Guid(),
                AccountId     = fakeAccountId,
                TransactionId = fakeTransactionId
            };

            var mockResponse = new RestResponse
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = JsonConvert.SerializeObject(fakeAccountResponse)
            };

            var mockTransactionResponse = new RestResponse
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = JsonConvert.SerializeObject(fakeTransactionResponse)
            };

            accountRepo.Setup(a => a.GetAllAccounts(fakeToken)).Returns(mockResponse);
            transactionRepo.Setup(a => a.GetAllTransactions(fakeAccountId, fakeToken)).Returns(mockTransactionResponse);
            transactionRepo.Setup(a => a.GetAccountTransaction(fakeAccountId, fakeTransactionId)).Returns(fakeAccountTransaction);

            var controller = new TransactionController(accountRepo.Object, transactionRepo.Object);

            controller.Get(fakeToken);
            transactionRepo.Verify(a => a.AddAccountTransaction(It.IsAny <AccountTransaction>()), Times.Never);
        }