/// <summary> /// Constructor for the User Tests to set up the context for the tests /// </summary> public UserListTests() { string rootPath = TestConfig.GetConfig().GetRipleyServerPath(); BBC.Dna.AppContext.OnDnaStartup(rootPath); Console.WriteLine("Before RecentSearch - AddRecentSearchTests"); //Create the mocked _InputContext Mockery mock = new Mockery(); _InputContext = DnaMockery.CreateDatabaseInputContext(); // Create a mocked site for the context ISite mockedSite = DnaMockery.CreateMockedSite(_InputContext, 1, "h2g2", "h2g2", true, "comment"); Stub.On(_InputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite)); Stub.On(mockedSite).GetProperty("ModClassID").Will(Return.Value(1)); BBC.Dna.User user = new BBC.Dna.User(_InputContext); Stub.On(_InputContext).GetProperty("ViewingUser").Will(Return.Value(user)); Stub.On(_InputContext).GetProperty("CurrentSite").Will(Return.Value(mockedSite)); //Create sub editor group and users //create test sub editors DnaTestURLRequest dnaRequest = new DnaTestURLRequest("h2g2"); dnaRequest.SetCurrentUserEditor(); TestDataCreator testData = new TestDataCreator(_InputContext); int[] userIDs = new int[10]; Assert.IsTrue(testData.CreateNewUsers(mockedSite.SiteID, ref userIDs), "Test users not created"); Assert.IsTrue(testData.CreateNewUserGroup(dnaRequest.CurrentUserID, "subs"), "CreateNewUserGroup not created"); Assert.IsTrue(testData.AddUsersToGroup(userIDs, mockedSite.SiteID, "subs"), "Unable to add users to group not created"); }
public void StartUp() { Console.WriteLine("StartUp()"); IInputContext context = DnaMockery.CreateDatabaseInputContext(); ISite siteContext = DnaMockery.CreateMockedSite(context, 1, "", "h2g2", true, "comment"); TestDataCreator testData = new TestDataCreator(context); int[] userIDs = new int[10]; Assert.IsTrue(testData.CreateNewUsers(siteContext.SiteID, ref userIDs), "Test users not created"); Console.WriteLine("Finished StartUp()"); }
public void Test03_CorrectAllocationTests() { DnaTestURLRequest dnaRequest = new DnaTestURLRequest("h2g2"); dnaRequest.SetCurrentUserEditor(); //create a dummy articles IInputContext context = DnaMockery.CreateDatabaseInputContext(); ISite siteContext = DnaMockery.CreateMockedSite(context, 1, "", "h2g2", true, "comment"); TestDataCreator testData = new TestDataCreator(context); entryIDs = new int[10]; h2g2IDs = new int[10]; Assert.IsTrue(testData.CreateEntries(siteContext.SiteID, dnaRequest.CurrentUserID, 3001, 3, ref entryIDs, ref h2g2IDs), "Articles not created"); recommendationIds = new int[10]; Assert.IsTrue(testData.CreateRecommendations(dnaRequest.CurrentUserID, entryIDs, ref recommendationIds), "Recommendation not created"); Assert.IsTrue(testData.AcceptRecommendations(dnaRequest.CurrentUserID, recommendationIds), "Recommendation accepted"); //create test sub editors userIDs = new int[10]; Assert.IsTrue(testData.CreateNewUsers(siteContext.SiteID, ref userIDs), "Test users not created"); Assert.IsTrue(testData.CreateNewUserGroup(dnaRequest.CurrentUserID, "subs"), "CreateNewUserGroup not created"); Assert.IsTrue(testData.AddUsersToGroup(userIDs, siteContext.SiteID, "subs"), "Unable to add users to group not created"); //get unallocated values from list dnaRequest = new DnaTestURLRequest("h2g2"); dnaRequest.SetCurrentUserEditor(); dnaRequest.UseEditorAuthentication = true; string relativePath = "allocatesubs?skin=purexml"; dnaRequest.RequestPage(relativePath); XmlDocument xmlResponse = dnaRequest.GetLastResponseAsXML(); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/UNALLOCATED-RECOMMENDATIONS") != null, "Incorrect data returned"); //update entryids with unallocated values XmlNode unallocRecommendations = xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/UNALLOCATED-RECOMMENDATIONS/ARTICLE-LIST"); for (int i = 0; i < entryIDs.Length && i < unallocRecommendations.ChildNodes.Count; i++) { entryIDs[i] = Int32.Parse(unallocRecommendations.ChildNodes[i].SelectSingleNode("ENTRY-ID").InnerText); } //allocate 2 articles to sub editor dnaRequest = new DnaTestURLRequest("h2g2"); dnaRequest.SetCurrentUserEditor(); dnaRequest.UseEditorAuthentication = true; relativePath = "allocatesubs?&Command=ALLOCATE&EntryID=" + entryIDs[0] + "&EntryID=" + entryIDs[1] + "&SubID=" + userIDs[0] + "&skin=purexml"; dnaRequest.RequestPage(relativePath); xmlResponse = dnaRequest.GetLastResponseAsXML(); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/SUCCESSFUL-ALLOCATIONS") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/FAILED-ALLOCATIONS") != null, "Incorrect data returned"); //deallocate those two relativePath = @"AllocateSubs?command=DEALLOCATE&DeallocateID=" + entryIDs[0] + "&DeallocateID=" + entryIDs[1] + "&SubID=" + userIDs[0] + "&skin=purexml"; dnaRequest.RequestPage(relativePath); xmlResponse = dnaRequest.GetLastResponseAsXML(); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/SUCCESSFUL-DEALLOCATIONS") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/FAILED-DEALLOCATIONS") != null, "Incorrect data returned"); //auto allocate some relativePath = @"AllocateSubs?command=AUTOALLOCATE&Amount=2&SubID=" + userIDs[0] + "&skin=purexml"; dnaRequest.RequestPage(relativePath); xmlResponse = dnaRequest.GetLastResponseAsXML(); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/SUCCESSFUL-ALLOCATIONS") != null, "Incorrect data returned"); Assert.IsTrue(xmlResponse.SelectSingleNode("/H2G2/SUB-ALLOCATION-FORM/FAILED-ALLOCATIONS") != null, "Incorrect data returned"); }