コード例 #1
0
        public async Task CastVoteCommandHandler_NoteGroupVote_VoteSavedAndBroadcast()
        {
            // Given
            var securityValidator = Substitute.For <ISecurityValidator>();
            var mediatorMock      = Substitute.For <IMediator>();
            var handler           = new CastVoteCommandHandler(
                this.Context,
                this._currentParticipantService,
                securityValidator,
                mediatorMock,
                this.Mapper
                );

            Retrospective retro = await this.CreateRetrospectiveWithNoteGroup();

            CastVoteCommand command = CastVoteCommand.ForNoteGroup(retro.NoteGroup.First().Id, VoteMutationType.Added);

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

            // Then
            await securityValidator.Received().
            EnsureOperation(Arg.Any <Retrospective>(), SecurityOperation.AddOrUpdate, Arg.Any <NoteVote>());

            var broadcastedNote = mediatorMock.ReceivedCalls().FirstOrDefault()?.GetArguments()[0] as VoteChangeNotification;

            if (broadcastedNote == null)
            {
                Assert.Fail("No broadcast has gone out");
            }

            Assert.That(broadcastedNote.VoteChange.RetroId, Is.EqualTo(retro.UrlId.StringId));
            Assert.That(broadcastedNote.VoteChange.Mutation, Is.EqualTo(VoteMutationType.Added));
            Assert.That(broadcastedNote.VoteChange.Vote.NoteGroupId, Is.EqualTo(retro.NoteGroup.First().Id));
        }
コード例 #2
0
        public async Task CastVoteCommandHandler_NoteVoteRemoved_VoteSavedAndBroadcast()
        {
            // Given
            var securityValidator = Substitute.For <ISecurityValidator>();
            var mediatorMock      = Substitute.For <IMediator>();
            var handler           = new CastVoteCommandHandler(
                this.Context,
                this._currentParticipantService,
                securityValidator,
                mediatorMock,
                this.Mapper
                );

            Retrospective retro = await this.CreateRetrospectiveWithNote();

            Note note = retro.Notes.First();

            NoteVote noteVote = this.Context.NoteVotes.Add(new NoteVote {
                Note          = note,
                Participant   = note.Participant,
                ParticipantId = note.ParticipantId,
                Retrospective = retro
            }).Entity;

            await this.Context.SaveChangesAsync();

            CastVoteCommand command = CastVoteCommand.ForNote(note.Id, VoteMutationType.Removed);

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

            // Then
            await securityValidator.Received().
            EnsureOperation(Arg.Any <Retrospective>(), SecurityOperation.Delete, Arg.Any <NoteVote>());

            var broadcastedNote = mediatorMock.ReceivedCalls().FirstOrDefault()?.GetArguments()[0] as VoteChangeNotification;

            if (broadcastedNote == null)
            {
                Assert.Fail("No broadcast has gone out");
            }

            Assert.That(broadcastedNote.VoteChange.RetroId, Is.EqualTo(retro.UrlId.StringId));
            Assert.That(broadcastedNote.VoteChange.Mutation, Is.EqualTo(VoteMutationType.Removed));
            Assert.That(broadcastedNote.VoteChange.Vote.NoteId, Is.EqualTo(note.Id));

            Assert.That(this.Context.NoteVotes.Select(x => x.Id), Does.Not.Contain(noteVote.Id));
        }
コード例 #3
0
        public void CastVoteCommandHandler_NoteGroupNotFound_ThrowsException()
        {
            // Given
            var handler = new CastVoteCommandHandler(
                this.Context,
                Substitute.For <ICurrentParticipantService>(),
                Substitute.For <ISecurityValidator>(),
                Substitute.For <IMediator>(),
                this.Mapper
                );
            var command = CastVoteCommand.ForNoteGroup(1337, VoteMutationType.Added);

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

            // Then
            Assert.That(action, Throws.InstanceOf <NotFoundException>());
        }
コード例 #4
0
        public async Task CastVoteCommandHandler_RemoveVote_VoteForNoteNotFound_ThrowsNothing()
        {
            // Given
            var handler = new CastVoteCommandHandler(
                this.Context,
                this._currentParticipantService,
                Substitute.For <ISecurityValidator>(),
                Substitute.For <IMediator>(),
                this.Mapper
                );
            Retrospective retro = await this.CreateRetrospectiveWithNote();

            CastVoteCommand command = CastVoteCommand.ForNote(retro.Notes.First().Id, VoteMutationType.Removed);

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

            // Then
            Assert.That(action, Throws.Nothing);
        }