Esempio n. 1
0
        public void GivenASubmitController_WhenCreatingAJob_AndTheFileHasAlreadyBeenProcessed_ThenAJsonResultIsReturnedWithTheRedirectUrl()
        {
            this.controller.Url = new UrlHelper(new RequestContext(MockHttpContext.Object, new RouteData()), Routes);

            this.SetControllerContext(this.controller);
            MockHttpContext.SetupGet(x => x.Session["Environment"]).Returns("environment");

            this.jobService.Setup(
                j =>
                j.CreateJob(
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <List <String> >(),
                    It.IsAny <String>(),
                    It.IsAny <Boolean>(),
                    It.IsAny <Boolean>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>())).Throws(new DocProcessingFileAlreadyProcessedException());

            var result     = this.controller.Create(new CreateJobViewModel());
            var jsonResult = result as JsonResult;

            jsonResult.Data.ToString().Should().Be("{ Url = , Error = File has already been processed }");
        }
Esempio n. 2
0
        public void GivenAValidUserIdAndPassword_WhenILoginAndHaveAPreferredLandingPage_IGetRedirectedToMyDefaultLandingPage()
        {
            var userMock = new Mock <ApplicationUser>();

            this.userService.Setup(m => m.GetApplicationUser("username", "password")).Returns(userMock.Object);
            userMock.SetupGet(u => u.IsApproved).Returns(true);
            userMock.SetupGet(u => u.IsLockedOut).Returns(false);
            userMock.SetupGet(u => u.PreferredLandingPage).Returns(LandingPage.JobsView);
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");

            this.userService.Setup(x => x.CheckForPassRenewal(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(false);
            this.userService.Setup(x => x.SignIn(userMock.Object, false));
            this.userService.Setup(x => x.UpdateUserLastLogindate(It.IsAny <String>()));

            SetControllerContext(this.sessionController);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(_sessionValue);

            var result =
                this.sessionController.Create(new LoginUserViewModel {
                Username = "******", Password = "******"
            }, string.Empty) as
                RedirectToRouteResult;

            this.userService.Verify(m => m.GetApplicationUser(It.IsAny <String>(), It.IsAny <String>()), Times.AtLeastOnce);
            this.userService.Verify(x => x.CheckForPassRenewal(It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.AtLeastOnce);
            this.userService.Verify(x => x.SignIn(userMock.Object, false), Times.AtLeastOnce);
            this.userService.Verify(x => x.UpdateUserLastLogindate(It.IsAny <String>()), Times.AtLeastOnce);

            result.Should().NotBeNull();
            result.RouteValues["controller"].Should().Be("Jobs");
            result.RouteValues["action"].Should().Be("Index");
        }
Esempio n. 3
0
        public void GivenAValidViewModel_WhenITryToDeleteADocumentInTheBasket_ThenIGetTheCorrectView()
        {
            SetControllerContext(_cartItemController);
            MockHttpContext.SetupGet(x => x.Session["CartId"]).Returns("testUser");
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            MockHttpContext.SetupGet(x => x.Session["testUser"]).Returns("testUser");

            List <RemoveCartItemViewModel> removeCartItemViewModel = new List <RemoveCartItemViewModel>()
            {
                new RemoveCartItemViewModel()
                {
                    DocumentId = "guid",
                    Selected   = true
                }
            };

            _cartItemService.Setup(c => c.RemoveItem("guid", "testUser"));

            RemoveCartItemsViewModel removeCartItemsViewModel = new RemoveCartItemsViewModel
            {
                RemoveCartItemViewModel = removeCartItemViewModel
            };

            var result = (PartialViewResult)_cartItemController.RemoveFromCart(removeCartItemsViewModel);

            result.Model.Should().BeOfType <CartItemSummaryViewModel>();
            result.ViewName.Should().Be("_CartSummary");
        }
        public void SetUp()
        {
            _approvalService    = new Mock <IApprovalService>();
            _documentService    = new Mock <IDocumentService>();
            _logger             = new Mock <ILogger>();
            _approvalController = new ApprovalController(_approvalService.Object, _documentService.Object, _logger.Object);

            _approveDocumentsViewModel = new ApproveDocumentsViewModel
            {
                ApproveDocumentViewModel = new List <ApproveDocumentViewModel>
                {
                    new ApproveDocumentViewModel
                    {
                        DocumentId = "guid1",
                        Selected   = true
                    },
                    new ApproveDocumentViewModel
                    {
                        DocumentId = "guid2",
                        Selected   = false
                    }
                },
                Grid = "grid",
                Page = "1"
            };

            SetControllerContext(_approvalController);
            MockHttpContext.SetupGet(x => x.Session["CartId"]).Returns("testUser");
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            MockHttpContext.SetupGet(x => x.Session["testUser"]).Returns("testUser");
        }
Esempio n. 5
0
        public void GivenAValidAddUserViewModel_WhenITryToPerformACreateUser_ThenItCreatesAndReturnsTheIndexView()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            var addModel = new AddUserViewModel {
            };

            this.userService.Setup(x => x.CreateUser(
                                       It.IsAny <String>(),
                                       It.IsAny <String>(),
                                       It.IsAny <String>(),
                                       It.IsAny <String>(),
                                       It.IsAny <String>()));

            ActionResult result = this.userController.Create(addModel);

            result.Should().BeOfType <RedirectToRouteResult>();

            this.userService.Verify(x => x.CreateUser(
                                        It.IsAny <String>(),
                                        It.IsAny <String>(),
                                        It.IsAny <String>(),
                                        It.IsAny <String>(),
                                        It.IsAny <String>()),
                                    Times.AtLeastOnce);
        }
Esempio n. 6
0
        public void GivenALockedOutUser_WhenITryToLogIn_IGetTheLockedOutView()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            var result = this.sessionController.LockedOut() as ActionResult;

            result.Should().BeOfType <ViewResult>();
        }
Esempio n. 7
0
        public void GivenAValidCartId_WhenITryToExportToZip_ThenIGetTheCorrectResult()
        {
            SetControllerContext(_cartItemController);
            MockHttpContext.SetupGet(x => x.Session["CartId"]).Returns("testUser");
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            MockHttpContext.SetupGet(x => x.Session["testUser"]).Returns("testUser");

            var zipFilePath = "files/exportFiles/err6f87r1.zip";

            _exportFileService.Setup(e => e.ExportToZip(It.IsAny <List <string> >())).Returns(zipFilePath);

            _cartItemService.Setup(e => e.GetCart("cartId")).Returns(new List <CartItem>()
            {
                new CartItem()
                {
                    Document = new Document()
                    {
                        DocumentId = "docId"
                    }
                }
            });

            this._cartItemService.Setup(x => x.RemoveItem(It.IsAny <string>(), "testUser"));

            var result     = this._cartItemController.ExportBasketToZip("cartId");
            var jsonResult = result as JsonResult;

            result.Should().BeOfType <JsonResult>();
            var jsonFilevalue = jsonResult.Data.GetType().GetProperty("file").GetValue(jsonResult.Data, null);

            jsonFilevalue.ShouldBeEquivalentTo(zipFilePath);

            _exportFileService.Verify(e => e.ExportToZip(It.IsAny <List <string> >()), Times.AtLeastOnce);
            this._cartItemService.Verify(x => x.RemoveItem(It.IsAny <string>(), "testUser"), Times.AtMost(5));
        }
        public void GivenAValidUserAndPassword_WhenILogin_ThenIGetRedirectedToTheDashboardPage()
        {
            var userMock = new Mock <ApplicationUser>();

            _userService.Setup(m => m.GetApplicationUser("username", "password")).Returns(userMock.Object);
            userMock.SetupGet(u => u.IsApproved).Returns(true);
            userMock.SetupGet(u => u.IsLockedOut).Returns(false);

            this._userService.Setup(x => x.CheckForPassRenewal(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(false);
            this._userService.Setup(x => x.SignIn(userMock.Object, false));
            this._userService.Setup(x => x.UpdateUserLastLogindate(It.IsAny <string>()));
            this._securityAnswerService.Setup(x => x.HasSecurityAnswers(It.IsAny <string>())).Returns(true);

            SetControllerContext(_sessionController);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(_sessionValue);

            var result =
                _sessionController.Create(new LoginUserViewModel {
                Username = "******", Password = "******"
            }, string.Empty) as
                RedirectToRouteResult;

            _userService.Verify(m => m.GetApplicationUser(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
            this._userService.Verify(x => x.CheckForPassRenewal(It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.AtLeastOnce);
            this._userService.Verify(x => x.SignIn(userMock.Object, false), Times.AtLeastOnce);
            this._userService.Verify(x => x.UpdateUserLastLogindate(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce);
            this._securityAnswerService.Verify(x => x.HasSecurityAnswers(It.IsAny <string>()), Times.AtLeastOnce);

            result.Should().NotBeNull();
            result.RouteValues["controller"].Should().Be("Dashboard");
            result.RouteValues["action"].Should().Be("Index");
        }
Esempio n. 9
0
        public void GivenAnInvalidEditUserViewModel_WhenITryToPerformAnEdit_AnEditIsNotDonAndTheCurrentPageIsReturned()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            var editModel = new EditUserViewModel(new ApplicationUser
            {
                FirstName = "ryan",
                LastName  = "Otherman",
                UserName  = "******",
                Id        = "ksdhsdids"
            });

            const string errorMess = "Email field must not be empty";

            this.userController.ModelState.AddModelError("Email", errorMess);

            ActionResult result     = this.userController.Edit("Save", editModel);
            var          viewResult = (ViewResult)result;

            result.Should().BeOfType <ViewResult>();
            viewResult.TempData["comment"].ToString().ShouldBeEquivalentTo(errorMess);

            this.appEnvironmentService.Verify(d => d.GetAppEnvironments(It.IsAny <String>()), Times.AtLeastOnce);
            this.userService.Verify(x => x.GetApplicationUser(It.IsAny <String>()), Times.AtLeastOnce);
            this.groupService.Verify(x => x.GetGroups(), Times.AtLeastOnce);
            this.identityRoleService.Verify(x => x.GetRoles(), Times.AtLeastOnce);
            this.identityRoleService.Verify(x => x.GetRoles(It.IsAny <String>()), Times.AtLeastOnce);
            this.userGroupService.Verify(x => x.GetUserGroups(It.IsAny <String>()), Times.AtLeastOnce);
        }
Esempio n. 10
0
        public void GivenAnEnvironmentControllerForAUserWhoHasNotChangedTheEnvironment_AndNotSpecifiedAPreferedLandingPAge_WhenILogIn_IGetMyTheLowestEnviromentIHaveAccessTo()
        {
            this.SetControllerContext(this.controller);
            MockHttpContext.SetupGet(x => x.Session["Environment"]).Returns(null);

            this.userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser()
            {
                Id = "guid"
            });
            this.appEnvironmentService.Setup(d => d.GetAppEnvironments("guid"))
            .Returns(
                new List <AppEnvironment>()
            {
                new AppEnvironment()
                {
                    Name = "UAT", AppEnvironmentID = 1
                },
                new AppEnvironment()
                {
                    Name = "Production", AppEnvironmentID = 2
                }
            });

            var result = (PartialViewResult)this.controller.Index();
            var model  = (EnvironmentViewModel)result.Model;

            model.SelectedEnvironment.Should().Be("UAT");
            result.ViewName.Should().Be("_environment");
        }
        public void GivenADocumentController_WhenICallItsSearchCriteraMethod_ThenItReturnsTheCorrectView()
        {
            _controller = new DocumentController(
                _documentService.Object,
                _userService.Object,
                _manCoService.Object,
                _logger.Object);

            _userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser());
            _manCoService.Setup(x => x.GetManCosByUserId(It.IsAny <string>())).Returns(new List <ManCo>());
            _documentService.Setup(d => d.GetDocument(It.IsAny <string>())).Returns(new Document
            {
                GridRun = new GridRun
                {
                    Grid = "grid"
                }
            });

            _documentService.Setup(
                d =>
                d.GetDocuments(
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <List <string> >(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>())).Returns(_documentsIndexed);

            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = (ViewResult)_controller.Search(new SearchViewModel());

            _userService.Verify(x => x.GetApplicationUser(), Times.Once);

            _manCoService.Verify(x => x.GetManCosByUserId(It.IsAny <string>()), Times.Once);

            result.Model.Should().BeOfType <DocumentsViewModel>();
            var model = (DocumentsViewModel)result.Model;

            model.Documents.Should().OnlyContain(d => d.Grid == "grid");

            _controller.TempData.Should().NotBeNull();
            _controller.TempData["valid"].Should().Be("Show filter");
        }
Esempio n. 12
0
        public void GivenASearchController_WhenTheIndexPageIsAccessed_ThenTheIndexViewShouldContainTheModel()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = (PartialViewResult)_controller.Index();

            result.Model.Should().BeOfType <SearchViewModel>();
        }
Esempio n. 13
0
        public void GivenALoggedInUser_WhenILoginOut_ThenILoginView()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");
            MockHttpContext.Setup(x => x.Session.Clear());

            var result = this.sessionController.Remove() as RedirectToRouteResult;

            result.RouteValues["action"].Should().Be("New");
        }
        public void GivenADashBoardController_WhenTheIndexPageIsAccess_ThenTheIndexVieWModelIsReturned()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            var result = _controller.Index(new ManCoFilterViewModel());

            result.Should().BeOfType <ViewResult>();
        }
        public void GivenADashBoardController_WhenTheIndexPageIsAccessed_ThenTheIndexViewShouldContainTheModel()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            var result = (ViewResult)_controller.Index(new ManCoFilterViewModel());

            result.Model.Should().BeOfType <DashboardViewModel>();
        }
        public void GivenNoAuthenticatedUser_WhenILogin_ThenIGetTheLoginView()
        {
            SetControllerContext(_sessionController);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(null);

            MockHttpContext.Setup(h => h.User).Returns(new UserViewModel());
            ActionResult result = _sessionController.New();

            result.Should().BeOfType <ViewResult>();
        }
        public void GivenADashboardController_WhenIViewTheDashboardPage_AndThereAreRecentExceptions_ThenTheViewModelContainsExceptions()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(null);

            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            var model = result.Model as DashboardViewModel;

            model.DashboardExceptionViewModels.Should().HaveCount(5);
        }
        public void GivenADashBoardController_WhenIViewTheIndexPage_ThenTheViewModelContainsTheCorrectNumberOfExceptionGridRuns()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            var model = result.Model as DashboardViewModel;

            model.DashboardExceptionViewModels.Should().HaveCount(5);
        }
