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!"); } } }
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!"); } } }
/// <summary> /// Creates a new valid content rating poll /// </summary> /// <param name="minResponse">The minimum response value</param> /// <param name="maxResponse">The maximum response value</param> /// <param name="appContext">The App context you want to create the poll in</param> /// <returns>The new poll</returns> private PollContentRating CreateValidPoll(int minResponse, int maxResponse, IAppContext appContext) { // Create the app context for the poll to run in using (IDnaDataReader reader = CreateDataReaderForMockedAppContextForStoreProcedure("CreateNewVote", appContext)) { PollContentRating testPoll = new PollContentRating(appContext, null); testPoll.SetResponseMinMax(0, 10); if (!testPoll.CreatePoll()) { return null; } return testPoll; } }
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 TestCreateNewPollWithRange() { // Create the app context for the poll to run in IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics(); using (IDnaDataReader reader = CreateDataReaderForMockedAppContextForStoreProcedure("CreateNewVote", mockedAppContext)) { PollContentRating testPoll = new PollContentRating(mockedAppContext, null); testPoll.SetResponseMinMax(0, 10); Assert.IsTrue(testPoll.CreatePoll(), "Creating a poll with a range should return true!"); } }