public void GivenARequestWithInvalidWarningNoteIdValidationFails() { var request = new PatchWarningNoteRequest { Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.WarningNoteId, request) .WithErrorMessage("Warning Note Id must be greater than 1"); }
public void GivenARequestWithNoReviewDateValidationFails() { var request = new PatchWarningNoteRequest { Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ReviewDate, request) .WithErrorMessage("Review date required"); }
public void GivenARequestWithInvalidStatusValidationFails() { var request = new PatchWarningNoteRequest { Status = "hello" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.Status, request) .WithErrorMessage("Provide a valid status"); }
public void GivenARequestWithNextReviewDateSetInThePastValidationFails() { var request = new PatchWarningNoteRequest { NextReviewDate = new DateTime(2000, 1, 1), Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.NextReviewDate, request) .WithErrorMessage("Next review date must be in the future"); }
public void GivenARequestWithInvalidReviewedByEmailAddressValidationFails() { var request = new PatchWarningNoteRequest { ReviewedBy = "hello", Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ReviewedBy, request) .WithErrorMessage("Provide a valid email address"); }
public void GivenARequestWithFutureReviewDateValidationFails() { var request = new PatchWarningNoteRequest { ReviewDate = DateTime.Now.AddYears(2), Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ReviewDate, request) .WithErrorMessage("Review date must be in the past"); }
public void GivenARequestWithDiscussedWithManagerDateSetInTheFutureValidationFails() { var request = new PatchWarningNoteRequest { DiscussedWithManagerDate = DateTime.Now.AddYears(2), Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.DiscussedWithManagerDate, request) .WithErrorMessage("Discussed with manager date must be in the past"); }
public void GivenARequestWithManagerNameMoreThanMaximumLengthValidationFails() { var request = new PatchWarningNoteRequest { ManagerName = new string('a', 110), Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ManagerName, request) .WithErrorMessage("Manager name must be less than 100 characters"); }
public void GivenARequestWithReviewNotesMoreThanMaximumLengthValidationFails() { var request = new PatchWarningNoteRequest { ReviewNotes = new string('a', 1100), Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ReviewNotes, request) .WithErrorMessage("Review notes should be 1000 characters or less"); }
public void GivenARequestWithReviewNotesLessThanMinimumLengthValidationFails() { var request = new PatchWarningNoteRequest { ReviewNotes = "", Status = "open" }; _classUnderTest.ShouldHaveValidationErrorFor(x => x.ReviewNotes, request) .WithErrorMessage("Review notes required"); }
private static WarningNoteReview PostWarningNoteReview(PatchWarningNoteRequest request) { return(new WarningNoteReview { WarningNoteId = request.WarningNoteId, ReviewDate = request.ReviewDate, ReviewNotes = request.ReviewNotes, DisclosedWithIndividual = request.DisclosedWithIndividual, ManagerName = request.ManagerName, DiscussedWithManagerDate = request.DiscussedWithManagerDate, CreatedBy = request.ReviewedBy, LastModifiedBy = request.ReviewedBy }); }
public IActionResult PatchWarningNote([FromBody] PatchWarningNoteRequest request) { var validator = new PatchWarningNoteRequestValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } try { _warningNoteUseCase.ExecutePatch(request); return(NoContent()); } catch (PatchWarningNoteException e) { return(BadRequest(e.Message)); } }
public void ExecutePatch(PatchWarningNoteRequest request) { _databaseGateway.PatchWarningNote(request); }
public void PatchWarningNote(PatchWarningNoteRequest request) { WarningNote warningNote = _databaseContext.WarningNotes.FirstOrDefault(x => x.Id == request.WarningNoteId); if (warningNote == null) { throw new PatchWarningNoteException($"Warning Note with given id ({request.WarningNoteId}) not found"); } if (warningNote.Status == "closed") { throw new PatchWarningNoteException( $"Warning Note with given id ({request.WarningNoteId}) has already been closed"); } Person person = _databaseContext.Persons.FirstOrDefault(x => x.Id == warningNote.PersonId); if (person == null) { throw new PatchWarningNoteException("Person not found"); } Worker worker = _databaseContext.Workers.FirstOrDefault(x => x.Email == request.ReviewedBy); if (worker == null) { throw new PatchWarningNoteException($"Worker ({request.ReviewedBy}) not found"); } warningNote.LastReviewDate = request.ReviewDate; warningNote.NextReviewDate = request.NextReviewDate; if (request.Status?.ToLower() == "closed") { warningNote.Status = "closed"; warningNote.EndDate = _systemTime.Now; warningNote.NextReviewDate = null; } warningNote.LastModifiedBy = request.ReviewedBy; var review = PostWarningNoteReview(request); _databaseContext.WarningNoteReview.Add(review); _databaseContext.SaveChanges(); var dt = DateTime.Now; var note = new WarningNoteCaseNote { FirstName = person.FirstName, LastName = person.LastName, MosaicId = person.Id.ToString(), Timestamp = dt.ToString("dd/MM/yyyy H:mm:ss"), Note = $"{dt.ToShortDateString()} | Warning Note | {((request.Status == "closed") ? "Warning note against this person ended" : "Warning note against this person reviewed")}", FormNameOverall = "API_WarningNote", FormName = (request.Status == "closed") ? "Warning Note Ended" : "Warning Note Reviewed", WarningNoteId = warningNote.Id.ToString(), WorkerEmail = request.ReviewedBy }; var caseNotesDocument = new CaseNotesDocument { CaseFormData = JsonConvert.SerializeObject(note) }; _ = _processDataGateway.InsertCaseNoteDocument(caseNotesDocument).Result; }