public void GivenOtfController_WhenTheShowPartialViewIsAccessedAndEmailsIsLessThanOne_ThenTheRightPartialViewAndRightViewModelIsReturned() { var pagedAppManCoEmails = new PagedResult <AppManCoEmail>(); var listAppManCoEmails = new List <AppManCoEmail>(); pagedAppManCoEmails.Results = listAppManCoEmails; pagedAppManCoEmails.ItemsPerPage = 10; this._applicationService.Setup(x => x.GetApplications()).Returns(new List <Application>()); this._manCoService.Setup(x => x.GetManCos()).Returns(new List <ManCo>()); this._docTypeService.Setup(x => x.GetDocTypes()).Returns(new List <DocType>()); this._appManCoEmailService.Setup(x => x.GetPagedAppManCoEmails(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(pagedAppManCoEmails); var paramModel = new OtfParameterModel(); paramModel.AppId = 2; paramModel.ManCoId = 4; paramModel.IsAjaxCall = true; paramModel.Page = 1; var result = _controller.Show(paramModel); var partialViewResult = result as PartialViewResult; result.Should().BeOfType <PartialViewResult>(); partialViewResult.Model.Should().BeOfType <OtfItemsViewModel>(); partialViewResult.TempData["comment"].Should().Be("No records for the selected criteria"); this._applicationService.Verify(x => x.GetApplications(), Times.AtLeastOnce()); this._manCoService.Verify(x => x.GetManCos(), Times.AtLeastOnce()); this._docTypeService.Verify(x => x.GetDocTypes(), Times.AtLeastOnce()); this._appManCoEmailService.Verify(x => x.GetPagedAppManCoEmails(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>()), Times.AtLeastOnce()); }
public ActionResult Show(OtfParameterModel parameterModel) { if (parameterModel.IsAjaxCall) { var applications = this._applicationService.GetApplications(); var manCos = this._manCoService.GetManCos(); var doctypes = this._docTypeService.GetDocTypes(); var appManCoEmails = this._appManCoEmailService.GetPagedAppManCoEmails( parameterModel.AccountNumber, parameterModel.AppId, parameterModel.ManCoId, parameterModel.Page, PageSize); var model = new OtfItemsViewModel(applications, manCos, doctypes); model.AddAppManCoEmails(appManCoEmails); if (model.AppManCoEmails.Count < 1) { TempData["comment"] = "No records for the selected criteria"; } return(this.PartialView("_PagedOtfResults", model)); } TempData["Page"] = parameterModel.Page; return(this.RedirectToAction("Index", "Otf")); }
public void GivenOtfController_WhenTheShowPartialViewIsAccessedAjaxCallIsFalse_ThenARedirectIsDoneToTheControllerIndex() { var paramModel = new OtfParameterModel(); paramModel.IsAjaxCall = false; paramModel.Page = 2; var result = _controller.Show(paramModel); var redirectToRouteResult = result as RedirectToRouteResult; result.Should().BeOfType <RedirectToRouteResult>(); redirectToRouteResult.RouteValues["action"].Should().Be("Index"); redirectToRouteResult.RouteValues["controller"].Should().Be("Otf"); }
public void GivenOtfController_WhenTheShowPartialViewIsAccessedAndEmailsIsMoreThanOne_ThenTheRightPartialViewAndRightViewModelIsReturned() { var pagedAppManCoEmails = new PagedResult <AppManCoEmail>(); var otfs = new List <AppManCoEmail>(); otfs.Add(new AppManCoEmail() { DocTypeId = 3, DocType = new DocType("code", "description"), ApplicationId = 5, Application = new Application("code", "description"), ManCoId = 7, ManCo = new ManCo("code", "description"), Id = 1, Email = "*****@*****.**", AccountNumber = "2547 963" }); otfs.Add(new AppManCoEmail() { DocTypeId = 3, DocType = new DocType("code2", "description2"), ApplicationId = 8, Application = new Application("code2", "description2"), ManCoId = 9, ManCo = new ManCo("code2", "description2"), Id = 2, Email = "*****@*****.**", AccountNumber = "2547 954" }); pagedAppManCoEmails.Results = otfs; pagedAppManCoEmails.ItemsPerPage = 10; this._applicationService.Setup(x => x.GetApplications()).Returns(new List <Application>()); this._manCoService.Setup(x => x.GetManCos()).Returns(new List <ManCo>()); this._docTypeService.Setup(x => x.GetDocTypes()).Returns(new List <DocType>()); this._appManCoEmailService.Setup(x => x.GetPagedAppManCoEmails(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(pagedAppManCoEmails); var paramModel = new OtfParameterModel(); paramModel.AppId = 2; paramModel.ManCoId = 4; paramModel.IsAjaxCall = true; paramModel.Page = 1; var result = _controller.Show(paramModel); var partialViewResult = result as PartialViewResult; result.Should().BeOfType <PartialViewResult>(); partialViewResult.Model.Should().BeOfType <OtfItemsViewModel>(); this._applicationService.Verify(x => x.GetApplications(), Times.AtLeastOnce()); this._manCoService.Verify(x => x.GetManCos(), Times.AtLeastOnce()); this._docTypeService.Verify(x => x.GetDocTypes(), Times.AtLeastOnce()); this._appManCoEmailService.Verify(x => x.GetPagedAppManCoEmails(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>()), Times.AtLeastOnce()); }