예제 #1
0
        /// <summary>
        /// AddPollXml - Delegates responsibility of producing standard Poll Xml to the Poll Class.
        /// Only produces Poll Xml where a valid Poll exists in the resultset.
        /// </summary>
        /// <param name="dataReader">Record set containing the data</param>
        /// <param name="parent">Parent node to add the xml to</param>
        private void AddPollXml(IDnaDataReader dataReader, XmlNode parent)
        {
            if (dataReader.DoesFieldExist("CRPollID"))
            {
                int pollId = dataReader.GetInt32NullAsZero("CRPollID");
                if (pollId > 0)
                {
                    PollContentRating poll = new PollContentRating(this.InputContext, this.InputContext.ViewingUser);

                    poll.PollID = dataReader.GetInt32NullAsZero("CRPollID");
                    poll.Hidden = dataReader.GetInt32NullAsZero("Hidden") != 0;
                    int voteCount = dataReader.GetInt32NullAsZero("CRVoteCount");
                    double avgRating = dataReader.GetDoubleNullAsZero("CRAverageRating");
                    poll.SetContentRatingStatistics(voteCount, avgRating);
                    XmlNode node = poll.MakePollXML(false);
                    if (node != null)
                    {
                        parent.AppendChild(ImportNode(node));
                    }
                }
            }
        }
예제 #2
0
        public void Test_Statistics_RemoveAStat()
        {
            // Create the app context for the poll to run in
            IAppContext mockedAppContext = CreateMockedAppContextAndDiagnostics();

            // Create data reader for load user vote. 
            using (IDnaDataReader mockedDataReader = CreateMockedDanDataReaderForAppContextWithValues("GetUserVotes", mockedAppContext, true, true))
            {
                Stub.On(mockedDataReader).Method("GetInt32").WithAnyArguments().Will(Return.Value(1));

                Stub.On(mockedAppContext).Method("CreateDnaDataReader").With("GetUserVotes").Will(Return.Value(mockedDataReader));

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

                // Create the Poll.
                PollContentRating testPoll = new PollContentRating(mockedAppContext, mockedUser);
                testPoll.PollID = 123;

                // add VOTECOUNT and AVERAGERATING
                testPoll.SetContentRatingStatistics(5, 2.2);
                testPoll.SetPollStatistic("votecount", null);

                Assert.IsTrue(testPoll.MakePollXML(false) != null, "MakePollXML should return true when user is logged in and stats set.");

                // Check Xml
                XmlDocument doc = new XmlDocument();
                XmlNode docNode = doc.ImportNode(testPoll.RootElement, true);
                XmlNode statNode = docNode.SelectSingleNode("POLL/STATISTICS");
                Assert.IsNotNull(statNode, "Failed to find POLL/STATISTICS");



                // Check values of Statistics XML
                Assert.IsTrue(statNode.Attributes.Count == 1, "Unexpected attributes in Poll Statistics");
                XmlNode countNode = statNode.Attributes.GetNamedItem("VOTECOUNT");
                Assert.IsNull(countNode, "Found VOTECOUNT attribute when we should not have.");

                XmlNode avgRatingNode = statNode.Attributes.GetNamedItem("AVERAGERATING");
                Assert.IsTrue(avgRatingNode.Value.Equals("2.2"), "AVERAGERATING attribute is not an expected value.");
            }
        }