コード例 #1
0
        public async Task MoveNoteCommandHandler_UpdatesNoteAndBroadcast_OnRequest()
        {
            // 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"
            };

            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, noteGroup.Id);
            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(noteGroup.Id));

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

            await mediator.Received().Publish(Arg.Any <NoteMovedNotification>());
        }