Пример #1
0
        public async Task <IActionResult> Index()
        {
            string caseflowUserId = GetCaseflowUserId();

            List <AccountSummary> accountSummaries = await _accountsService.GetAccounts(caseflowUserId);

            List <string> lowellReferences = accountSummaries.Select(x => x.AccountReference).ToList();
            IDictionary <string, Guid> surrogateKeysByLowellReference = ApplicationSessionState.AddLowellReferenceSurrogateKeys(lowellReferences);

            Guid?  lowellFinancialAccountSurrogateKey = null;
            string loggedInLowellRef = null;

            foreach (AccountSummary account in accountSummaries)
            {
                if (!account.AccountStatusIsWithSolicitors && lowellFinancialAccountSurrogateKey == null)
                {
                    lowellFinancialAccountSurrogateKey = surrogateKeysByLowellReference[account.AccountReference];
                    loggedInLowellRef = ApplicationSessionState.GetLowellReferenceFromSurrogate(lowellFinancialAccountSurrogateKey.Value);
                }
            }

            CustomerSummary customerSummary = await _accountsService.CreateCustomerSummary(accountSummaries, loggedInLowellRef, surrogateKeysByLowellReference);

            MyAccountsVm vm = _mapper.Map <CustomerSummary, MyAccountsVm>(customerSummary);

            if (TempData != null && TempData.ContainsKey("GTMEvents"))
            {
                vm.GtmEvents = JsonConvert.DeserializeObject <List <GtmEvent> >(TempData["GTMEvents"].ToString());
                TempData.Remove("GTMEvents");
            }

            _gtmService.RaiseMyAccountsPageViewedEvent(vm, LoggedInUserId);

            await _webActivityService.LogMyAccountsPageViewed(loggedInLowellRef, LoggedInUserId);

            return(View(vm));
        }
        public async Task IndexTest()
        {
            List <AccountSummary> accountSummaries = new List <AccountSummary>()
            {
                new AccountSummary()
                {
                    AccountReference = "11111111", OutstandingBalance = 111.11M
                },
                new AccountSummary()
                {
                    AccountReference = "22222222", OutstandingBalance = 222.22M
                },
                new AccountSummary()
                {
                    AccountReference = "33333333", OutstandingBalance = 333.33M
                },
                new AccountSummary()
                {
                    AccountReference = "44444444", OutstandingBalance = 444.44M
                },
                new AccountSummary()
                {
                    AccountReference = "55555555", OutstandingBalance = 555.55M
                }
            };

            Dictionary <string, Guid> surrogateKeysByLowellReference = new Dictionary <string, Guid>()
            {
                { "11111111", Guid.NewGuid() },
                { "22222222", Guid.NewGuid() },
                { "33333333", Guid.NewGuid() },
                { "44444444", Guid.NewGuid() },
                { "55555555", Guid.NewGuid() },
            };

            CustomerSummary customerSummary = new CustomerSummary()
            {
                Accounts = accountSummaries,
                SurrogateKeysByLowellReference = surrogateKeysByLowellReference,
                IncomeAndExpenditure           = new IncomeAndExpenditure()
            };

            MyAccountsVm myAccountsVm = new MyAccountsVm()
            {
                Accounts = new List <AccountSummaryVm>()
                {
                    new AccountSummaryVm()
                    {
                        AccountReferenceText = "11111111", OutstandingBalanceText = "£111.11"
                    },
                    new AccountSummaryVm()
                    {
                        AccountReferenceText = "22222222", OutstandingBalanceText = "£222.22"
                    },
                    new AccountSummaryVm()
                    {
                        AccountReferenceText = "33333333", OutstandingBalanceText = "£333.33"
                    },
                    new AccountSummaryVm()
                    {
                        AccountReferenceText = "44444444", OutstandingBalanceText = "£444.44"
                    },
                    new AccountSummaryVm()
                    {
                        AccountReferenceText = "55555555", OutstandingBalanceText = "£555.55"
                    },
                },
            };

            this._accountsService.Setup(x => x.GetAccounts(this._caseflowUserId)).Returns(Task.FromResult(accountSummaries));
            this._sessionState.Setup(x => x.AddLowellReferenceSurrogateKeys(It.Is <List <string> >(a =>
                                                                                                   a.Count == 5 && a[0] == "11111111" && a[1] == "22222222" && a[2] == "33333333" && a[3] == "44444444" && a[4] == "55555555")))
            .Returns(surrogateKeysByLowellReference);
            this._sessionState.Setup(x => x.GetLowellReferenceFromSurrogate(surrogateKeysByLowellReference["11111111"]))
            .Returns("11111111");
            this._accountsService.Setup(x => x.CreateCustomerSummary(accountSummaries, "11111111", surrogateKeysByLowellReference))
            .Returns(Task.FromResult(customerSummary));
            this._mapper.Setup(x => x.Map <CustomerSummary, MyAccountsVm>(customerSummary)).Returns(myAccountsVm);
            this._gtmService.Setup(x => x.RaiseMyAccountsPageViewedEvent(myAccountsVm, this._caseflowUserId)).Verifiable();
            this._webActivityService.Setup(x => x.LogMyAccountsPageViewed("11111111", this._caseflowUserId)).Returns(Task.CompletedTask);

            ViewResult result = (ViewResult)await this._controller.Index();

            Assert.AreSame(myAccountsVm, result.Model);

            this._gtmService.Verify(x => x.RaiseMyAccountsPageViewedEvent(myAccountsVm, this._caseflowUserId), Times.Once);
            this._webActivityService.Verify(x => x.LogMyAccountsPageViewed("11111111", this._caseflowUserId), Times.Once);

            this.VerifyAll();
        }