public void TestVotingRetrunsTrueIfTheResponseIsOutOfRangeOnAnAnonymousePollAndUserNotLoggedIn_AboveMaxValue()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            int mockedUserID = 123456;
            IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, mockedUserID, false, false);
            Stub.On(mockedUser).GetProperty("BbcUid").Will(Return.Value("376A83FE-C114-8E06-698B-C66138D635AE"));

            PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
            testPoll.PollID = 123;
            testPoll.RedirectURL = @"/dna/actionnetwork/";
            testPoll.AllowAnonymousVoting = true;
            testPoll.SetResponseMinMax(0, 10);

            using (IDnaDataReader reader = CreateMockedDanDataReaderForAppContextWithValues("pollgetitemids", mockedAppContext, true, false))
            {
                // Test for value above the maximum
                Assert.IsTrue(testPoll.Vote(11), "Vote should return true if a non logged in users response to an anonymous poll is above the maximum value!");
                Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=2", testPoll.RedirectURL, "Redirect should contain an error code when a logged out users response to an anonymous poll is out of range");
            }
        }
        public void TestVotingReturnsTrueWithNoErrorsWhenAnonLoggedInUserWithValidResponseVotesOnAnAnonymousPoll()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            int mockedUserID = 123456;
            IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, mockedUserID, false, false);
            Stub.On(mockedUser).GetProperty("BbcUid").Will(Return.Value("376A83FE-C114-8E06-698B-C66138D635AE"));

            PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
            testPoll.PollID = 123;
            testPoll.RedirectURL = @"/dna/actionnetwork/";
            testPoll.AllowAnonymousVoting = true;
            testPoll.SetResponseMinMax(0, 10);

            using (IDnaDataReader reader = CreateMockedDanDataReaderForAppContextWithValues("pollgetitemids", mockedAppContext, true, false))
            {
                using (IDnaDataReader reader2 = CreateDataReaderForMockedAppContextForStoreProcedure("pollanonymouscontentratingvote", mockedAppContext))
                {
                    // Test for value below the minimum
                    Assert.IsTrue(testPoll.Vote(5), "Vote should return true if a logged in users response to an anonymous poll is within voting range!");
                    Assert.AreEqual(@"/dna/actionnetwork/", testPoll.RedirectURL, "Redirect should not contain an error code when logged in user votes with an inrange response!");
                }
            }
        }
        public void TestVotingReturnsTrueWIthErrorCodesWhenTheAuthorOfTheContentThatThePollIsLinkedToTriesToVote()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            int mockedUserID = 123456;
            IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, mockedUserID, true, false);
            Stub.On(mockedUser).GetProperty("BbcUid").Will(Return.Value("376A83FE-C114-8E06-698B-C66138D635AE"));

            PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
            testPoll.PollID = 123;
            testPoll.RedirectURL = "/dna/actionnetwork/";
            testPoll.AllowAnonymousVoting = true;

            using (IDnaDataReader mockedDataReader = CreateMockedDanDataReaderForAppContextWithValues("pollgetitemids", mockedAppContext, true, true))
            {
                Stub.On(mockedDataReader).Method("GetInt32").With("itemid").Will(Return.Value(654321));
                using (IDnaDataReader mockedDataReader2 = CreateMockedDanDataReaderForAppContextWithValues("pollgetarticleauthorid", mockedAppContext, true, true))
                {
                    Stub.On(mockedDataReader2).Method("GetInt32").With("userid").Will(Return.Value(mockedUserID));

                    Assert.IsTrue(testPoll.Vote(0), "Vote should return true if a logged in user who's the author of the content the poll is linked to!");
                    Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=6", testPoll.RedirectURL, "Redirect should contain an error code when the author of the content the poll is linked to tries to vote");
                }
            }
        }
 public void TestVotingReturnsFalseWhenLoggedInUserWithInValidUserIDTriesToVoteOnAnAnonymousVotingPoll()
 {
     // Create the app context for the poll to run in
     IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();
     IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, 0, true, false);
     PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
     testPoll.PollID = 123;
     testPoll.RedirectURL = @"/dna/actionnetwork/";
     testPoll.AllowAnonymousVoting = true;
     Assert.IsFalse(testPoll.Vote(0), "vote should return true if a logged in user with invalid userid tries to vote on an anonymous poll!");
     Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=0", testPoll.RedirectURL, "Redirect should contain an error code when trying to vote on an anonymous poll logged in with invalid user id");
 }
 public void TestVotingReturnsTrueWhenUserNotLoggedInVotingOnANonAnonymousPoll()
 {
     // Create the app context for the poll to run in
     IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();
     IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, 123, false, false);
     PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
     testPoll.PollID = 123;
     testPoll.RedirectURL = @"/dna/actionnetwork/";
     testPoll.AllowAnonymousVoting = false;
     Assert.IsTrue(testPoll.Vote(0), "vote should return true if a non logged in user tries to vote on a non anonymous poll!");
     Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=4", testPoll.RedirectURL, "Redirect should contain an error code when trying to vote on a non anonymous poll not logged in");
 }
 public void TestVoteReturnsFalseWhenRedirectGivenAndPollIDIsInvalid()
 {
     // Create the app context for the poll to run in
     IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();
     PollContentRating testPoll = new PollContentRating(mockedAppContext,null);
     testPoll.PollID = 0;
     testPoll.RedirectURL = @"/dna/actionnetwork/";
     Assert.IsFalse(testPoll.Vote(0), "vote should return false if the poll id is not valid!");
     Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=3", testPoll.RedirectURL, "Redirect should contain an error code when trying to hide a poll with an editor");
 }
 public void TestVoteReturnsTrueWhenNoRedirectGiven()
 {
     // Create the app context for the poll to run in
     IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();
     PollContentRating testPoll = new PollContentRating(mockedAppContext, null);
     testPoll.PollID = 0;
     testPoll.RedirectURL = "";
     Assert.IsTrue(testPoll.Vote(0), "Vote with no redirect value should return true!");
     Assert.AreEqual(@"<ERROR TYPE=""ERRORCODE_BADPARAMS""><ERRORMESSAGE>'s_redirectto' not set by skin</ERRORMESSAGE></ERROR>", testPoll.RootElement.InnerXml.ToString(), "The xml for the poll should contain an error about a missing redirect");
 }