public async Task <IActionResult> Details(int id) { CompanyDetailsServiceModel company = await this._companyServices.GetByIdAsync(id); if (company == null) { return(NotFound()); } List <OfficeDetailsViewModel> offices = company.Offices .Select(x => new OfficeDetailsViewModel { City = x.City, OfficeId = x.OfficeId, Country = x.Country, IsHQ = x.IsHQ == true? "The office is Headquarter" : "", Street = x.Street, StreetNumber = x.StreetNumber }) .ToList(); CompanyDetailsViewModel model = new CompanyDetailsViewModel() { CompanyId = company.CompanyId, Name = company.Name, CreationDate = company.CreationDate.ToString("MM/dd/yyyy"), Offices = offices }; return(View(model)); }
public void Details_WithExistingCompanyAndLastReviewsPageShouldReturnView() { //Arrange CompanyDetailsServiceModel company = this.GetCompanyDetailsServiceModel(); reviewService.Setup(r => r.TotalReviews(It.IsAny <string>())) .Returns(ReviewsCount); companyService.Setup(c => c.CompanyDetails(It.IsAny <string>())) .Returns(company); var controller = new CompaniesController(companyService.Object, townService.Object, reviewService.Object); //Act var result = controller.Details(CompanyId, LastPage); //Assert result.Should().BeOfType <ViewResult>(); var model = result.As <ViewResult>().Model; model.Should().BeOfType <CompanyDetails>(); model.As <CompanyDetails>().SearchForm.CompanyId.Should().Be(CompanyId); model.As <CompanyDetails>().ReviewForm.CompanyId.Should().Be(CompanyId); model.As <CompanyDetails>().Reviews.Pagination.CurrentPage.Should().Be(LastPage); model.As <CompanyDetails>().Reviews.Pagination.NextPage.Should().Be(LastPage); model.As <CompanyDetails>().Reviews.Pagination.TotalPages.Should().Be(LastPage); model.As <CompanyDetails>().Reviews.Pagination.TotalElements.Should().Be(ReviewsCount); this.AssertCompayDetailsViewModel(this.GetCompanyDetailsServiceModel(), model.As <CompanyDetails>()); }
public async Task <CompanyDetailsServiceModel> GetByIdAsync(int id) { Company company = await this._context.Companies .Include(o => o.Offices) .FirstOrDefaultAsync(c => c.CompanyId == id); List <OfficeDetailsServiceModel> offices = company.Offices .Select(x => new OfficeDetailsServiceModel { City = x.City, OfficeId = x.OfficeId, Country = x.Country, IsHQ = x.IsHQ, Street = x.Street, StreetNumber = x.StreetNumber }) .ToList(); CompanyDetailsServiceModel model = new CompanyDetailsServiceModel() { CompanyId = company.CompanyId, Name = company.Name, CreationDate = company.CreationDate, Offices = offices, }; return(model); }
private void AssertCompayDetailsViewModel(CompanyDetailsServiceModel companyDetailsServiceModel, CompanyDetails companyDetails) { companyDetailsServiceModel.Chief.Should().Be(companyDetails.Company.Chief); companyDetailsServiceModel.Description.Should().Be(companyDetails.Company.Description); companyDetailsServiceModel.Name.Should().Be(companyDetails.Company.Name); companyDetailsServiceModel.PhoneNumber.Should().Be(companyDetails.Company.PhoneNumber); companyDetailsServiceModel.TicketsSold.Should().Be(companyDetails.Company.TicketsSold); companyDetailsServiceModel.Town.Should().Be(companyDetails.Company.Town); }
public async Task <ActionResult> GetByIdAsync(int id) { CompanyDetailsServiceModel company = await companyService .GetByIdAsync(id); if (company == null) { return(NotFound()); } return(Ok(company)); }
public void Details_WithExistingCompanyAndNegativeReviewsPageShouldRedirectToCompanyDetails(int page) { //Arrange CompanyDetailsServiceModel company = new CompanyDetailsServiceModel(); this.companyService.Setup(c => c.CompanyDetails(It.IsAny <string>())) .Returns(company); var controller = new CompaniesController(companyService.Object, null, null); //Act var result = controller.Details(CompanyId, page); //Assert result.Should().BeOfType <RedirectToActionResult>(); (result as RedirectToActionResult).ActionName.Should().Be(nameof(CompaniesController.Details)); (result as RedirectToActionResult).RouteValues[RouteValueKeyId].Should().Be(CompanyId); (result as RedirectToActionResult).RouteValues[RouteValueKeyPage].Should().Be(MinPageSize); }
public void Details_WithNonExistingCompanyShouldRedirectToAllCompaniesWithAlertMessage() { //Arrange CompanyDetailsServiceModel company = null; this.companyService.Setup(c => c.CompanyDetails(It.IsAny <string>())) .Returns(company); var controller = new CompaniesController(companyService.Object, null, null); this.PrepareTempData(); controller.TempData = tempData.Object; //Act var result = controller.Details(CompanyId); //Assert result.Should().BeOfType <RedirectToActionResult>(); this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, nameof(WebConstants.Entity.Company), CompanyId)); (result as RedirectToActionResult).ActionName.Should().Be(nameof(CompaniesController.All)); }
public void Details_WithExistingCompanyAndGreaterThanTotalReviewsPagesCountShouldRedirectToCompanyDetails() { const int Page = 7; //Arrange CompanyDetailsServiceModel company = new CompanyDetailsServiceModel(); this.reviewService.Setup(r => r.TotalReviews(It.IsAny <string>())) .Returns(ReviewsCount); this.companyService.Setup(c => c.CompanyDetails(It.IsAny <string>())) .Returns(company); var controller = new CompaniesController(companyService.Object, null, reviewService.Object); //Act var result = controller.Details(CompanyId, Page); //Assert result.Should().BeOfType <RedirectToActionResult>(); (result as RedirectToActionResult).ActionName.Should().Be(nameof(CompaniesController.Details)); (result as RedirectToActionResult).RouteValues[RouteValueKeyId].Should().Be(CompanyId); (result as RedirectToActionResult).RouteValues[RouteValueKeyPage].Should().Be(LastPage); }