public void All_ValidPageAndNoTownsShouldReturnCountZero() { //Arrange var controller = new AdminTownsController(this.townService.Object); this.townService.Setup(t => t.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(new List <AdminTownListingServiceModel>()); this.townService.Setup(t => t.TotalTowns(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 <AllTowns>(); model.Towns.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); }
public void All_ShouldReturnCorrectDataWithValidInputAndParticularSearchTerm() { const string SearchTerm = "Test"; //Arrange var controller = new AdminTownsController(this.townService.Object); this.townService.Setup(t => t.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(this.GetTowns()); this.townService.Setup(t => t.TotalTowns(It.IsAny <string>())) .Returns(TotalTowns); //Act var result = controller.All(SearchTerm, MinPageSize); //Assert result.Should().BeOfType <ViewResult>(); var model = result.As <ViewResult>().Model.As <AllTowns>(); model.Towns.Should().HaveCount(TotalTowns); 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(TotalTowns); }
public void All_PageGreaterThanTotalPagesShouldRedirectToAllTowns() { const int InvalidPageSize = 10; //Arrange var controller = new AdminTownsController(this.townService.Object); this.townService.Setup(t => t.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(this.GetTowns()); this.townService.Setup(t => t.TotalTowns(It.IsAny <string>())) .Returns(TotalTowns); //Act var result = controller.All(string.Empty, InvalidPageSize); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllTowns); 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); }
public void All_WithPageLessOrEqualToZeroShouldRedirectToAllTowns(int page) { //Arrange var controller = new AdminTownsController(this.townService.Object); //Act var result = controller.All(string.Empty, page); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllTowns); 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); }