public void TestXmlNoModClass()
        {
            Mockery mocks = new Mockery();
            IInputContext context = mocks.NewMock<IInputContext>();
            IDnaDataReader mockedReader = mocks.NewMock<IDnaDataReader>();
            Stub.On(context).Method("CreateDnaDataReader").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).Method("Dispose");
            IAction mockReaderResults = new MockedReaderResults(new object[] { true, false });
            Stub.On(mockedReader).Method("Read").Will(mockReaderResults);

            // Check Stored Procedure is called as expected.
            Expect.Never.On(mockedReader).Method("AddParameter").With("modclassid");

            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("reasonid").Will(Return.Value(6));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("displayname").Will(Return.Value("DisplayName"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("emailname").Will(Return.Value("EmailName"));
            Stub.On(mockedReader).Method("GetTinyIntAsInt").With("editorsonly").Will(Return.Value(0));

            ModerationReasons modReasons = new ModerationReasons(context);
            modReasons.GenerateXml(0);

            //Check XML.is as expected.
            XmlNode node = modReasons.RootElement.SelectSingleNode(@"MOD-REASONS");
            Assert.IsNotNull(node, "ModerationReasons Element Found");
            Assert.IsNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/@MODCLASSID"), "Moderation Class Id");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@DISPLAYNAME='DisplayName']"), "Displayname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EMAILNAME='EmailName']"), "Emailname");
            Assert.IsNotNull(modReasons.RootElement.SelectSingleNode(@"MOD-REASONS/MOD-REASON[@EDITORSONLY='0']"), "Editors Only");


            mocks.VerifyAllExpectationsHaveBeenMet();
        }
示例#2
0
        /// <summary>
        /// 
        /// </summary>
        public override void ProcessRequest()
        {

            bool alerts = InputContext.GetParamBoolOrFalse("alerts", "Moderation Alerts");
            bool referrals = InputContext.GetParamBoolOrFalse("referrals", "Refered Items");
            bool locked = InputContext.GetParamBoolOrFalse("locked", "Locked Items");
            bool fastMod = InputContext.GetParamBoolOrFalse("fastmod", "!Fast Moderation");
            int modClassId = InputContext.GetParamIntOrZero("modclassid", "Moderation Class Id");
            int postId = InputContext.GetParamIntOrZero("postfilterid", "PostId Filter");
            int show = InputContext.GetParamIntOrZero("show", "Number of Items");
            if (show == 0)
            {
                show = 10;
            }

            // Process Input
            ProcessSubmission();

            if (InputContext.DoesParamExist("done","Redirect"))
            {
                String redir = InputContext.GetParamStringOrEmpty("redirect", "Redirect");
                //AddDnaRedirect("moderate?newstyle=1");
                XmlNode redirect = AddElementTag(RootElement, "REDIRECT");
                AddAttribute(redirect, "URL", redir);
                return;
            }

            // Generate XML
            GenerateXml(alerts, referrals, locked, fastMod, InputContext.ViewingUser.UserID, modClassId, postId, show);
            
            // Get a list of all the sites.
            SiteXmlBuilder siteXml = new SiteXmlBuilder(InputContext);
            RootElement.AppendChild(ImportNode(siteXml.GenerateAllSitesXml(InputContext.TheSiteList).FirstChild));

            // Get a list of site options for all sites.
            RootElement.AppendChild(ImportNode(siteXml.GetSiteOptionListXml(InputContext.TheSiteList)));

            //Get Moderation Resons for current moderation class
            ModerationReasons modReasons = new ModerationReasons(InputContext);
            RootElement.AppendChild(ImportNode(modReasons.GenerateXml(modClassId)) );

            //Get Distress Messages for current Moderation Class
            ModerationDistressMessages mdm = new ModerationDistressMessages(InputContext);
            RootElement.AppendChild(ImportNode(mdm.GenerateXml(modClassId)));
            
        }
        public void VerifyXmlWithSchema()
        {
            Mockery mocks = new Mockery();
            IInputContext context = mocks.NewMock<IInputContext>();
            
            IDnaDataReader mockedReader = mocks.NewMock<IDnaDataReader>();
            Stub.On(context).Method("CreateDnaDataReader").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute");
            Stub.On(mockedReader).Method("Dispose");
            IAction mockReaderResults = new MockedReaderResults(new object[] { true, false });
            Stub.On(mockedReader).Method("Read").Will(mockReaderResults);

            Stub.On(mockedReader).Method("GetInt32NullAsZero").With("reasonid").Will(Return.Value(6));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("displayname").Will(Return.Value("DisplayName"));
            Stub.On(mockedReader).Method("GetStringNullAsEmpty").With("emailname").Will(Return.Value("EmailName"));
            Stub.On(mockedReader).Method("GetTinyIntAsInt").With("editorsonly").Will(Return.Value(0));

            ModerationReasons modReasons = new ModerationReasons(context);
            modReasons.ProcessRequest();

            DnaXmlValidator validator = new DnaXmlValidator(modReasons.RootElement.InnerXml, "Mod-Reasons.xsd");
            validator.Validate();
        }