Example #1
0
        public void All_PageGreaterThanTotalPagesShouldRedirectToAllStations()
        {
            const int InvalidPageSize = 10;

            //Arrange
            var controller = new AdminStationsController(null, this.stationService.Object);

            this.stationService.Setup(s => s.All(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(this.GetStations());

            this.stationService.Setup(s => s.TotalStations(It.IsAny <string>()))
            .Returns(TotalStations);

            //Act
            var result = controller.All(string.Empty, InvalidPageSize);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllStations);
            model.RouteValues.Keys.Should().Contain(RouteValueKeyPage);
            model.RouteValues.Values.Should().Contain(MaxPageSize);
            model.RouteValues.Keys.Should().Contain(RouteValueKeySearchTerm);
            model.RouteValues.Values.Should().Contain(string.Empty);
        }
Example #2
0
        public void All_ShouldReturnCorrectDataWithValidInputAndParticularSearchTerm()
        {
            const string SearchTerm = "Test";

            //Arrange
            var controller = new AdminStationsController(null, this.stationService.Object);

            this.stationService.Setup(s => s.All(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(this.GetStations());

            this.stationService.Setup(s => s.TotalStations(It.IsAny <string>()))
            .Returns(TotalStations);

            //Act
            var result = controller.All(SearchTerm, MinPageSize);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model.As <AllStations>();

            model.Stations.Should().HaveCount(TotalStations);
            model.Pagination.SearchTerm.Should().Be(SearchTerm);
            model.Pagination.CurrentPage.Should().Be(MinPageSize);
            model.Pagination.NextPage.Should().Be(MaxPageSize);
            model.Pagination.PreviousPage.Should().Be(MinPageSize);
            model.Pagination.TotalElements.Should().Be(TotalStations);
        }
Example #3
0
        public void All_ValidPageAndNoStationsShouldReturnCountZero()
        {
            //Arrange
            var controller = new AdminStationsController(null, this.stationService.Object);

            this.stationService.Setup(s => s.All(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new List <AdminStationListingServiceModel>());

            this.stationService.Setup(s => s.TotalStations(It.IsAny <string>()))
            .Returns(0);

            //Act
            var result = controller.All(string.Empty, MinPageSize);

            //Assert
            result.Should().BeOfType <ViewResult>();
            var model = result.As <ViewResult>().Model.As <AllStations>();

            model.Stations.Should().HaveCount(0);
            model.Pagination.SearchTerm.Should().Be(string.Empty);
            model.Pagination.CurrentPage.Should().Be(MinPageSize);
            model.Pagination.NextPage.Should().Be(0);
            model.Pagination.PreviousPage.Should().Be(MinPageSize);
            model.Pagination.TotalElements.Should().Be(0);
        }
Example #4
0
        public void All_WithPageLessOrEqualToZeroShouldRedirectToAllStations(int page)
        {
            //Arrange
            var controller = new AdminStationsController(null, null);

            //Act
            var result = controller.All(string.Empty, page);

            //Assert
            result.Should().BeOfType <RedirectToActionResult>();
            var model = result.As <RedirectToActionResult>();

            model.ActionName.Should().Be(WebConstants.Action.AdminAllStations);
            model.RouteValues.Keys.Should().Contain(RouteValueKeyPage);
            model.RouteValues.Values.Should().Contain(MinPageSize);
            model.RouteValues.Keys.Should().Contain(RouteValueKeySearchTerm);
            model.RouteValues.Values.Should().Contain(string.Empty);
        }