public async Task TransactionsTest_IdNull() { TransactionsVm vm = new TransactionsVm() { }; RedirectToActionResult result = (RedirectToActionResult)await this._controller.Transactions(vm, 1); Assert.AreEqual("Index", result.ActionName); Assert.AreEqual("MyAccounts", result.ControllerName); this.VerifyAll(); }
public async Task TransactionsTest_ModelStateInvalid() { TransactionsVm vm = new TransactionsVm() { }; string id = Guid.NewGuid().ToString(); this._controller.RouteData.Values.Add("id", id); this._controller.ModelState.AddModelError("Testing...", "Testing"); ViewResult result = (ViewResult)await this._controller.Transactions(vm, 1); Assert.AreSame(result.Model, vm); this.VerifyAll(); }
public async Task TransactionsTest_LowellRefNull() { TransactionsVm vm = new TransactionsVm() { }; Guid id = Guid.NewGuid(); this._controller.RouteData.Values.Add("id", id); this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(id)).Returns <string>(null); try { await this._controller.Transactions(vm, 1); } catch (Exception ex) { Assert.AreEqual("No lowell reference found in cache", ex.Message); this.VerifyAll(); return; } Assert.Fail("No exception thrown"); }
public async Task TransactionsTest_EverythingCached() { TransactionsVm vm = new TransactionsVm() { }; Guid id = Guid.NewGuid(); string lowellRef = "12345678"; this._controller.RouteData.Values.Add("id", id); Account account = new Account() { AccountReference = "12345678", OutstandingBalance = 999.99M, OriginalCompany = "OriginalCompany", }; List <Transaction> transactions = new List <Transaction>() { new Transaction() { Amount = 111.11M, Date = DateTime.Now.AddDays(-28), Description = "Description", Type = "Type", RollingBalance = 999.99M } }; List <TransactionVm> transactionsVm = new List <TransactionVm>() { new TransactionVm() { AmountText = "£111.11", DateText = DateTime.Now.AddDays(-28).ToString(), Description = "Description", RollingBalanceText = "£999.99", } }; this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(id)).Returns(lowellRef); this._sessionState.Setup(x => x.GetAccount(lowellRef)).Returns(account); this._sessionState.Setup(x => x.GetTransactions(lowellRef)).Returns(transactions); this._gtmService.Setup(x => x.RaiseTransactionsViewedEvent(vm, _caseflowUserId, "Regular Account")).Verifiable(); this._webActivityService.Setup(x => x.LogAllTransactionsViewed("12345678", this._caseflowUserId)).Returns(Task.CompletedTask); this._mapper.Setup(x => x.Map <List <Transaction>, List <TransactionVm> >(transactions)).Returns(transactionsVm); this._sessionState.Setup(x => x.GetLoggedInLowellRef()).Returns("12345678"); ViewResult result = (ViewResult)await this._controller.Transactions(vm, 1); Assert.AreSame(vm, result.Model); Assert.AreEqual("OriginalCompany", vm.AccountName); Assert.AreEqual(999.99M, vm.AccountBalance); Assert.AreEqual("12345678", vm.AccountReference); Assert.AreEqual(this._caseflowUserId, vm.LoggedInUserID); Assert.AreEqual("12345678", vm.LoggedInLowellRef); Assert.AreEqual(1, vm.PagedList.Count); Assert.AreEqual(1, vm.PagedList.TotalItemCount); Assert.AreEqual(1, vm.PagedList.PageNumber); Assert.AreEqual(5, vm.PagedList.PageSize); Assert.AreEqual(1, vm.PagedList.PageCount); this.VerifyAll(); }
public async Task <IActionResult> Transactions( TransactionsVm transactionsVm, int pageNumber = 1) { var value = RouteData.Values["id"]; if (value == null) { return(RedirectToAction("Index", "MyAccounts")); } Guid.TryParse(value.ToString(), out var id); if (!ModelState.IsValid) { return(View(transactionsVm)); } string lowellReference = ApplicationSessionState.GetLowellReferenceFromSurrogate(id); if (string.IsNullOrEmpty(lowellReference)) { throw new Exception("No lowell reference found in cache"); } Account account = ApplicationSessionState.GetAccount(lowellReference); if (account == null) { account = await _accountsService.GetAccount(LoggedInUserId, lowellReference); ApplicationSessionState.SaveAccount(account, lowellReference); } List <Transaction> transactions = ApplicationSessionState.GetTransactions(lowellReference); if (transactions == null) { transactions = await _transactionsService.GetTransactions(account.AccountReference); ApplicationSessionState.SaveTransactions(transactions, lowellReference); } if (transactions == null) { transactions = new List <Transaction>(); } transactionsVm.AccountName = account.OriginalCompany; transactionsVm.AccountBalance = account.OutstandingBalance; transactionsVm.AccountReference = account.AccountReference; _gtmService.RaiseTransactionsViewedEvent(transactionsVm, LoggedInUserId, "Regular Account"); await _webActivityService.LogAllTransactionsViewed(transactionsVm.AccountReference, LoggedInUserId); if (transactionsVm.FilterTransactions.DateFrom != null) { transactions = transactions.Where(x => x.Date >= transactionsVm.FilterTransactions.DateFrom).ToList(); } if (transactionsVm.FilterTransactions.DateTo != null) { transactions = transactions.Where(x => x.Date <= transactionsVm.FilterTransactions.DateTo).ToList(); } if (!string.IsNullOrEmpty(transactionsVm.FilterTransactions.KeyWord)) { transactions = transactions.Where(x => x.Description.ToLower().Contains(transactionsVm.FilterTransactions.KeyWord.ToLower())).ToList(); } transactions = transactions.OrderByDescending(x => x.Date).ToList(); if (!transactions.Any()) { transactionsVm.FilterTransactions.DateMessage = "No Results Found"; } transactionsVm.PagedList = _mapper.Map <List <Transaction>, List <TransactionVm> >(transactions).ToPagedList(pageNumber, _pageSize); transactionsVm.LoggedInUserID = LoggedInUserId; transactionsVm.LoggedInLowellRef = ApplicationSessionState.GetLoggedInLowellRef(); return(View(transactionsVm)); }