public void UnBlock_WithValidDataShouldRedirectToAllCompanies() { //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.CompanyExists(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.ChangeStatus(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.GetCompanyName(It.IsAny <string>())) .Returns(CompanyName); this.companyService.Setup(c => c.GetBlockStatus(It.IsAny <string>())) .Returns(CompanyStatusUnblocked); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Block(CompanyId, CompanyStatus.All, MinPageSize); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); model.RouteValues.Keys.Should().Contain(RouteValueKeyPage); model.RouteValues.Values.Should().Contain(MinPageSize); model.RouteValues.Keys.Should().Contain(RouteValueKeyAdminCompaniesFilter); model.RouteValues.Values.Should().Contain(CompanyStatus.All); this.customMessage.Should().Be(string.Format(WebConstants.Message.CompanyStatusChanged, CompanyName, CompanyStatusUnblocked)); }
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 Block_UnapprovedCompanyShouldRedirectToAllCompanies() { //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.CompanyExists(It.IsAny <string>())) .Returns(true); this.companyService.Setup(c => c.ChangeStatus(It.IsAny <string>())) .Returns(false); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Block(CompanyId, CompanyStatus.All, MinPageSize); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); this.customMessage.Should().Be(string.Format(WebConstants.Message.BlockCompanyUnavailable, CompanyId)); }
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_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 ControllerShouldBeForAuthorizedUsers() { //Arrange var controller = new AdminCompaniesController(null); //Act var attributes = controller.GetType().GetCustomAttributes(true); //Assert attributes.Any(a => a.GetType() == typeof(AuthorizeAttribute)); }
public void ControllerShouldBeForAdminsOnly() { //Arrange var controller = new AdminCompaniesController(null); //Act var attributes = controller.GetType().GetCustomAttributes(true); //Assert var authorizeAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(AuthorizeAttribute)).As <AuthorizeAttribute>(); authorizeAttribute.Roles.Should().Be(Role.Administrator.ToString()); }
public void ControllerShouldBeInAdminArea() { //Arrange var controller = new AdminCompaniesController(null); //Act var attributes = controller.GetType().GetCustomAttributes(true); //Assert attributes.Any(a => a.GetType() == typeof(AreaAttribute)); var areaAttribute = attributes.FirstOrDefault(a => a.GetType() == typeof(AreaAttribute)); areaAttribute.As <AreaAttribute>().RouteValue.Should().Be(WebConstants.Area.Admin); }
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); }
public void Block_WithInvalidCompanyIdShouldRedirectToAllCompanies(string companyId) { //Arrange var controller = new AdminCompaniesController(this.companyService.Object); this.companyService.Setup(c => c.CompanyExists(It.IsAny <string>())) .Returns(false); this.PrepareTempData(); controller.TempData = this.tempData.Object; //Act var result = controller.Block(companyId, CompanyStatus.Unapproved, MinPageSize); //Assert result.Should().BeOfType <RedirectToActionResult>(); var model = result.As <RedirectToActionResult>(); model.ActionName.Should().Be(WebConstants.Action.AdminAllCompanies); this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, nameof(WebConstants.Entity.Company), companyId)); }