public ShowcaseItem(RetrospectiveNote note, RetrospectiveLane lane, RetrospectiveVoteStatus voteStatus) { if (voteStatus == null) { throw new ArgumentNullException(nameof(voteStatus)); } this.Note = note ?? throw new ArgumentNullException(nameof(note)); this.Lane = lane ?? throw new ArgumentNullException(nameof(lane)); this.Votes = voteStatus.VotesByNote.Get(note.Id); }
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); }
protected async Task AddNote() { try { this.ShowErrorMessage = false; RetrospectiveNote result = await this.Mediator.Send(new AddNoteCommand(this.RetroId.StringId, this.Lane.Id)); this.Contents.Notes.Insert(0, result); this.LastAddedNote = result; } catch (Exception ex) { this.ShowErrorMessage = true; this.Logger.LogError(ex, $"Unable to add note for {this.RetroId} in lane {this.Lane?.Id}"); } }
protected void OnNoteDeletedCallback(RetrospectiveNote note) { this.Contents.Notes.RemoveAll(n => n.Id == note.Id); }
private bool ExecuteNoteMove(int noteId, int?newGroupId) { // Find the source group, target group and the note RetrospectiveNoteGroup sourceGroup = null, targetGroup = null; RetrospectiveNote note = null; foreach (RetrospectiveNoteGroup noteGroup in this.Contents.Groups) { if (noteGroup.Id == newGroupId) { targetGroup = noteGroup; } foreach (RetrospectiveNote groupNote in noteGroup.Notes) { if (groupNote.Id == noteId) { sourceGroup = noteGroup; note = groupNote; } } if (sourceGroup != null && targetGroup != null) { break; } } foreach (RetrospectiveNote noGroupNote in this.Contents.Notes) { if (noGroupNote.Id == noteId) { sourceGroup = null; note = noGroupNote; } } // No need to do anything or can't do anything if (sourceGroup == targetGroup || note == null) { return(false); } // Update state if (sourceGroup == null) { this.Contents.Notes.Remove(note); targetGroup.Notes.Add(note); note.GroupId = targetGroup.Id; } else if (targetGroup == null) { sourceGroup.Notes.Remove(note); this.Contents.Notes.Add(note); note.GroupId = null; } else { sourceGroup.Notes.Remove(note); targetGroup.Notes.Add(note); note.GroupId = targetGroup.Id; } return(true); }
public NoteAddedNotification(string retroId, int laneId, RetrospectiveNote note) : base(retroId) { this.LaneId = laneId; this.Note = note; }