public void Test1_CheckPromptSetUserNameNotVisibleOnSiteWithSiteOptionNotSet()
        {
            // Create a mocked input context for the test
            IInputContext context = DnaMockery.CreateDatabaseInputContext();

            // Create a profileAPI for the test
            int userID = GetNextUserID;
            IDnaIdentityWebServiceProxy mockedProfileAPI = DnaMockery.CreateMockedProfileConnection(context, userID, "testUser", "BBCUID-Testing", "[email protected]", userID.ToString() + "123456789012345678901234567890abcdefghijklmnopqrstuvwxyz", true);

            // Create a mocked site
            ISite mockedSite = DnaMockery.CreateMockedSite(context, 1, "h2g2", "h2g2", true, "comment");

            // Create the site options for the new mocked site
            SiteOptionList siteOptionList = new SiteOptionList();
            siteOptionList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default);
            siteOptionList.SetValueBool(1, "Moderation", "SetNewUsersNickNames", false, DnaMockery.CreateDatabaseReaderCreator(),null);
            siteOptionList.SetValueBool(1, "General", "CheckUserNameSet", false, DnaMockery.CreateDatabaseReaderCreator(), null);

            // Stub the call to the siteoption
            Stub.On(context).Method("GetSiteOptionValueBool").With("General", "CheckUserNameSet").Will(Return.Value(false));

            // Create the user
            User testUser = new User(context);
            testUser.CreateUser();

            // Check the XML
            XmlNode userXml = testUser.RootElement.SelectSingleNode("//USER");
            Assert.AreEqual(null, userXml.SelectSingleNode("PROMPTSETUSERNAME"), "The prompt set username should not be pressent in the user xml");
            Assert.AreEqual("U" + testUser.UserID.ToString(), userXml.SelectSingleNode("USERNAME").InnerText, "The username should be set to U" + userID.ToString() + " in the user xml");
        }
Example #2
0
        public void Test08GetUITemplateForValidationParamsWithProfanity()
        {
            Console.WriteLine("Before Test08GetUITemplateForValidationParamsWithProfanity");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = DnaMockery.CreateDatabaseInputContext();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            Stub.On(site).GetProperty("ModClassID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the site options for the new mocked site
            SiteOptionList siteOptionList = new SiteOptionList();
            siteOptionList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default);
            siteOptionList.SetValueBool(1, "Forum", "EmailAddressFilter", true, DnaMockery.CreateDatabaseReaderCreator(), null);
            siteOptionList.SetValueBool(1, "General", "IsURLFiltered", true, DnaMockery.CreateDatabaseReaderCreator(), null);

            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("Forum", "EmailAddressFilter").Will(Return.Value(true));
            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("General", "IsURLFiltered").Will(Return.Value(true));

            // Initialise the profanities object
            var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);

            using (IDnaDataReader reader = mockedInputContext.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = _createdUITemplateID;
                testUITemplate.LoadTemplate();
                List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();

                KeyValuePair<string, string> subject = new KeyValuePair<string, string>("SUBJECT", "TestSubject");
                parameters.Add(subject);
                KeyValuePair<string, string> description = new KeyValuePair<string, string>("Description", "TestDescription with f**k");
                parameters.Add(description);

                testUITemplate.ProcessParameters(parameters);

                testUITemplate.Validate();

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test08GetUITemplateForValidationParamsWithProfanity");
        }
Example #3
0
        public void SetValueBool_NoOption_ThrowsException()
        {
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Creating list from database")).Repeat.Once();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Created list from database")).Repeat.Once();


            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("setsiteoption")).Return(reader);

            

            mocks.ReplayAll();

            SiteOptionList target = new SiteOptionList();
            try
            {
                target.SetValueBool(1, "test", "test", false, creator, diag);
            }
            catch (SiteOptionNotFoundException)
            {
            }
        }
Example #4
0
        public void SetValueBool_ChangesDefaultOption_ReturnsValidObject()
        {
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Creating list from database")).Repeat.Once();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Created list from database")).Repeat.Once();


            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetInt32("Type")).Return((int)SiteOption.SiteOptionType.Bool);
            reader.Stub(x => x.GetString("Value")).Return("0");
            reader.Stub(x => x.GetString("Section")).Return("test");
            reader.Stub(x => x.GetString("Name")).Return("test");
            reader.Stub(x => x.GetInt32("SiteID")).Return(0);
            reader.Stub(x => x.GetString("description")).Return("test");


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("setsiteoption")).Return(reader);

            

            mocks.ReplayAll();

            SiteOptionList target = new SiteOptionList();
            target.CreateFromDatabase(creator, diag);
            Assert.AreEqual(1, target.GetAllOptions().Count);
            Assert.AreEqual(1, target.GetAllOptionsDictionary().Count);
            Assert.AreEqual(SiteOption.SiteOptionType.Bool, target.GetAllOptions()[0].OptionType);

            target.SetValueBool(1, "test", "test", true, creator, diag);
            Assert.AreEqual(true, target.GetValueBool(1, "test", "test"));
        }