Exemplo n.º 1
0
            public void ChoiceAddingAllowedForPoll_AddsChoice()
            {
                const string optionName        = "new option";
                const string optionDescription = "description";

                IDbSet <Poll>   polls   = DbSetTestHelper.CreateMockDbSet <Poll>();
                IDbSet <Choice> options = DbSetTestHelper.CreateMockDbSet <Choice>();

                polls.Add(new Poll()
                {
                    UUID = PollManageGuid, ChoiceAdding = true
                });


                IContextFactory      contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, options);
                PollChoiceController controller     = CreatePollChoiceController(contextFactory);


                ChoiceCreationRequestModel optionCreationRequestModel = new ChoiceCreationRequestModel()
                {
                    Name        = optionName,
                    Description = optionDescription,
                };

                controller.Post(PollManageGuid, optionCreationRequestModel);

                Assert.AreEqual(1, options.Count());
                Assert.AreEqual(optionName, options.First().Name);
                Assert.AreEqual(optionDescription, options.First().Description);
            }
Exemplo n.º 2
0
            public void AlteringMiscConfigGeneratesMetrics()
            {
                // Arrange
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPolls.Add(existingPoll);

                existingPoll.NamedVoting  = false;
                existingPoll.InviteOnly   = false;
                existingPoll.ChoiceAdding = false;

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);
                ManagePollMiscRequest request        = new ManagePollMiscRequest {
                    InviteOnly = true, NamedVoting = true, ChoiceAdding = true
                };

                Mock <IMetricHandler> metricHandler = new Mock <IMetricHandler>();
                ManageMiscController  controller    = CreateManageExpiryController(contextFactory, metricHandler.Object);

                // Act
                controller.Put(PollManageGuid, request);

                // Assert
                metricHandler.Verify(m => m.HandleInviteOnlyChangedEvent(true, existingPoll.UUID), Times.Once());
                metricHandler.Verify(m => m.HandleNamedVotingChangedEvent(true, existingPoll.UUID), Times.Once());
                metricHandler.Verify(m => m.HandleChoiceAddingChangedEvent(true, existingPoll.UUID), Times.Once());
            }
Exemplo n.º 3
0
            public void CreatesBallotForCreator()
            {
                Guid pollId = new Guid("00DB2F1B-C4F5-44D3-960C-386CEB9690C4");

                var existingPoll = new Poll()
                {
                    CreatorIdentity = UserId1, UUID = pollId
                };

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

                polls.Add(existingPoll);

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                IContextFactory     mockContextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots);
                DashboardController controller         = CreateDashboardController(mockContextFactory);

                controller.User = CreateAuthenticatedUser(UserId1);

                var request = new CopyPollRequestModel()
                {
                    UUIDToCopy = pollId
                };


                controller.Copy(request);


                Poll copiedPoll = polls.ToList()[1];

                Assert.AreEqual(1, copiedPoll.Ballots.Count());
            }
Exemplo n.º 4
0
            public void AddingChoiceGeneratesMetric()
            {
                // Arrange
                IDbSet <Poll>        polls          = DbSetTestHelper.CreateMockDbSet <Poll>();
                var                  contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);
                var                  metricHandler  = new Mock <IMetricHandler>();
                PollChoiceController controller     = CreatePollChoiceController(contextFactory, metricHandler.Object);

                Poll existingPoll = new Poll()
                {
                    Choices = new List <Choice>(), UUID = Guid.NewGuid(), ChoiceAdding = true
                };

                polls.Add(existingPoll);

                ChoiceCreationRequestModel request = new ChoiceCreationRequestModel()
                {
                    Name = "New Choice"
                };

                // Act
                controller.Post(existingPoll.UUID, request);

                // Assert
                metricHandler.Verify(m => m.HandleChoiceAddedEvent(It.Is <Choice>(o => o.Name == "New Choice"), existingPoll.UUID), Times.Once());
            }
            public void UnchangedExpiryDateDoesNotGenerateMetric()
            {
                // Arrange
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();
                DateTime      currentExpiry = DateTime.UtcNow.AddHours(1);

                existingPoll.ExpiryDateUtc = currentExpiry;
                existingPolls.Add(existingPoll);


                IContextFactory         contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);
                ManagePollExpiryRequest request        = new ManagePollExpiryRequest {
                    ExpiryDateUtc = currentExpiry
                };

                Mock <IMetricHandler>  metricHandler = new Mock <IMetricHandler>();
                ManageExpiryController controller    = CreateManageExpiryController(contextFactory, metricHandler.Object);

                // Act
                controller.Put(PollManageGuid, request);

                // Assert
                metricHandler.Verify(m => m.HandleExpiryChangedEvent(It.IsAny <DateTimeOffset?>(), It.IsAny <Guid>()), Times.Never());
            }
            public void NoXTokenGuidHeader_Response_Choices_ContainsVoteValueZero()
            {
                const int choiceId = 42;

                var choice = new Choice()
                {
                    Id               = choiceId,
                    Name             = "A choice",
                    Description      = "Some description",
                    PollChoiceNumber = 13
                };

                Poll poll = CreateNonInviteOnlyPoll();

                poll.Choices.Add(choice);

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

                polls.Add(poll);
                IDbSet <Choice> choices = DbSetTestHelper.CreateMockDbSet <Choice>();

                choices.Add(choice);

                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, choices);

                PollController controller = CreatePollController(contextFactory);


                PollRequestResponseModel response = controller.Get(PollId);

                PollRequestChoiceResponseModel responseChoice = response.Choices.Single();

                Assert.AreEqual(0, responseChoice.VoteValue);
            }
            public void InviteOnly_XTokenGuidHeader_BallotInPoll_ReturnsHeaderValueAsTokenGuid()
            {
                var ballot = new Ballot()
                {
                    TokenGuid = TokenGuid
                };

                Poll poll = CreateInviteOnlyPoll();

                poll.Ballots.Add(ballot);

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

                polls.Add(poll);
                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                ballots.Add(ballot);

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

                PollController controller = CreatePollController(contextFactory);

                AddXTokenGuidHeader(controller, TokenGuid);


                controller.Get(PollId);
            }
Exemplo n.º 8
0
            public void SettingExistingMiscSettingsDoesNotGenerateMetrics()
            {
                // Arrange
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPolls.Add(existingPoll);

                existingPoll.NamedVoting  = false;
                existingPoll.InviteOnly   = false;
                existingPoll.ChoiceAdding = false;

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);
                ManagePollMiscRequest request        = new ManagePollMiscRequest {
                    InviteOnly = false, NamedVoting = false, ChoiceAdding = false
                };

                Mock <IMetricHandler> metricHandler = new Mock <IMetricHandler>();
                ManageMiscController  controller    = CreateManageExpiryController(contextFactory, metricHandler.Object);

                // Act
                controller.Put(PollManageGuid, request);

                // Assert
                metricHandler.Verify(m => m.HandleInviteOnlyChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never());
                metricHandler.Verify(m => m.HandleNamedVotingChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never());
                metricHandler.Verify(m => m.HandleChoiceAddingChangedEvent(It.IsAny <bool>(), It.IsAny <Guid>()), Times.Never());
            }
Exemplo n.º 9
0
            public void BallotWithNoVotes_IsNotReturned()
            {
                var pollManageGuid = new Guid("992E252C-56DB-4E9D-9A31-F5BBA3FA5361");

                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll  = new Poll()
                {
                    ManageId = pollManageGuid
                };

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var             ballot  = new Ballot()
                {
                    ManageGuid = new Guid("96ADD6EF-DFE4-4160-84C5-63EDC3076A1B")
                };

                IDbSet <Vote> votes = DbSetTestHelper.CreateMockDbSet <Vote>();

                poll.Ballots.Add(ballot);

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

                IContextFactory  contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots, votes);
                ManageController controller     = CreateManageController(contextFactory);


                ManagePollRequestResponseModel response = controller.Get(pollManageGuid);


                Assert.AreEqual(0, response.VotersCount);
            }
Exemplo n.º 10
0
            public void NonInviteOnly_XTokenGuidHeader_ReturnsHeaderValueAsTokenGuid()
            {
                IDbSet <Poll>   polls   = DbSetTestHelper.CreateMockDbSet <Poll>();
                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                var ballot = new Ballot()
                {
                    TokenGuid = TokenGuid
                };

                Poll nonInviteOnlyPoll = CreateNonInviteOnlyPoll();

                nonInviteOnlyPoll.Ballots.Add(ballot);

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

                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);

                PollController controller = CreatePollController(contextFactory);

                AddXTokenGuidHeader(controller, TokenGuid);


                PollRequestResponseModel response = controller.Get(PollId);

                Assert.AreEqual(TokenGuid, response.TokenGuid);
            }
Exemplo n.º 11
0
            public void UnChangedPollType_LeavesVotes()
            {
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPoll.PollType   = PollType.Basic;
                existingPoll.MaxPoints  = 1;
                existingPoll.MaxPerVote = 1;
                existingPolls.Add(existingPoll);

                Vote testVote = new Vote()
                {
                    Poll = existingPoll
                };

                IDbSet <Ballot> existingBallots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                IDbSet <Vote> existingVotes = DbSetTestHelper.CreateMockDbSet <Vote>();

                existingVotes.Add(testVote);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls, existingBallots, existingVotes);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                    PollType = "Basic", MaxPerVote = 1, MaxPoints = 1
                };

                ManagePollTypeController controller = CreateManagePollTypeController(contextFactory);

                controller.Put(PollManageGuid, request);

                Assert.AreEqual(1, existingVotes.Local.Count);
            }
            public void PollWithChoices_ReturnsAll()
            {
                const int    option1ChoiceNumber = 1;
                const string option1Name         = "Choice 1";
                const string option1Description  = "Description 1";

                const int    option2ChoiceNumber = 2;
                const string option2Name         = "Choice 2";
                const string option2Description  = "Description 2";


                IDbSet <Poll>   polls   = DbSetTestHelper.CreateMockDbSet <Poll>();
                IDbSet <Choice> options = DbSetTestHelper.CreateMockDbSet <Choice>();

                Poll poll = new Poll()
                {
                    ManageId = PollManageGuid
                };

                polls.Add(poll);

                Choice option1 = new Choice()
                {
                    Name             = option1Name,
                    Description      = option1Description,
                    PollChoiceNumber = option1ChoiceNumber
                };
                Choice option2 = new Choice()
                {
                    Name             = option2Name,
                    Description      = option2Description,
                    PollChoiceNumber = option2ChoiceNumber
                };

                options.Add(option1);
                options.Add(option2);

                poll.Choices.Add(option1);
                poll.Choices.Add(option2);

                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, options);

                ManageChoiceController controller = CreateManageChoiceController(contextFactory);

                IEnumerable <ManageChoiceResponseModel> response = controller.Get(PollManageGuid);

                Assert.AreEqual(2, response.Count());

                ManageChoiceResponseModel responseChoice1 = response.First();

                Assert.AreEqual(option1ChoiceNumber, responseChoice1.ChoiceNumber);
                Assert.AreEqual(option1Name, responseChoice1.Name);
                Assert.AreEqual(option1Description, responseChoice1.Description);

                ManageChoiceResponseModel responseChoice2 = response.Last();

                Assert.AreEqual(option2ChoiceNumber, responseChoice2.ChoiceNumber);
                Assert.AreEqual(option2Name, responseChoice2.Name);
                Assert.AreEqual(option2Description, responseChoice2.Description);
            }
            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);
            }
Exemplo n.º 14
0
            public void ChangingToPointsPollWithoutChangingPointsValuesGeneratesMetric()
            {
                // Arrange
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPoll.PollType   = PollType.Basic;
                existingPoll.MaxPerVote = 3;
                existingPoll.MaxPoints  = 7;
                existingPolls.Add(existingPoll);

                IDbSet <Vote> votes        = DbSetTestHelper.CreateMockDbSet <Vote>();
                Vote          existingVote = new Vote()
                {
                    Poll = existingPoll
                };

                votes.Add(existingVote);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls, DbSetTestHelper.CreateMockDbSet <Ballot>(), votes);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                    PollType = "Points", MaxPerVote = 3, MaxPoints = 7
                };

                Mock <IMetricHandler>    mockMetricHandler = new Mock <IMetricHandler>();
                ManagePollTypeController controller        = CreateManagePollTypeController(contextFactory, mockMetricHandler.Object);

                // Act
                controller.Put(PollManageGuid, request);

                // Assert
                mockMetricHandler.Verify(m => m.HandlePollTypeChangedEvent(PollType.Points, 3, 7, existingPoll.UUID), Times.Once());
                mockMetricHandler.Verify(m => m.HandleVoteDeletedEvent(existingVote, existingPoll.UUID), Times.Once());
            }
Exemplo n.º 15
0
            public void InvalidPollType_ReturnsBadRequest()
            {
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPolls.Add(existingPoll);

                Vote testVote = new Vote()
                {
                    Poll = existingPoll
                };

                IDbSet <Ballot> existingBallots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                IDbSet <Vote> existingVotes = DbSetTestHelper.CreateMockDbSet <Vote>();

                existingVotes.Add(testVote);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls, existingBallots, existingVotes);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                    PollType = "NotAnChoice", MaxPerVote = 1, MaxPoints = 1
                };

                ManagePollTypeController controller = CreateManagePollTypeController(contextFactory);

                controller.Put(PollManageGuid, request);

                Assert.AreEqual(0, existingVotes.Local.Count);
            }
Exemplo n.º 16
0
            public void SetMaxValues_SetsMaxValues()
            {
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPolls.Add(existingPoll);

                IDbSet <Ballot> existingBallots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                IDbSet <Vote>   existingVotes   = DbSetTestHelper.CreateMockDbSet <Vote>();

                int maxPerVote = 15;
                int maxPoints  = 17;

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls, existingBallots, existingVotes);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                    PollType = "UpDown", MaxPerVote = maxPerVote, MaxPoints = maxPoints
                };

                ManagePollTypeController controller = CreateManagePollTypeController(contextFactory);

                controller.Put(PollManageGuid, request);

                Assert.AreEqual(maxPerVote, existingPoll.MaxPerVote);
                Assert.AreEqual(maxPoints, existingPoll.MaxPoints);
            }
            public void PollWithBallotContainingNoVotes_ReturnsEmptyList()
            {
                Guid pollManageGuid = new Guid("EBDE4ED9-D014-4145-B998-13B5A247BB4B");

                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll          =
                    new Poll()
                {
                    ManageId = pollManageGuid,
                    Ballots  = new List <Ballot>()
                    {
                        new Ballot()
                    }
                };

                existingPolls.Add(poll);
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);

                ManageVoterController controller = CreateManageVoteController(contextFactory);


                List <ManageVoteResponseModel> response = controller.Get(pollManageGuid);


                CollectionAssert.AreEqual(new List <ManageVoteResponseModel>(), response);
            }
Exemplo n.º 18
0
            public void IdenticalPollTypeDoesNotGenerateMetric()
            {
                // Arrange
                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                Poll          existingPoll  = CreatePoll();

                existingPoll.PollType   = PollType.Points;
                existingPoll.MaxPerVote = 3;
                existingPoll.MaxPoints  = 7;
                existingPolls.Add(existingPoll);

                IDbSet <Vote> votes        = DbSetTestHelper.CreateMockDbSet <Vote>();
                Vote          existingVote = new Vote()
                {
                    Poll = existingPoll
                };

                votes.Add(existingVote);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls, DbSetTestHelper.CreateMockDbSet <Ballot>(), votes);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                    PollType = "Points", MaxPerVote = 3, MaxPoints = 7
                };

                Mock <IMetricHandler>    mockMetricHandler = new Mock <IMetricHandler>();
                ManagePollTypeController controller        = CreateManagePollTypeController(contextFactory, mockMetricHandler.Object);

                // Act
                controller.Put(PollManageGuid, request);

                // Assert
                mockMetricHandler.Verify(m => m.HandlePollTypeChangedEvent(It.IsAny <PollType>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Guid>()), Times.Never());
                mockMetricHandler.Verify(m => m.HandleVoteDeletedEvent(It.IsAny <Vote>(), It.IsAny <Guid>()), Times.Never());
            }
            public void DeletingAnChoiceGeneratesADeleteChoiceMetric()
            {
                // Arrange
                var                    metricHandler  = new Mock <IMetricHandler>();
                IDbSet <Poll>          polls          = DbSetTestHelper.CreateMockDbSet <Poll>();
                var                    contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);
                ManageChoiceController controller     = CreateManageChoiceController(contextFactory, metricHandler.Object);

                Poll existingPoll = new Poll()
                {
                    Choices = new List <Choice>(), UUID = Guid.NewGuid(), ManageId = Guid.NewGuid()
                };

                polls.Add(existingPoll);

                Choice existingChoice = new Choice()
                {
                    Name = "New Choice", PollChoiceNumber = 1
                };

                existingPoll.Choices.Add(existingChoice);
                ManageChoiceUpdateRequest request = new ManageChoiceUpdateRequest()
                {
                    Choices = new List <ChoiceUpdate>()
                };

                // Act
                controller.Put(existingPoll.ManageId, request);

                // Assert
                metricHandler.Verify(m => m.HandleChoiceDeletedEvent(existingChoice, existingPoll.UUID), Times.Once());
                metricHandler.Verify(m => m.HandleChoiceAddedEvent(It.IsAny <Choice>(), It.IsAny <Guid>()), Times.Never());
                metricHandler.Verify(m => m.HandleChoiceUpdatedEvent(It.IsAny <Choice>(), It.IsAny <Guid>()), Times.Never());
            }
            public void PollWithBallotsWithVotes_ReturnsAll()
            {
                var          manageGuid = new Guid("A76287F6-BC56-421C-9294-A477D1E9C4B3");
                const string voterName  = "Derek";

                const int    optionNumber = 1;
                const string optionName   = "Value?";
                const int    optionValue  = 23;

                IDbSet <Poll> existingPolls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll          = new Poll()
                {
                    ManageId = PollManageGuid
                };

                var ballot = new Ballot()
                {
                    ManageGuid = manageGuid,
                    VoterName  = voterName,
                    TokenGuid  = new Guid("1AC3FABB-A077-4EF3-84DC-62074BA8FDF1")
                };

                var vote = new Vote()
                {
                    Choice = new Choice()
                    {
                        PollChoiceNumber = optionNumber,
                        Name             = optionName
                    },
                    VoteValue = optionValue
                };


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

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);
                ManageVoterController controller     = CreateManageVoteController(contextFactory);


                List <ManageVoteResponseModel> response = controller.Get(PollManageGuid);


                Assert.AreEqual(1, response.Count);

                ManageVoteResponseModel responseBallot = response[0];

                Assert.AreEqual(manageGuid, responseBallot.BallotManageGuid);
                Assert.AreEqual(voterName, responseBallot.VoterName);
                Assert.AreEqual(1, responseBallot.Votes.Count);

                VoteResponse responseVote = responseBallot.Votes[0];

                Assert.AreEqual(optionName, responseVote.ChoiceName);
                Assert.AreEqual(optionValue, responseVote.Value);
                Assert.AreEqual(optionNumber, responseVote.ChoiceNumber);
            }