Esempio n. 19
0
        public void GivenASearchController_WhenIGoToTheResetController_ThenIGetTheRedirectView()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = _controller.Reset() as RedirectToRouteResult;

            result.Should().NotBeNull();
            result.RouteValues["action"].Should().Be("Index");
            result.RouteValues["controller"].Should().Be("Document");
        }
Esempio n. 20
0
        public void GivenASearchController_WhenIViewTheIndexPage_AndModelIsNotInSesion_ThenTheViewModelContainsTheCorrectNumberOfManCos()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = _controller.Index() as PartialViewResult;

            var model = result.Model as SearchViewModel;

            model.ManCos.Should().HaveCount(1);
        }
        public void GivenADashboardController_WhenIViewTheDashboardPage_AndThereAreNoFilesProcessing_ThenTheViewModelContainsNoProcessingFiles()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["LastLoggedInDate"]).Returns(null);

            _gridRunService.Setup(x => x.GetProcessing()).Returns(new List <GridRun>());
            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            var model = result.Model as DashboardViewModel;

            model.DashboardProcessingViewModels.Should().HaveCount(0);
        }
Esempio n. 22
0
        public void GivenAnEnvironmentController_WhenIChangeMyEnvironment_MyEnvironmentIsChanged()
        {
            this.SetControllerContext(this.controller);
            MockHttpContext.SetupGet(x => x.Session["Environment"]).Returns(null);

            RouteTable.Routes.Add("TestRoutes", new Route("{controller}/{action}", new MvcRouteHandler()));
            var result = (JsonResult)this.controller.Change("UAT", "/Jobs/View");

            result.Data.ToString().Should().Be(@"{ Url = /Jobs/View, Error =  }");
            result.Should().NotBeNull();
            result.Should().BeOfType <JsonResult>();
        }
