예제 #1
0
        public async Task MoveNoteCommandHandler_InvalidGroupId_ThrowsNotFoundException()
        {
            // Given
            var note = new Note {
                Retrospective = new Retrospective {
                    FacilitatorHashedPassphrase = "whatever",
                    CurrentStage = RetrospectiveStage.Writing,
                    Title        = this.GetType().FullName
                },
                Participant = new Participant {
                    Name = "Tester"
                },
                Lane = this.Context.NoteLanes.FirstOrDefault(),
                Text = "Derp"
            };

            TestContext.WriteLine(note.Retrospective.UrlId);
            this.Context.Notes.Add(note);
            await this.Context.SaveChangesAsync();

            var command = new MoveNoteCommand(note.Id, 0);
            var handler = new MoveNoteCommandHandler(this.Context, Substitute.For <ISecurityValidator>(), Substitute.For <IMediator>());

            // When
            TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            // Then
            Assert.That(action, Throws.InstanceOf <NotFoundException>());
        }
예제 #2
0
        public void MoveNoteCommandHandler_InvalidNoteId_ThrowsNotFoundException()
        {
            // Given
            var command = new MoveNoteCommand(-1, null);
            var handler = new MoveNoteCommandHandler(this.Context, Substitute.For <ISecurityValidator>(), Substitute.For <IMediator>());

            // When
            TestDelegate action = () => handler.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            // Then
            Assert.That(action, Throws.InstanceOf <NotFoundException>());
        }
예제 #3
0
        public async Task MoveNoteCommandHandler_RemoveGroup_UpdatesNoteAndBroadcast()
        {
            // Given
            var note = new Note {
                Retrospective = new Retrospective {
                    FacilitatorHashedPassphrase = "whatever",
                    CurrentStage = RetrospectiveStage.Writing,
                    Title        = this.GetType().FullName
                },
                Participant = new Participant {
                    Name = "Tester"
                },
                Lane = this.Context.NoteLanes.FirstOrDefault(),
                Text = "Derp"
            };
            var noteGroup = new NoteGroup {
                Lane          = note.Lane,
                Retrospective = note.Retrospective,
                Title         = "G1"
            };

            note.Group = noteGroup;

            TestContext.WriteLine(note.Retrospective.UrlId);
            this.Context.Notes.Add(note);
            this.Context.NoteGroups.Add(noteGroup);
            await this.Context.SaveChangesAsync();

            var updateCommand     = new MoveNoteCommand(note.Id, null);
            var mediator          = Substitute.For <IMediator>();
            var securityValidator = Substitute.For <ISecurityValidator>();

            var handler = new MoveNoteCommandHandler(this.Context, securityValidator, mediator);

            // When
            await handler.Handle(updateCommand, CancellationToken.None);

            // Then
            this.Context.Entry(note).Reload();
            Assert.That(note.GroupId, Is.EqualTo(null));

            await securityValidator.Received().EnsureOperation(Arg.Any <Retrospective>(), SecurityOperation.AddOrUpdate, Arg.Is <NoteGroup>(n => n.Id == noteGroup.Id));

            await mediator.Received().Publish(Arg.Any <NoteMovedNotification>());
        }
 public async Task <ActionResult <BoardViewModel> > Move([FromBody] MoveNoteCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }