コード例 #1
0
        public void Test_ParseRequestURLForCommand_ReturnsTrueForValidConfigPollCommandWithHideSetToOne()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            // Create a logged in editor
            IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, 123456, true, true);

            // Create the Poll. It won't need a user at this stage
            PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
            testPoll.PollID = 123;

            // Create a mocked data reader
            using (IDnaDataReader mockedDataReader = CreateMockedDanDataReaderForAppContextWithValues("HidePoll", mockedAppContext, true, true))
            {
                // Create the request object
                IRequest mockedRequest = _mock.NewMock<IRequest>();
                Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("s_redirectto", "Check the redirect for the poll exists").Will(Return.Value("/dna/actionnetwork/"));
                Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("cmd", "Get the command for the poll").Will(Return.Value("hidepoll"));
                Stub.On(mockedRequest).Method("DoesParamExist").With("hide", "Hide/Unhide bool param").Will(Return.Value(true));
                Stub.On(mockedRequest).Method("GetParamIntOrZero").With("hide", "Hide/Unhide bool param").Will(Return.Value(1));

                // Now test that the request is handled correctly
                Assert.IsTrue(testPoll.ParseRequestURLForCommand(mockedRequest), "Parsing the request with config poll command with hide = 1 should not fail!");
                Assert.AreEqual(@"/dna/actionnetwork/", testPoll.RedirectURL, "Redirect should not contain an error code when parsing the request with config poll command with hide = 1!");
            }
        }
コード例 #2
0
        public void Test_ParseRequestURLForCommand_ReturnsTrueForValidVoteCommand()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            // Create a non logged in user with valid bbcuid
            IUser mockedUser = CreateMockedUserForMockedAppContext(mockedAppContext, 123456, false, false);
            Stub.On(mockedUser).GetProperty("BbcUid").Will(Return.Value("376A83FE-C114-8E06-698B-C66138D635AE"));

            // Create the Poll. It won't need a user at this stage
            PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
            testPoll.SetResponseMinMax(0, 10);
            testPoll.PollID = 123;
            testPoll.AllowAnonymousVoting = true;

            // Mock the procedures the voting 
            using (IDnaDataReader reader = CreateMockedDanDataReaderForAppContextWithValues("pollgetitemids", mockedAppContext, true, false))
            {
                using (IDnaDataReader reader2 = CreateDataReaderForMockedAppContextForStoreProcedure("pollanonymouscontentratingvote", mockedAppContext))
                {
                    // Create the request object
                    IRequest mockedRequest = _mock.NewMock<IRequest>();
                    Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("s_redirectto", "Check the redirect for the poll exists").Will(Return.Value("/dna/actionnetwork/"));
                    Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("cmd", "Get the command for the poll").Will(Return.Value("vote"));
                    Stub.On(mockedRequest).Method("TryGetParamIntOrKnownValueOnError").With("response", -1, "Try to get the response for the poll vote").Will(Return.Value(5));

                    // Now test that the request is handled correctly
                    Assert.IsTrue(testPoll.ParseRequestURLForCommand(mockedRequest), "Parsing the request with valid vote command should not fail!");
                    Assert.AreEqual(@"/dna/actionnetwork/", testPoll.RedirectURL, "Redirect should not contain an error code when parsing the request with valid vote command!");
                }
            }
        }
コード例 #3
0
        public void Test_ParseRequestURLForCommand_ReturnsTrueForRemoveVoteCommand()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            // Create the Poll. It won't need a user at this stage
            PollContentRating testPoll = new PollContentRating(mockedAppContext, null);

            // Create the request object
            IRequest mockedRequest = _mock.NewMock<IRequest>();
            Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("s_redirectto", "Check the redirect for the poll exists").Will(Return.Value("/dna/actionnetwork/"));
            Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("cmd", "Get the command for the poll").Will(Return.Value("removevote"));

            // Now test that the request is handled correctly
            Assert.IsTrue(testPoll.ParseRequestURLForCommand(mockedRequest), "Parsing the request with remove vote command should not fail!");
            Assert.AreEqual(@"/dna/actionnetwork/?PollErrorCode=2", testPoll.RedirectURL, "Redirect should contain an error code when parsing the request with remove command!");
        }
コード例 #4
0
        public void Test_ParseRequestURLForCommand_FailsWithNoRedirect()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            // Create the request object
            IRequest mockedRequest = _mock.NewMock<IRequest>();
            Stub.On(mockedRequest).Method("GetParamStringOrEmpty").With("s_redirectto", "Check the redirect for the poll exists").Will(Return.Value(""));

            // Create the Poll. It won't need a user at this stage
            PollContentRating testPoll = new PollContentRating(mockedAppContext, null);

            // Now test that the request is handled correctly
            Assert.IsFalse(testPoll.ParseRequestURLForCommand(mockedRequest),"Parsing the request with no redirect should fail!");
            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");
        }