Esempio n. 23
0
        public void GivenAValidEditUserViewModel_WhenITryToPerformAnEdit_ThenItEditsAndReturnsTheHomeController()
        {
            MockHttpContext.SetupGet(x => x.User.Identity.Name).Returns("testUser");

            var editModel = new EditUserViewModel(new ApplicationUser
            {
                Email     = "*****@*****.**",
                FirstName = "ryan",
                LastName  = "Otherman",
                UserName  = "******"
            });

            editModel.SelectedGroups = new List <Int32>();
            editModel.SelectedRoles  = new List <String>();


            this.userService.Setup(
                x =>
                x.Updateuser(
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <Boolean>(),
                    It.IsAny <Int32>(), It.IsAny <Boolean>()));

            this.identityRoleService.Setup(x => x.AddRolesToUser(It.IsAny <String>(), new List <string>()));
            this.userGroupService.Setup(x => x.AddGroupsToUser(It.IsAny <String>(), new List <int>()));

            ActionResult result = this.userController.Edit("Save", editModel);

            result.Should().BeOfType <RedirectToRouteResult>();

            this.userService.Verify(
                x =>
                x.Updateuser(
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <String>(),
                    It.IsAny <Boolean>(),
                    It.IsAny <Int32>(), It.IsAny <Boolean>()),
                Times.Once);
        }
        public void GivenADocumentController_WhenICallItsSearchCriteraMethod_AndThereAreTooManyDocumentsReurned_ThenIGetTheCorrectErrorMessage()
        {
            _controller = new DocumentController(
                _documentService.Object,
                _userService.Object,
                _manCoService.Object,
                _logger.Object);

            _userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser());

            _manCoService.Setup(x => x.GetManCosByUserId(It.IsAny <string>())).Returns(new List <ManCo>());

            _documentService.Setup(
                d =>
                d.GetDocuments(
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <List <string> >(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>())).Returns(_tooManyDocuments);

            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = (ViewResult)_controller.Search(new SearchViewModel());

            _userService.Verify(x => x.GetApplicationUser(), Times.Once);

            _manCoService.Verify(x => x.GetManCosByUserId(It.IsAny <string>()), Times.Once);

            var model = (DocumentsViewModel)result.Model;

            model.Should().BeOfType <DocumentsViewModel>();

            _controller.TempData.Should().NotBeNull();
            _controller.TempData["valid"].Should().Be("Show filter");
            _controller.TempData["tooManyDocs"].Should().Be("There were too many documents returned from your search. Please refine your search criteria");
        }
        public void GivenADashboardController_WhenIViewTheDashboardPage_AndThereAreGridsThatHaveDocsAwaitingHouseholding_ThenViewModelContainsGridsAwaitingHouseHolding()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            var model = result.Model as DashboardViewModel;

            _gridRunService.Verify(x => x.GetTopFifteenGridsAwaitingHouseHolding(), Times.AtLeastOnce());

            model.DashboardGridsAwaitingHouseHoldingViewModel.Should().HaveCount(5);
        }
        public void GivenADocumentController_WhenICallItsSearchCriteraMethod_WithAnAjaxRequest_ThenItReturnsTheCorrectView()
        {
            _controller = new DocumentController(
                _documentService.Object,
                _userService.Object,
                _manCoService.Object,
                _logger.Object);

            _userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser());

            _manCoService.Setup(x => x.GetManCosByUserId(It.IsAny <string>())).Returns(new List <ManCo>());

            _documentService.Setup(
                d =>
                d.GetDocuments(
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <List <string> >(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>())).Returns(_documentsIndexed);

            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = (PartialViewResult)_controller.Search(new SearchViewModel(), It.IsAny <int>(), true);

            _userService.Verify(x => x.GetApplicationUser(), Times.Once);

            _manCoService.Verify(x => x.GetManCosByUserId(It.IsAny <string>()), Times.Once);

            result.Model.Should().BeOfType <DocumentsViewModel>();
            result.ViewName.Should().Be("_PagedDocumentResults");

            _controller.TempData.Should().NotBeNull();
            _controller.TempData["valid"].Should().Be("Show filter");
            _controller.TempData["tooManyDocs"].Should().Be(string.Empty);
        }
        public void GivenADocumentController_WhenICallItsSearchCriteriaMethod_ThenItRetrunsTheCorrectNumberOfDocuments()
        {
            _controller = new DocumentController(
                _documentService.Object,
                _userService.Object,
                _manCoService.Object,
                _logger.Object);

            _userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser());

            _manCoService.Setup(x => x.GetManCosByUserId(It.IsAny <string>())).Returns(new List <ManCo>());

            _documentService.Setup(
                d =>
                d.GetDocuments(
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <List <string> >(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <DateTime?>(),
                    It.IsAny <string>())
                ).Returns(_documentsIndexed);

            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["SearchViewModel"]).Returns(null);

            var result = (ViewResult)_controller.Search(new SearchViewModel());

            _userService.Verify(x => x.GetApplicationUser(), Times.Once);

            _manCoService.Verify(x => x.GetManCosByUserId(It.IsAny <string>()), Times.Once);

            var model = (DocumentsViewModel)result.Model;

            int documentCount = (from s in _documentsIndexed.Results select s).Count();

            model.Documents.Should().HaveCount(documentCount);
        }
        public void GivenALoggedInUser_WhenILoginOut_ThenIGetTheEndView()
        {
            SetControllerContext(_sessionController);

            MockHttpContext.SetupGet(x => x.Session["SessionGuid"]).Returns("guid");

            _sessionService.Setup(s => s.Update("guid", It.IsAny <DateTime>()));

            MockHttpContext.Setup(x => x.Session.Clear());

            var result = _sessionController.Remove() as ActionResult;

            result.Should().BeOfType <ViewResult>();
        }
        public void GivenADashboardController_WhenIViewTheDashboardPage_AndThereAreNoRecentProcssedFiles_ThenTheViewModelContainsNoProcessedFiles()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            _gridRunService.Setup(x => x.GetTopFifteenSuccessfullyCompleted()).Returns(new List <GridRun>());
            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            _gridRunService.Verify(x => x.GetTopFifteenSuccessfullyCompleted(), Times.AtLeastOnce());

            var model = result.Model as DashboardViewModel;

            model.DashboardProcessedViewModels.Should().HaveCount(0);
        }
        public void GivenADashboardController_WhenIViewTheDashboardPage_AndThereAreNoGridsAwaitingApproval_ThenViewModelContainsNoDocumentsAwaitingApproval()
        {
            SetControllerContext(_controller);
            MockHttpContext.SetupGet(x => x.Session["ManCoFilter"]).Returns(null);

            _gridRunService.Setup(x => x.GetTopFifteenRecentUnapprovedGrids()).Returns(new List <GridRun>());

            var result = _controller.Index(new ManCoFilterViewModel()) as ViewResult;

            var model = result.Model as DashboardViewModel;

            _gridRunService.Verify(x => x.GetTopFifteenRecentUnapprovedGrids(), Times.AtLeastOnce());

            model.DashboardUnapporvedGridsViewModels.Should().HaveCount(0);
        }