public async Task <IActionResult> Index() { var user = await userFacade.GetByIdAsync(Int32.Parse(User.Identity.Name)); var model = user.Role == Roles.JobSeeker ? await jobApplicationFacade.GetByApplicantIdAsync(new JobApplicationDto { ApplicantId = user.JobSeekerId }) : await jobApplicationFacade.GetByCompanyIdAsync(user.CompanyId ?? 0); return(View(model)); }
public void JobApplicationFacadeTest() { var unit = new UnitOfWork(GetInMemoryOptions()); Seeder.Seed(unit); var jobApplicationService = new JobApplicationService(unit, new JobApplicationQueryObject(unit)); var jobApplicationFacade = new JobApplicationFacade(unit, mapper, new JobApplicationService(unit, new JobApplicationQueryObject(unit))); var jason = unit.JobSeekerRepository.GetById(3); Assert.Equal("Jason", jason.Name); var application = jobApplicationService.GetByApplicantIdAsync(jason.Id ?? -1).Result.First(); // Null ID get var excp1 = Assert.Throws <AggregateException>(() => jobApplicationFacade.GetByApplicantIdAsync(new JobApplicationDto()).Wait()); Assert.Contains("ApplicantId can't be null!", excp1.Message); excp1 = Assert.Throws <AggregateException>(() => jobApplicationFacade.GetByApplicantIdAndStatusAsync(new JobApplicationDto(), Status.Rejected).Wait()); Assert.Contains("ApplicantId can't be null!", excp1.Message); excp1 = Assert.Throws <AggregateException>(() => jobApplicationFacade.GetByJobOfferIdAsync(new JobApplicationDto()).Wait()); Assert.Contains("JobOfferId can't be null!", excp1.Message); excp1 = Assert.Throws <AggregateException>(() => jobApplicationFacade.GetByJobOfferIdAndStatusAsync(new JobApplicationDto(), Status.Rejected).Wait()); Assert.Contains("JobOfferId can't be null!", excp1.Message); // Null ID edit/update var excp2 = Assert.Throws <AggregateException>(() => jobApplicationFacade.UpdateStatusAsync(mapper .Map <JobApplicationDto>(new JobApplication()), Status.Rejected).Wait()); Assert.Contains("JobApplicationId can't be null!", excp2.Message); // Null ID delete excp2 = Assert.Throws <AggregateException>(() => jobApplicationFacade.DeleteAsync(mapper .Map <JobApplicationDto>(new JobApplication())).Wait()); Assert.Contains("JobApplicationId can't be null!", excp2.Message); // Addition with conflicting ID // This invalidates the database var id1 = unit.JobApplicationRepository.GetById(1); Assert.NotNull(id1); // makes sure company with id 1 is already in database var excp = Assert.Throws <AggregateException>(() => jobApplicationFacade.ApplyToJobOfferAsync(new JobApplicationDto() { Id = 1 }).Wait()); Assert.Contains("The instance of entity type 'JobApplication' cannot be tracked " + "because another instance with the same key value for {'Id'} is already being tracked.", excp.Message); unit.Dispose(); }