Exemplo n.º 21
0
            public void InviteOnly_XTokenGuidHeader_BallotInPoll_ReturnsWinners()
            {
                const int    winnerPollChoiceNumber = 1;
                const string winnerName             = "Winner-winner-chicken-dinner";

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

                polls.Add(poll);

                IDbSet <Choice> choices       = DbSetTestHelper.CreateMockDbSet <Choice>();
                var             winningChoice = new Choice()
                {
                    Name             = winnerName,
                    PollChoiceNumber = winnerPollChoiceNumber,
                    Id = 1
                };
                var losingChoice = new Choice()
                {
                    PollChoiceNumber = 2, Id = 2
                };

                choices.Add(winningChoice);
                choices.Add(losingChoice);

                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();
                var             ballot  = new Ballot()
                {
                    VoterName = "Barbara", TokenGuid = TokenGuid
                };

                ballots.Add(ballot);
                poll.Ballots.Add(ballot);
                poll.Choices.AddRange(choices);

                IDbSet <Vote> votes = DbSetTestHelper.CreateMockDbSet <Vote>();
                var           vote  = new Vote()
                {
                    Choice = winningChoice, Poll = poll, Ballot = ballot, VoteValue = 1
                };

                votes.Add(vote);
                ballot.Votes.Add(vote);

                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots, votes, choices);
                PollResultsController controller     = CreatePollController(contextFactory);

                AddXTokenGuidHeader(controller, TokenGuid);


                ResultsRequestResponseModel response = controller.Get(PollId);

                Assert.AreEqual(1, response.Winners.Count);

                string winner = response.Winners.First();

                Assert.AreEqual(winnerName, winner);
            }
            public void UnknownManageId_ReturnsNotFound()
            {
                IDbSet <Poll>   polls          = DbSetTestHelper.CreateMockDbSet <Poll>();
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);

                ManageChoiceController controller = CreateManageChoiceController(contextFactory);

                controller.Get(PollManageGuid);
            }
            public void NullUpdateRequest_ThrowsError()
            {
                IDbSet <Poll>   polls          = DbSetTestHelper.CreateMockDbSet <Poll>();
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);

                ManageChoiceController controller = CreateManageChoiceController(contextFactory);

                controller.Put(PollManageGuid, null);
            }
            public void NullRequest_ThrowsBadRequest()
            {
                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();

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


                controller.Delete(PollManageGuid, null);
            }
