public void Candidate_CanBeAddedToAdvertisement() { var service = new AdvertisementCandidateService(context); service.AddCandidateToAdvertisement(this.advertisement.Id, this.candidate.Id); Assert.AreEqual(1, this.context.AdvertisementsCandidates.Count()); }
public void Candidate_WhenAddedToAdvertisementWithInvalidId_ThrowsException() { var service = new AdvertisementCandidateService(context); var ex = Assert.Throws <ArgumentException>(() => service.AddCandidateToAdvertisement(2, this.candidate.Id)); Assert.That(ex.Message, Is.EqualTo("Invalid advertisement id. (Parameter 'advertisementId')")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var userName = User.Identity.Name; var advertisementCandidateService = new AdvertisementCandidateService(_context); var candidate = this._context.Candidates.FirstOrDefault(c => c.Email == Candidate.Email); if (candidate == null) { candidate = service.CreateCandidate(Candidate.FirstName, Candidate.LastName, Candidate.Email); } var advId = Convert.ToInt32(Request.Form["advId"]); advertisementCandidateService.AddCandidateToAdvertisement(advId, candidate.Id); return(RedirectToPage("/Index")); }