public void RequestedBallots_DoNotBelongToPoll()
            {
                var ballotManageGuid = new Guid("1AC3FABB-A077-4EF3-84DC-62074BA8FDF1");

                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll  = CreatePoll();

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var             ballot  = new Ballot()
                {
                    ManageGuid = ballotManageGuid
                };

                ballots.Add(ballot);
                polls.Add(poll);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots);
                ManageVoterController controller     = CreateManageVoteController(contextFactory);


                var request             = new DeleteVotersRequestModel();
                var ballotDeleteRequest = new DeleteBallotRequestModel()
                {
                    BallotManageGuid = ballotManageGuid
                };
                DeleteVoteRequestModel voteRequest = new DeleteVoteRequestModel();

                ballotDeleteRequest.VoteDeleteRequests.Add(voteRequest);
                request.BallotDeleteRequests.Add(ballotDeleteRequest);


                controller.Delete(PollManageGuid, request);
            }
            public void AllVotesRequestedRemovalForBallot_RemovesBallot()
            {
                const int pollChoiceNumber = 1;

                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll  = CreatePoll();

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var             ballot  = new Ballot()
                {
                    ManageGuid = PollManageGuid
                };

                IDbSet <Vote> votes = DbSetTestHelper.CreateMockDbSet <Vote>();
                var           vote  = new Vote()
                {
                    Choice = new Choice()
                    {
                        PollChoiceNumber = pollChoiceNumber
                    }
                };



                ballot.Votes.Add(vote);
                poll.Ballots.Add(ballot);

                votes.Add(vote);
                ballots.Add(ballot);
                polls.Add(poll);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots, votes);
                ManageVoterController controller     = CreateManageVoteController(contextFactory);

                var voteRequest = new DeleteVoteRequestModel {
                    ChoiceNumber = pollChoiceNumber
                };
                var ballotRequest = new DeleteBallotRequestModel {
                    BallotManageGuid = PollManageGuid
                };

                ballotRequest.VoteDeleteRequests.Add(voteRequest);

                var request = new DeleteVotersRequestModel();

                request.BallotDeleteRequests.Add(ballotRequest);


                controller.Delete(PollManageGuid, request);


                Assert.AreEqual(0, ballots.Count());
                Assert.AreEqual(0, poll.Ballots.Count());
            }
            public void RequestedVotes_DoNotBelongToBallot()
            {
                const int pollChoiceNumber1 = 1;
                const int pollChoiceNumber2 = 2;

                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll  = CreatePoll();

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var             ballot  = new Ballot()
                {
                    ManageGuid = PollManageGuid
                };

                IDbSet <Vote> votes = DbSetTestHelper.CreateMockDbSet <Vote>();
                var           vote  = new Vote()
                {
                    Choice = new Choice()
                    {
                        PollChoiceNumber = pollChoiceNumber1
                    }
                };



                ballot.Votes.Add(vote);
                poll.Ballots.Add(ballot);

                votes.Add(vote);
                ballots.Add(ballot);
                polls.Add(poll);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots, votes);
                ManageVoterController controller     = CreateManageVoteController(contextFactory);

                var voteRequest = new DeleteVoteRequestModel {
                    ChoiceNumber = pollChoiceNumber2
                };
                var ballotRequest = new DeleteBallotRequestModel {
                    BallotManageGuid = PollManageGuid
                };

                ballotRequest.VoteDeleteRequests.Add(voteRequest);

                var request = new DeleteVotersRequestModel();

                request.BallotDeleteRequests.Add(ballotRequest);


                controller.Delete(PollManageGuid, request);
            }
            public void ClearedVotesGenerateVoteDeletionMetric()
            {
                // Arrange
                Choice option = new Choice()
                {
                    PollChoiceNumber = 1, Id = 1, Name = "Choice"
                };
                Poll poll = new Poll()
                {
                    UUID = Guid.NewGuid(), ManageId = Guid.NewGuid(), Choices = new List <Choice>()
                    {
                        option
                    }
                };
                Ballot ballot = new Ballot()
                {
                    TokenGuid = Guid.NewGuid(), Votes = new List <Vote>(), ManageGuid = Guid.NewGuid()
                };
                Vote voteToClear = new Vote()
                {
                    Ballot = ballot, Poll = poll, VoteValue = 1, Choice = option
                };

                ballot.Votes.Add(voteToClear);
                poll.Ballots.Add(ballot);

                var options = DbSetTestHelper.CreateMockDbSet <Choice>();
                var polls   = DbSetTestHelper.CreateMockDbSet <Poll>();
                var ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var votes   = DbSetTestHelper.CreateMockDbSet <Vote>();

                options.Add(option);
                polls.Add(poll);
                ballots.Add(ballot);
                votes.Add(voteToClear);

                var metricHandler  = new Mock <IMetricHandler>();
                var contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots, votes, options);
                ManageVoterController controller = CreateManageVoteController(contextFactory, metricHandler.Object);

                // Act
                DeleteVoteRequestModel voteDelete = new DeleteVoteRequestModel()
                {
                    ChoiceNumber = 1
                };
                DeleteBallotRequestModel deletion = new DeleteBallotRequestModel()
                {
                    BallotManageGuid = ballot.ManageGuid, VoteDeleteRequests = new List <DeleteVoteRequestModel>()
                    {
                        voteDelete
                    }
                };
                List <DeleteBallotRequestModel> ballotDeletions = new List <DeleteBallotRequestModel>()
                {
                    deletion
                };
                DeleteVotersRequestModel request = new DeleteVotersRequestModel()
                {
                    BallotDeleteRequests = ballotDeletions
                };

                controller.Delete(poll.ManageId, request);

                // Assert
                metricHandler.Verify(m => m.HandleVoteDeletedEvent(voteToClear, poll.UUID), Times.Once());
            }