Exemplo n.º 25
0
            public void InviteOnly_XTokenGuidHeader_BallotInPoll_ReturnsPoll()
            {
                const string   pollName = "Why are we here?";
                const PollType pollType = PollType.UpDown;

                var ballot = new Ballot()
                {
                    TokenGuid = TokenGuid
                };

                var poll = new Poll()
                {
                    UUID     = PollId,
                    Name     = pollName,
                    PollType = pollType,

                    MaxPoints  = 5,
                    MaxPerVote = 1,

                    ExpiryDateUtc = null,

                    NamedVoting  = false,
                    ChoiceAdding = false,
                    InviteOnly   = true
                };

                poll.Ballots.Add(ballot);

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

                polls.Add(poll);
                IDbSet <Ballot> ballots = DbSetTestHelper.CreateMockDbSet <Ballot>();

                ballots.Add(ballot);
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, ballots);

                PollController controller = CreatePollController(contextFactory);

                AddXTokenGuidHeader(controller, TokenGuid);


                PollRequestResponseModel response = controller.Get(PollId);


                Assert.AreEqual(pollName, response.Name);
                Assert.AreEqual(pollType.ToString(), response.PollType);
                Assert.IsNull(response.ExpiryDateUtc);

                Assert.AreEqual(5, response.MaxPoints);
                Assert.AreEqual(1, response.MaxPerVote);

                Assert.IsFalse(response.NamedVoting);
                Assert.IsFalse(response.ChoiceAdding);
                Assert.IsFalse(response.UserHasVoted);
            }
            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());
            }
Exemplo n.º 27
0
            public void InviteOnly_NoXTokenGuidHeader_ThrowsUnauthorized()
            {
                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();

                polls.Add(CreateInviteOnlyPoll());
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);

                PollResultsController controller = CreatePollController(contextFactory);

                controller.Get(PollId);
            }
            public void UnknownPollManageGuid_ThrowsNotFound()
            {
                IDbSet <Poll>   polls          = DbSetTestHelper.CreateMockDbSet <Poll>();
                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls);

                var request = new ManageChoiceUpdateRequest();

                ManageChoiceController controller = CreateManageChoiceController(contextFactory);

                controller.Put(PollManageGuid, request);
            }
            public void ChoiceWithPollChoiceNumber_IsUpdated()
            {
                const string optionName        = "Some Choice";
                const string optionDescription = "Some Description";
                const int    pollChoiceNumber  = 2;

                const string newChoiceName        = "Some other option";
                const string newChoiceDescription = "Some other description";


                IDbSet <Poll> polls = DbSetTestHelper.CreateMockDbSet <Poll>();
                var           poll  = new Poll()
                {
                    ManageId = PollManageGuid
                };


                IDbSet <Choice> options = DbSetTestHelper.CreateMockDbSet <Choice>();
                var             option  = new Choice()
                {
                    Name             = optionName,
                    Description      = optionDescription,
                    PollChoiceNumber = pollChoiceNumber
                };

                poll.Choices.Add(option);

                options.Add(option);
                polls.Add(poll);


                IContextFactory contextFactory = ContextFactoryTestHelper.CreateContextFactory(polls, options);

                var request = new ManageChoiceUpdateRequest();

                var optionRequest = new ChoiceUpdate()
                {
                    Name         = newChoiceName,
                    Description  = newChoiceDescription,
                    ChoiceNumber = pollChoiceNumber
                };

                request.Choices.Add(optionRequest);


                ManageChoiceController controller = CreateManageChoiceController(contextFactory);


                controller.Put(PollManageGuid, request);


                Assert.AreEqual(newChoiceName, options.First().Name);
                Assert.AreEqual(newChoiceDescription, options.First().Description);
            }
Exemplo n.º 30
0
            public void UnknownManageId_ReturnsNotFound()
            {
                IDbSet <Poll>         existingPolls  = DbSetTestHelper.CreateMockDbSet <Poll>();
                IContextFactory       contextFactory = ContextFactoryTestHelper.CreateContextFactory(existingPolls);
                ManagePollTypeRequest request        = new ManagePollTypeRequest {
                };

                ManagePollTypeController controller = CreateManagePollTypeController(contextFactory);

                controller.Put(Guid.NewGuid(), request);
            }