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"); }
public void CreateFromDatabase_InvalidType_ThrowsException() { IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>(); diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Creating list from database")).Repeat.AtLeastOnce(); diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Created list from database")).Repeat.AtLeastOnce(); IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>(); reader.Stub(x => x.Read()).Return(true).Repeat.Once(); reader.Stub(x => x.GetInt32("Type")).Return(10); reader.Stub(x => x.GetString("Value")).Return("1"); reader.Stub(x => x.GetString("Section")).Return("test"); reader.Stub(x => x.GetString("Name")).Return("test"); reader.Stub(x => x.GetInt32("SiteID")).Return(1); reader.Stub(x => x.GetString("description")).Return("test"); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader); mocks.ReplayAll(); SiteOptionList target = new SiteOptionList(); try { target.CreateFromDatabase(creator, diag); throw new Exception("CreateFromDatabase should have thrown exception"); } catch (SiteOptionInvalidTypeException) { } }
public void Setup() { using (FullInputContext inputcontext = new FullInputContext("")) { _appContext = new AppContext(TestConfig.GetConfig().GetRipleyServerPath()); _siteOptionList = new SiteOptionList(); _siteOptionList.CreateFromDatabase(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics); } DnaTestURLRequest request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNormal(); IInputContext inputContext = DnaMockery.CreateDatabaseInputContext(); using (IDnaDataReader dataReader = inputContext.CreateDnaDataReader("")) { SetSiteID(dataReader, "h2g2"); _includeContentFromOtherSites = _siteOptionList.GetValueBool(_siteId, "PersonalSpace", "IncludeContentFromOtherSites"); //Create a post on h2g2 SetForumID(dataReader); request = new DnaTestURLRequest("h2g2"); request.SetCurrentUserNormal(); int id = request.CurrentUserID; request.RequestPage("AddThread?subject=test&body=blahblah&post=1&skin=purexml&forum=" + Convert.ToString(_forumId)); //Create a post on have your say. SetSiteID(dataReader, "haveyoursay"); SetForumID(dataReader); request = new DnaTestURLRequest("haveyoursay"); request.SetCurrentUserNormal(); request.RequestPage("AddThread?subject=test&body=blahblah&post=1&skin=purexml&forum=" + Convert.ToString(_forumId)); } }
public void CreateFromDatabase_ReadIsFalse_ReturnsEmptyObject() { 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(false); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader); mocks.ReplayAll(); SiteOptionList target = new SiteOptionList(); target.CreateFromDatabase(creator, diag); Assert.AreEqual(0, target.GetAllOptions().Count); Assert.AreEqual(0, target.GetAllOptionsDictionary().Count); }
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"); }
private void ReadSiteOptionListFromDatabase() { _testXSLTFilename = base.DnaConfig.CachePath + "DnaHtmlCacheTestFile.xsl"; _siteOptionList = new SiteOptionList(); _siteOptionList.CreateFromDatabase(ReaderCreator, base.dnaDiagnostics); }
public void CreateFromDatabase_AddsBoolOption_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 = GetBoolSiteOptionMockReader(); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader); mocks.ReplayAll(); SiteOptionList target = new SiteOptionList(); target.CreateFromDatabase(creator, diag); Assert.AreEqual(2, target.GetAllOptions().Count); Assert.AreEqual(2, target.GetAllOptionsDictionary().Count); Assert.AreEqual(SiteOption.SiteOptionType.Bool, target.GetAllOptions()[0].OptionType); Assert.IsTrue(target.GetAllOptions()[0].GetValueBool()); Assert.AreEqual(true, target.GetValueBool(1, "test", "test")); }
public void GetSiteOptionListForSite_DefaultOption_ReturnsCorrectList() { 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); List<SiteOption> actual = target.GetSiteOptionListForSite(1); Assert.AreEqual(1, actual.Count); Assert.AreEqual("test", actual[0].Name); Assert.IsTrue(actual[0].IsGlobal); }
public void SetValueBool_ChangesOption_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("1"); reader.Stub(x => x.GetString("Section")).Return("test"); reader.Stub(x => x.GetString("Name")).Return("test"); reader.Stub(x => x.GetInt32("SiteID")).Return(1); 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", false, creator, diag); Assert.AreEqual(false, target.GetValueBool(1, "test", "test")); }
public void TestSiteOptionListValues() { Console.WriteLine("TestSiteOptionListValues"); List<SiteOptionSpec> list = ReadSiteOptionsDirectly(); SiteOptionList soList = new SiteOptionList(); soList.CreateFromDatabase(ReaderCreator, base.dnaDiagnostics); foreach (SiteOptionSpec s in list) { switch (s.type) { case 0: int v = soList.GetValueInt(s.siteId, s.section, s.name); Assert.AreEqual(int.Parse(s.value), v); try { soList.GetValueBool(s.siteId, s.section, s.name); } catch (SiteOptionInvalidTypeException ex) { Assert.AreEqual("Value is not a bool", ex.Message); } break; case 1: bool sb = false; switch (s.value) { case "0": sb = false; break; case "1": sb = true; break; default: Assert.Fail("Invalid value for bool type", s.value); break; } bool b = soList.GetValueBool(s.siteId, s.section, s.name); Assert.AreEqual(sb, b); try { soList.GetValueInt(s.siteId, s.section, s.name); } catch (SiteOptionInvalidTypeException ex) { Assert.AreEqual("Value is not an int", ex.Message); } break; case 2: string value = soList.GetValueString(s.siteId, s.section, s.name); Assert.AreEqual(s.value, value); try { soList.GetValueString(s.siteId, s.section, s.name); } catch (SiteOptionInvalidTypeException ex) { Assert.AreEqual("Value is not a string", ex.Message); } break; default: Assert.Fail("Unknown site option type", s.type); break; } } foreach (SiteOptionSpec s in list) { SiteOption so = soList.CreateSiteOption(s.siteId, s.section, s.name); Assert.AreEqual(s.siteId, so.SiteId); Assert.AreEqual(s.section, so.Section); Assert.AreEqual(s.name, so.Name); Assert.AreEqual(s.description, so.Description); switch (s.type) { case 0: Assert.AreEqual(SiteOption.SiteOptionType.Int, so.OptionType); break; case 1: Assert.AreEqual(SiteOption.SiteOptionType.Bool, so.OptionType); break; case 2: Assert.AreEqual(SiteOption.SiteOptionType.String, so.OptionType); break; default: Assert.Fail("Unknown site option type", s.type); break; } } try { SiteOption so = soList.CreateSiteOption(999, "not", "there"); } catch (SiteOptionNotFoundException ex) { Assert.AreEqual(999, (int)ex.Data["SiteID"]); Assert.AreEqual("not", (string)ex.Data["Section"]); Assert.AreEqual("there", (string)ex.Data["Name"]); } }
public void TestSiteOptionListGetMethods() { Console.WriteLine("TestSiteOptionListGetMethods"); List<SiteOptionSpec> list = ReadSiteOptionsDirectly(); SiteOptionList soList = new SiteOptionList(); soList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), dnaDiagnostics); List<SiteOptionSpec> siteZero = new List<SiteOptionSpec>(); List<SiteOptionSpec> siteNoneZero = new List<SiteOptionSpec>(); List<SiteOptionSpec> valueDiffFromSiteZero = new List<SiteOptionSpec>(); foreach (SiteOptionSpec s in list) { switch (s.siteId) { case 0 : siteZero.Add(s); break; default: siteNoneZero.Add(s); break; } } bool foundDiffInt = false; bool foundDiffBool = false; bool foundDiffString = false; foreach (SiteOptionSpec snz in siteNoneZero) { foreach (SiteOptionSpec sz in siteZero) { if (snz.section == sz.section && snz.name == sz.name && snz.value != sz.value) { if (snz.type == 0 && !foundDiffInt) { valueDiffFromSiteZero.Add(snz); foundDiffInt = true; } if (snz.type == 1 && !foundDiffBool) { valueDiffFromSiteZero.Add(snz); foundDiffBool = true; } if (snz.type == 2 && !foundDiffString) { valueDiffFromSiteZero.Add(snz); foundDiffString = true; } } } } foreach (SiteOptionSpec s in valueDiffFromSiteZero) { if (s.type == 0) { int v0 = soList.GetValueInt(0, s.section, s.name); int vs = soList.GetValueInt(s.siteId, s.section, s.name); int v999 = soList.GetValueInt(999, s.section, s.name); Assert.AreNotEqual(v0, vs, "The value of this site option should be different to site zero"); Assert.AreEqual(v0, v999, "Non-existant site should have same value as site zero"); } if (s.type == 1) { bool v0 = soList.GetValueBool(0, s.section, s.name); bool vs = soList.GetValueBool(s.siteId, s.section, s.name); bool v999 = soList.GetValueBool(999, s.section, s.name); Assert.AreNotEqual(v0, vs, "The value of this site option should be different to site zero"); Assert.AreEqual(v0, v999, "Non-existant site should have same value as site zero"); } if (s.type == 2) { string v0 = soList.GetValueString(0, s.section, s.name); string vs = soList.GetValueString(s.siteId, s.section, s.name); string v999 = soList.GetValueString(999, s.section, s.name); Assert.AreNotEqual(v0, vs, "The value of this site option should be different to site zero"); Assert.AreEqual(v0, v999, "Non-existant site should have same value as site zero"); } } try { soList.GetValueInt(0, "NotThere", "gone"); } catch (SiteOptionNotFoundException ex) { Assert.AreEqual(0, (int)ex.Data["SiteID"]); Assert.AreEqual("NotThere", (string)ex.Data["Section"]); Assert.AreEqual("gone", (string)ex.Data["Name"]); } try { soList.GetValueBool(0, "NotThere", "gone"); } catch (SiteOptionNotFoundException ex) { Assert.AreEqual(0, (int)ex.Data["SiteID"]); Assert.AreEqual("NotThere", (string)ex.Data["Section"]); Assert.AreEqual("gone", (string)ex.Data["Name"]); } try { soList.GetValueString(0, "NotThere", "gone"); } catch (SiteOptionNotFoundException ex) { Assert.AreEqual(0, (int)ex.Data["SiteID"]); Assert.AreEqual("NotThere", (string)ex.Data["Section"]); Assert.AreEqual("gone", (string)ex.Data["Name"]); } List<int> siteIdList = new List<int>(); foreach (SiteOptionSpec s in valueDiffFromSiteZero) { int siteId = s.siteId; siteIdList.Add(siteId); List<SiteOption> siteOptionListForSite = soList.GetSiteOptionListForSite(siteId); Assert.AreEqual(siteZero.Count, siteOptionListForSite.Count); foreach (SiteOption so in siteOptionListForSite) { if (so.Section == s.section && so.Name == s.name && so.SiteId == siteId) { bool valuesDiffer = false; switch (so.OptionType) { case SiteOption.SiteOptionType.Int: int a = soList.GetValueInt(0, so.Section, so.Name); int b = soList.GetValueInt(so.SiteId, so.Section, so.Name); valuesDiffer = (a != b); break; case SiteOption.SiteOptionType.Bool: bool x = soList.GetValueBool(0, so.Section, so.Name); bool y = soList.GetValueBool(so.SiteId, so.Section, so.Name); valuesDiffer = (x != y); break; case SiteOption.SiteOptionType.String: string i = soList.GetValueString(0, so.Section, so.Name); string j = soList.GetValueString(so.SiteId, so.Section, so.Name); valuesDiffer = (i != j); break; default: Assert.Fail("Unknown site option type", so.OptionType); break; } Assert.IsTrue(valuesDiffer, "Values should be different"); } } } }