public void All_WithFilterForUnapprovedCompaniesAndPageShouldReturnCorrectData() { const int UnapprovedCompaniesCount = 5; //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(this.GetUnapprovedCompanies()); this.companyService.Setup(c => c.TotalCompanies(It.IsAny <string>())) .Returns(UnapprovedCompaniesCount); //Act var result = controller.All(CompanyStatus.Unapproved); //Assert result.Should().BeOfType <ViewResult>(); var model = result.As <ViewResult>().Model.As <AllCompanies>(); model.Companies.Should().HaveCount(UnapprovedCompaniesCount); model.Filter.Should().Be(CompanyStatus.Unapproved); model.Pagination.CurrentPage.Should().Be(FirstPage); model.Pagination.NextPage.Should().Be(FirstPage); model.Pagination.PreviousPage.Should().Be(FirstPage); model.Pagination.SearchTerm.Should().Be(CompanyStatus.Unapproved.ToString()); }
public void All_WithCorrectFilterAndPageGreaterThanTotalPagesShouldRedirectToAllCompaniesAndLastPage() { const int Page = 10; //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(this.GetAllCompanies()); this.companyService.Setup(c => c.TotalCompanies(It.IsAny <string>())) .Returns(TotalCompaniesCount); //Act var result = controller.All(CompanyStatus.All, Page); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); model.RouteValues.Keys.Should().Contain(RouteValueKeyAdminCompaniesFilter); model.RouteValues.Values.Should().Contain(CompanyStatus.All); model.RouteValues.Keys.Should().Contain(RouteValueKeyPage); model.RouteValues.Values.Should().Contain(LastPage); }
public void All_WithCorrectFilterAndPageShouldReturnNoCompaniesWhenThereAreNoRegisteredCompanies() { //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.All(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(new List <AdminCompanyListingServiceModel>()); this.companyService.Setup(c => c.TotalCompanies(It.IsAny <string>())) .Returns(0); //Act var result = controller.All(CompanyStatus.All); //Assert result.Should().BeOfType <ViewResult>(); var model = result.As <ViewResult>().Model.As <AllCompanies>(); model.Companies.Should().HaveCount(0); model.Filter.Should().Be(CompanyStatus.All); model.Pagination.CurrentPage.Should().Be(FirstPage); model.Pagination.NextPage.Should().Be(0); model.Pagination.PreviousPage.Should().Be(FirstPage); model.Pagination.SearchTerm.Should().Be(CompanyStatus.All.ToString()); }
public void All_WithCorrectPageAndNonExistingFilterShouldRedirectToAllCompaniesAndSetFilterToAll(CompanyStatus filter) { //Arrange var controller = new AdminCompaniesController(null); //Act var result = controller.All(filter); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); model.RouteValues.Keys.Should().Contain(RouteValueKeyAdminCompaniesFilter); model.RouteValues.Values.Should().Contain(CompanyStatus.All); }
public void All_WithPageLessOrEqualToZeroShouldRedirectToAllCompanies(int page) { //Arrange var controller = new AdminCompaniesController(null); var filter = CompanyStatus.All; //Act var result = controller.All(filter, page); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); model.RouteValues.Keys.Should().Contain(RouteValueKeyAdminCompaniesFilter); model.RouteValues.Values.Should().Contain(filter); }