// 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()); } // _context.Attach(JobPosition).State = EntityState.Modified; try { _jobPositionService.UpdateJobPosition(JobPosition); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JobPositionExists(JobPosition.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public void JobPositionWithInvalidId_WhenUpdated_ThrowsExeption() { var service = new JobPositionService(context); var updateData = new JobPosition { Name = "JobPosition" }; var ex = Assert.Throws <ArgumentException>(() => service.UpdateJobPosition(1, updateData)); Assert.That(ex.Message, Is.EqualTo("Invalid job position id. (Parameter 'id')")); }
public void JobPosition_CanBeUpdated() { context.JobPositions.Add(new JobPosition { Name = "JobPosition" }); context.SaveChanges(); var service = new JobPositionService(context); var updateData = new JobPosition { Name = "JobPosition2" }; var jobPosition = service.UpdateJobPosition(1, updateData); var jobPositionRecord = context.JobPositions.Single(i => i.Name == "JobPosition2"); Assert.AreEqual("JobPosition2", jobPosition.Name); Assert.AreEqual("JobPosition2", jobPositionRecord.Name); }