public async Task <IActionResult> AddJobApplication(AddJobApplicationModel addModel) { if (!ModelState.IsValid) { throw new ArgumentException(); } var jobOffer = await jobOfferFacade.GetByIdAsync(addModel.JobApplication.JobOfferId ?? 0); var user = await userFacade.GetByIdAsync(Int32.Parse(User.Identity.Name)); var jobSeeker = await jobSeekerFacade.GetByIdAsync(user.JobSeekerId.Value); var jobApplication = new JobApplicationDto { ApplicantId = jobSeeker.Id, JobOfferId = jobOffer.Id, Status = Status.Unresolved, Answers = addModel.JobApplication.Answers, Text = addModel.JobApplication.Text }; await jobApplicationFacade.ApplyToJobOfferAsync(jobApplication); return(RedirectToAction("Index")); }
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(); }