Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public async Task CastVoteCommandHandler_NoteGroupVoteRemoved_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();

            NoteGroup noteGroup = retro.NoteGroup.First();

            NoteVote note = this.Context.NoteVotes.Add(new NoteVote {
                NoteGroup     = noteGroup,
                Participant   = retro.Participants.First(),
                Retrospective = retro
            }).Entity;

            await this.Context.SaveChangesAsync();

            CastVoteCommand command = CastVoteCommand.ForNoteGroup(noteGroup.Id, VoteMutationType.Removed);

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

            // Then
            TestContext.WriteLine(securityValidator.ReceivedCalls().Select(x => x.GetMethodInfo().Name).FirstOrDefault());
            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.NoteGroupId, Is.EqualTo(noteGroup.Id));

            Assert.That(this.Context.NoteVotes.Select(x => x.Id), Does.Not.Contain(note.Id));
        }
Exemplo n.º 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>());
        }
Exemplo n.º 4
0
        public async Task CastVoteCommandHandler_RemoveVote_VoteForNoteGroupNotFound_ThrowsNothing()
        {
            // Given
            var handler = new CastVoteCommandHandler(
                this.Context,
                this._currentParticipantService,
                Substitute.For <ISecurityValidator>(),
                Substitute.For <IMediator>(),
                this.Mapper
                );

            Retrospective retro = await this.CreateRetrospectiveWithNoteGroup();

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

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

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