public async Task <ActionResult <Note> > Patch(string id, JsonPatchDocument <Note> note) { logger.LogDebug($"Patching note: {id}"); var noteToPatch = await notesService.GetNoteAsync(id); if (noteToPatch == null) { logger.LogDebug($"Unable to find note: {id}"); return(NotFound()); } var placeholderNote = new Note(noteToPatch); var validationResults = new NoteValidator().Validate(placeholderNote); if (!validationResults.IsValid) { return(BadRequest(validationResults.Errors)); } note.ApplyTo(placeholderNote); var patchedNote = await notesService.UpdateNoteAsync(id, placeholderNote.Title, placeholderNote.Content); logger.LogDebug($"Patched note {noteToPatch.Id}"); return(Ok(new Note(patchedNote))); }
private void SetupTestEnv() { InsertSeedRecords(); _user = LookupRepo.GetEntities <Author>().FirstOrDefault(); _validator = new NoteValidator(NoteRepository); _manager = new HmmNoteManager(NoteRepository, _validator, DateProvider); }
public void AlertWithNoteAndMessageTypeErrorIsValid() { var alert = new Alert(); alert.Note = "maxOccurs"; alert.MessageType = MessageType.Error; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
public void AlertWithNoteAndStatusExerciseIsValid() { var alert = new Alert(); alert.Note = "maxOccurs"; alert.Status = Status.Excercise; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
public void AlertWithNoteNullAndStatusDifferentFromExerciseIsValid() { var alert = new Alert(); alert.Note = null; alert.MessageType = MessageType.Cancel; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
private void SetupTestEnv() { InsertSeedRecords(); _validator = new NoteValidator(NoteRepository); _author = AuthorRepository.GetEntities().FirstOrDefault(); _catalog = CatalogRepository.GetEntities().FirstOrDefault(); Assert.NotNull(_author); Assert.NotNull(_catalog); }
public void AlertWithNoteNullAndMessageTypeErrorIsInvalid() { var alert = new Alert(); alert.Note = null; alert.MessageType = MessageType.Error; var noteValidator = new NoteValidator(alert); Assert.False(noteValidator.IsValid); Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType()); }
public void AlertWithNoteNullAndStatusExerciseIsInvalid() { var alert = new Alert(); alert.Note = null; alert.Status = Status.Excercise; var noteValidator = new NoteValidator(alert); Assert.False(noteValidator.IsValid); Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType()); }
public void AlertWithNoteAndMessageTypeErrorIsValid() { var alert = new Alert(); alert.Note = "maxOccurs"; alert.MessageType = MessageType.Error; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
public void AlertWithNoteNullAndStatusDifferentFromExerciseIsValid() { var alert = new Alert(); alert.Note = null; alert.MessageType = MessageType.Cancel; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
public void AlertWithNoteAndStatusExerciseIsValid() { var alert = new Alert(); alert.Note = "maxOccurs"; alert.Status = Status.Exercise; var noteValidator = new NoteValidator(alert); Assert.True(noteValidator.IsValid); }
public void AlertWithNoteNullAndMessageTypeErrorIsInvalid() { var alert = new Alert(); alert.Note = null; alert.MessageType = MessageType.Error; var noteValidator = new NoteValidator(alert); Assert.False(noteValidator.IsValid); Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType()); }
public void AlertWithNoteNullAndStatusExerciseIsInvalid() { var alert = new Alert(); alert.Note = null; alert.Status = Status.Exercise; var noteValidator = new NoteValidator(alert); Assert.False(noteValidator.IsValid); Assert.Equal(typeof(NoteError), noteValidator.Errors.ElementAt(0).GetType()); }
public bool Remove(Guid id) { try { NoteValidator.Check(id); return(_noteDAO.Remove(id)); } catch (Exception e) { //TO DO: log here return(false); } }
public NoteDTO Get(Guid id) { try { NoteValidator.Check(id); return(_noteDAO.Get(id)); } catch (Exception e) { //TO DO: log here return(new NoteDTO()); } }
public bool Add(NoteDTO noteDTO) { try { NoteValidator.Check(noteDTO, true); return(_noteDAO.Add(noteDTO)); } catch (Exception e) { //TO DO: log here return(false); } }
public IEnumerable <NoteDTO> Find(string query) { try { query = query.ToLower(); NoteValidator.Check(nameof(query), query); return(_noteDAO.GetAll().Where(x => x.LastName.ToLower().Contains(query) || x.FirstName.ToLower().Contains(query) || x.PhoneNumber.Contains(query))); } catch (Exception e) { //TO DO: log here return(new NoteDTO[0]); } }
private void SaveOrUpdate() { NoteValidator validator = new NoteValidator(); var validationResult = validator.Validate(Note); if (validationResult.IsValid) { if (ActionName.Equals("Save")) { Note note = new Note { Title = Note.Title, Content = Note.Content, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, UserId = _loggedInUser.Id }; UnitOfWork.Notes.Add(note); } else { Note foundNote = UnitOfWork.Notes.SingleOrDefault(n => n.Id == Note.Id); foundNote.Title = Note.Title; foundNote.Content = Note.Content; foundNote.UpdatedDate = DateTime.Now; } if (UnitOfWork.Complete() > 0) { MessageBox.Show($"Note Title: '{Note.Title}' {ActionName.ToLower()}d.", $"Note {ActionName}", MessageBoxButton.OK, MessageBoxImage.Information); NavigateNotesPage(); } else { ErrorText = $"Note could not {ActionName.ToLower()}d."; } } else { // show first error message ErrorText = validationResult.Errors[0].ErrorMessage; } }
public NoteValidatorTests() { this.validator = new NoteValidator(); }
/// <summary> /// Validated entered birth year /// </summary> /// <param name="birthYear">Validated value</param> /// <returns>Is value expected match with max human age property</returns> public static bool Check(int birthYear) { return(NoteValidator.Check(birthYear, false)); }
public NoteService(INoteRepository noteRepository, IPatientService patientService) { _noteRepository = noteRepository; _patientService = patientService; _noteValidator = new NoteValidator(); }