Exemplo n.º 1
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.");
            }
        }
Exemplo n.º 2
0
        public void Test_Statistics_BlankName()
        {
            // 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;

                // try to set stat with invalid name
                testPoll.SetPollStatistic("", "blah-value");

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

                XmlDocument doc = new XmlDocument();
                XmlNode docNode = doc.ImportNode(testPoll.RootElement, true);
                XmlNode errorNode = docNode.SelectSingleNode("ERROR");
                Assert.IsNotNull(errorNode, "Failed to find ERROR element");
                XmlNode errorAttribute = errorNode.Attributes.GetNamedItem("TYPE");
                Assert.IsTrue(errorAttribute.Value.Equals("2"), "Unexpected value for error code.");

                XmlNode statNode = docNode.SelectSingleNode("POLL/STATISTICS");
                Assert.IsNull(statNode, "Inexpected POLL/STATISTICS element");
            }
        }