public ShowcaseItem(RetrospectiveNoteGroup noteGroup, RetrospectiveLane lane, RetrospectiveVoteStatus voteStatus) { if (voteStatus == null) { throw new ArgumentNullException(nameof(voteStatus)); } this.NoteGroup = noteGroup ?? throw new ArgumentNullException(nameof(noteGroup)); this.Lane = lane ?? throw new ArgumentNullException(nameof(lane)); this.Votes = voteStatus.VotesByNoteGroup.Get(noteGroup.Id); }
public async Task AddNoteGroupCommandHandler_ValidCommand_CreatesValidObjectAndBroadcast() { // Given var securityValidator = Substitute.For <ISecurityValidator>(); var mediatorMock = Substitute.For <IMediator>(); var handler = new AddNoteGroupCommandHandler( this.Context, securityValidator, this.Mapper, mediatorMock ); 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 AddNoteGroupCommand(retroId, (int)KnownNoteLane.Start); // When RetrospectiveNoteGroup result = await handler.Handle(command, CancellationToken.None); // Then Assert.That(result, Is.Not.Null); Assert.That(result.Title, Is.EqualTo(String.Empty)); await securityValidator.Received().EnsureOperation(Arg.Is <Retrospective>(r => r.Id == retro.Id), SecurityOperation.AddOrUpdate, Arg.Any <NoteGroup>()); var broadcastedUpdate = mediatorMock.ReceivedCalls().FirstOrDefault()?.GetArguments()[0] as NoteLaneUpdatedNotification; if (broadcastedUpdate == null) { Assert.Fail("No broadcast has gone out"); } Assert.That(broadcastedUpdate.LaneId, Is.EqualTo((int)KnownNoteLane.Start)); Assert.That(broadcastedUpdate.RetroId, Is.EqualTo(command.RetroId)); Assert.That(broadcastedUpdate.GroupId, Is.EqualTo(result.Id)); }
protected async Task AddNoteGroup() { try { this.ShowErrorMessage = false; this._skipFirstUpdate.Set(); RetrospectiveNoteGroup result = await this.Mediator.Send(new AddNoteGroupCommand(this.RetroId.StringId, this.Lane.Id)); this.Contents.Groups.Add(result); } catch (Exception ex) { this.ShowErrorMessage = true; this.Logger.LogError(ex, $"Unable to add note group for {this.RetroId} in lane {this.Lane?.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); }