public async Task AddNoteCommandHandler_InvalidLaneId_ThrowsNotFoundException() { // Given var handler = new AddNoteCommandHandler( this.Context, this._currentParticipantService, Substitute.For <ISecurityValidator>(), Substitute.For <IMediator>(), this.Mapper, this._systemClock ); var retro = new Retrospective { CurrentStage = RetrospectiveStage.Writing, FacilitatorHashedPassphrase = "whatever", Title = TestContext.CurrentContext.Test.FullName, CreationTimestamp = DateTimeOffset.Now, Participants = { new Participant { Name = "John" } } }; string retroId = retro.UrlId.StringId; this.Context.Retrospectives.Add(retro); await this.Context.SaveChangesAsync(); var command = new AddNoteCommand(retroId, -1); // When TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult(); // Then Assert.That(action, Throws.InstanceOf <NotFoundException>()); }
public async Task <int> Handle(AddNoteCommand request, CancellationToken cancellationToken) { try { // check if beneficiary exists and that the current user is allowed to add notes for the beneficiary var currentUser = await _context.Users.FirstOrDefaultAsync(u => u.UserId == request.UserId); var beneficiary = _context.Beneficiaries.Include(b => b.User).FirstOrDefault(b => b.BeneficiaryId == request.BeneficiaryId); if (beneficiary == null || (currentUser.NgoId != beneficiary.User.NgoId)) { return(-1); } var noteEntity = _mapper.Map <Entities.Note>(request); _context.Notes.Add(noteEntity); return(await _context.SaveChangesAsync(cancellationToken)); } catch (Exception ex) { _logger.LogError("Add note error", ex); throw ex; } }
private void RefreshCommands() { AddNoteCommand.RaiseCanExecuteChanged(); MoveUpCommand.RaiseCanExecuteChanged(); MoveDownCommand.RaiseCanExecuteChanged(); DeleteNodeCommand.RaiseCanExecuteChanged(); }
public WorkPageViewModel() { WPOpenProjectCommand = new WPOpenProjectCommand(this); BeginStopWorkCommand = new BeginStopWorkCommand(this); CompleteTaskCommand = new CompleteTaskCommand(this); AddNoteCommand = new AddNoteCommand(this); ToggleNotesCommand = new ToggleNotesCommand(); CloseProjectCommand = new CloseProjectCommand(this); DeleteNoteCommand = new DeleteNoteCommand(); EditNoteCommand = new EditNoteCommand(this); }
public async Task AddNoteCommandHandler_ValidCommand_CreatesValidObjectAndBroadcast() { // Given var securityValidator = Substitute.For <ISecurityValidator>(); var mediatorMock = Substitute.For <IMediator>(); var handler = new AddNoteCommandHandler( this.Context, this._currentParticipantService, securityValidator, mediatorMock, this.Mapper, this._systemClock ); var retro = new Retrospective { CurrentStage = RetrospectiveStage.Writing, FacilitatorHashedPassphrase = "whatever", Title = TestContext.CurrentContext.Test.FullName, CreationTimestamp = DateTimeOffset.Now, Participants = { new Participant { Name = "John" } } }; string retroId = retro.UrlId.StringId; this.Context.Retrospectives.Add(retro); await this.Context.SaveChangesAsync(); var command = new AddNoteCommand(retroId, (int)KnownNoteLane.Start); // When RetrospectiveNote result = await handler.Handle(command, CancellationToken.None); // Then Assert.That(result, Is.Not.Null); Assert.That(result.ParticipantName, Is.EqualTo(retro.Participants.First().Name)); Assert.That(result.IsOwnedByCurrentUser, Is.True); await securityValidator.Received().EnsureOperation(Arg.Is <Retrospective>(r => r.Id == retro.Id), SecurityOperation.AddOrUpdate, Arg.Any <Note>()); var broadcastedNote = mediatorMock.ReceivedCalls().FirstOrDefault()?.GetArguments()[0] as NoteAddedNotification; if (broadcastedNote == null) { Assert.Fail("No broadcast has gone out"); } Assert.That(broadcastedNote.LaneId, Is.EqualTo((int)KnownNoteLane.Start)); Assert.That(broadcastedNote.RetroId, Is.EqualTo(command.RetroId)); Assert.That(broadcastedNote.Note.IsOwnedByCurrentUser, Is.False); }
public async Task <int> Handle(AddNoteCommand request, CancellationToken cancellationToken) { try { var noteEntity = _mapper.Map <Entities.Note>(request); _context.Notes.Add(noteEntity); return(await _context.SaveChangesAsync(cancellationToken)); } catch (Exception e) { Console.WriteLine(e); throw; } }
// public ViewModel(MySoundGameRuler in_ruler, StackPanel in_stack_panel, ScrollViewer in_scroll) { var window = Application.Current.Windows.OfType <Window>().FirstOrDefault(w => w is MainWindow); notes_manager = new NotesManager(in_stack_panel); //苦肉の策 ruler = in_ruler; main_stack = in_stack_panel; scroll = in_scroll; command_add_note = new AddNoteCommand(this); }
public void AddNoteCommandHandler_InvalidRetroId_ThrowsNotFoundException() { // Given var handler = new AddNoteCommandHandler( this.Context, this._currentParticipantService, Substitute.For <ISecurityValidator>(), Substitute.For <IMediator>(), this.Mapper, this._systemClock ); var command = new AddNoteCommand("not found", (int)KnownNoteLane.Start); // When TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult(); // Then Assert.That(action, Throws.InstanceOf <NotFoundException>()); }
public async Task <AddNoteResponse> Execute(AddNoteRequest req) { var careAgentUserName = RequestHeaderInfo.GetUserName(); try { if (String.IsNullOrEmpty(careAgentUserName)) { throw new BadRequestException("Invalid parameter header.UserName"); } var rsp = await AddNoteCommand.ExecuteAsync(new AddNoteInput { Note = req.Note, UserFullName = req.UserFullName, CareAgentUserName = careAgentUserName, AccountIdentifier = new Guid(req.AccountIdentifier) } ); return(new AddNoteResponse { Notekey = rsp.Notekey }); } catch (GdErrorException) { throw; } catch (Exception ex) { throw new GdErrorException( $"Error while executing AddNote for UserFullName={req.UserFullName}, Note={req.Note}", new LogObject("NoteManager_AddNote", new Dictionary <string, object> { { "CareAgentName", careAgentUserName }, { "Note", req.Note } }), ex); } }
private void ProcessCommands(string commands) { string commandType = String.Join(string.Empty, commands.Split()); ICommand command = null; string commandResult = String.Empty; switch (commandType) { case "register": case "registeruser": command = new RegisterCommand(); break; case "login": case "log": command = new LoginCommand(); break; case "logout": command = new LogOutCommand(); break; case "addnotebook": command = new AddNotebookCommand(); break; case "addnote": if (LoggedUser.Notebooks.Count == 0) { throw new ArgumentException(Messages.MustCreateANotebook()); } command = new AddNoteCommand(); break; case "switchnotebook": command = new SwitchNotebookCommand(); break; case "addtask": command = new AddTaskCommand(); break; case "addlongtermtask": command = new AddLongTermTaskCommand(); break; case "addsubtask": command = new AddSubtaskCommand(); break; case "addremindertotask": command = new AddReminderToTaskCommand(); break; case "addnotetofavourites": command = new AddNoteToFavouritesCommand(); break; case "addnotebooktofavourites": command = new AddNotebookToFavouritesCommand(); break; case "listall": command = new ListCommand(); break; case "listtask": command = new ListTask(); break; case "listnotebook": command = new ListNotebookCommand(); break; case "listnote": command = new ListNoteCommand(); break; case "listlongtermtask": command = new ListLongTermTaskCommand(); break; case "listsubtask": command = new ListSubTaskCommand(); break; case "switchlongtertask": command = new SwitchLongTermTaskCommand(); break; case "deletetask": command = new DeleteTaskCommand(); break; case "deletesubtask": command = new DeleteSubTaskCommand(); break; case "clearhistory": command = new ClearHistoryCommand(); break; case "sortallnotebooks": command = new SortNotebooksCommand(); break; case "sortnotebook": command = new SortNotebookCommand(); break; case "sorttasks": command = new SortTasksCommand(); break; default: throw new ArgumentException("Wrong Command"); } command.TakeInput(); commandResult = command.Execute(); Writer.WriteLine(commandResult); }
public async Task <ActionResult <BoardViewModel> > Add([FromBody] AddNoteCommand command) { return(Ok(await Mediator.Send(command))); }