public void RatingCreateTwoThreads_Good() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a test generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testthreadedratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //1st normal users rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); ThreadInfo result = _ratings.RatingThreadCreate(ratingForum, rating); int threadID1 = result.id; Assert.IsTrue(result != null); Assert.IsTrue(result.rating.ID > 0); Assert.IsTrue(result.rating.text == rating.text); //create second editors rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetEditorUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetEditorUserAccount.Cookie, TestUserAccounts.GetEditorUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.text += "SecondOne"; result = _ratings.RatingThreadCreate(ratingForum, rating); int threadID2 = result.id; Assert.IsTrue(result != null); Assert.IsTrue(result.rating.ID > 0); Assert.IsTrue(result.rating.text == rating.text); Assert.IsTrue(threadID1 != threadID2, "Thread ids are the same, they need to be in different threads"); }
public Stream CreateRating(string RatingForumID, string siteName, RatingInfo rating) { RatingInfo ratingInfo = null; try { ISite site = GetSite(siteName); RatingForum RatingForumData = _ratingObj.RatingForumReadByUID(RatingForumID, site); if (RatingForumData == null) { throw ApiException.GetError(ErrorType.ForumUnknown); } _ratingObj.CallingUser = GetCallingUser(site); ratingInfo = _ratingObj.RatingCreate(RatingForumData, rating); } catch (ApiException ex) { throw new DnaWebProtocolException(ex); } return GetOutputStream(ratingInfo); }
public Stream CreateRatingThread(string RatingForumID, string siteName, RatingInfo rating) { ThreadInfo ratingThreadInfo = null; try { ISite site = GetSite(siteName); RatingForum ratingForumData = null; ratingForumData = _ratingObj.RatingForumReadByUID(RatingForumID, site); _ratingObj.CallingUser = GetCallingUser(site); ratingThreadInfo = _ratingObj.RatingThreadCreate(ratingForumData, rating); } catch (ApiException ex) { throw new DnaWebProtocolException(ex); } return GetOutputStream(ratingThreadInfo); }
public void RatingForum_ByUserList() { RatingForum ratingForum = new RatingForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum", SiteName = site.SiteName }; RatingForum result = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ParentUri == ratingForum.ParentUri); Assert.IsTrue(result.Title == ratingForum.Title); //create first rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); byte[] ratings = { 1, 2, 1 }; RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = ratings[0] }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post RatingInfo ratingReturned = _ratings.RatingCreate(ratingForum, rating); //create second rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNotableUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNotableUserAccount.Cookie, TestUserAccounts.GetNotableUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.rating = ratings[1]; ratingReturned = _ratings.RatingCreate(ratingForum, rating); //create third rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetSuperUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetSuperUserAccount.Cookie, TestUserAccounts.GetSuperUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.rating = ratings[2]; ratingReturned = _ratings.RatingCreate(ratingForum, rating); //get rating forum for user list who have create reviews int[] userList = new int[]{ TestUserAccounts.GetNormalUserAccount.UserID, TestUserAccounts.GetNotableUserAccount.UserID, TestUserAccounts.GetModeratorAccount.UserID }; RatingForum ratingForumReturned = _ratings.RatingForumReadByUIDAndUserList(ratingForum.Id, site, userList); Assert.IsTrue(ratingForumReturned != null); Assert.IsTrue(ratingForumReturned.ratingsSummary.Total == 2); Assert.IsTrue(ratingForumReturned.ratingsSummary.Average == (ratings[0] + ratings[1])/2); //get rating forum for list of users who haven't reviewed. userList = new int[] { TestUserAccounts.GetEditorUserAccount.UserID}; ratingForumReturned = _ratings.RatingForumReadByUIDAndUserList(ratingForum.Id, site, userList); Assert.IsTrue(ratingForumReturned != null); Assert.IsTrue(ratingForumReturned.ratingsSummary.Total == 0); }
public void RatingForumReadByUID() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_readUID", ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; //create the forum RatingForum result = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ParentUri == ratingForum.ParentUri); Assert.IsTrue(result.Title == ratingForum.Title); //create the comment //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString(), rating = 5 }; string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID); RatingInfo returnedRating = _ratings.RatingCreate(result, rating); Assert.IsTrue(returnedRating != null); Assert.IsTrue(returnedRating.ID > 0); Assert.IsTrue(returnedRating.text == rating.text); Assert.IsTrue(returnedRating.rating == rating.rating); //test good site result = _ratings.RatingForumReadByUID(ratingForum.Id, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ratingsList != null); Assert.IsTrue(result.ratingsList.TotalCount != 0); Assert.IsTrue(result.ratingsSummary.Average == 5); //test paging _ratings.ItemsPerPage = 50; _ratings.StartIndex = 0; result = _ratings.RatingForumReadByUID(ratingForum.Id, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ratingsList != null); Assert.IsTrue(result.ratingsList.TotalCount != 0); Assert.IsTrue(result.ratingsList.ItemsPerPage == _ratings.ItemsPerPage); Assert.IsTrue(result.ratingsList.StartIndex == _ratings.StartIndex); //test bad site name result = _ratings.RatingForumReadByUID("this doesn't exist", site); Assert.IsTrue(result == null); }
public void RatingCreate_WithProfanities() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit f**k generated rating." }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum_good" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.ProfanityFoundInText); } }
public void RatingForumCreate_WithAverage() { RatingForum ratingForum = new RatingForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum", SiteName = site.SiteName }; RatingForum result = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ParentUri == ratingForum.ParentUri); Assert.IsTrue(result.Title == ratingForum.Title); //create first rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); byte[] ratings = { 1, 2, 5 }; RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = ratings[0] }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post RatingInfo ratingReturned = _ratings.RatingCreate(ratingForum, rating); //create second rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetEditorUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetEditorUserAccount.Cookie, TestUserAccounts.GetEditorUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.rating = ratings[1]; ratingReturned = _ratings.RatingCreate(ratingForum, rating); //create third rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNotableUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNotableUserAccount.Cookie, TestUserAccounts.GetNotableUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.rating = ratings[2]; ratingReturned = _ratings.RatingCreate(ratingForum, rating); //get rating forum back and check post count and average result = _ratings.RatingForumReadByUID(ratingForum.Id, site); Assert.IsTrue(result.ratingsSummary.Total == 3); Assert.IsTrue(result.ratingsSummary.Average == (ratings[0] + ratings[1] + ratings[2]) / 3); }
public void RatingCreate_RepeatDifferentRatingText() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); RatingForum ratingForumData = _ratings.RatingForumReadByUID(ratingForumID, site); int total = ratingForumData.ratingsList.TotalCount; rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post //post new rating from same user try { result = _ratings.RatingCreate(ratingForumData, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.MultipleRatingByUser); } }
public void RatingCreate_BannedUser() { Reviews ratings = null; using (FullInputContext inputcontext = new FullInputContext("")) { ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetBannedUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetBannedUserAccount.Cookie, TestUserAccounts.GetBannedUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.UserIsBanned); } }
public void RatingCreate_RatingLargerThanSiteOption() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 6//site option = 5 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); //repeat post try { _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.RatingExceedsMaximumAllowed); } }
public void RatingCreate_RatingWithBiggerSiteOption() { try { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'CommentForum', 'MaxForumRatingScore','15',0,'test MaxForumRatingScore value')"); } _siteList.ReInitialise(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 14//standard site option = 5 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); //getr the forum and check value RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); Assert.IsTrue(result.rating == rating.rating); } finally { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxForumRatingScore'"); _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); } } } }
public void RatingCreate_WithoutRating() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating." }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); //repeat post RatingInfo returnRating = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(returnRating.rating == 0); }
private void AssertRatingCreate(RatingForum ratingForum, RatingInfo rating) { RatingInfo result= null; try { result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); } catch (ApiException ex) { if (ex.type != ErrorType.ProfanityFoundInText) { throw; } } }
public void RatingCreateTwoThreadsAndCommentsOnEach_Good() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a test generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testthreadedratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //1st normal users rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); ThreadInfo result = _ratings.RatingThreadCreate(ratingForum, rating); int threadID1 = result.id; Assert.IsTrue(result != null); Assert.IsTrue(result.rating.ID > 0); Assert.IsTrue(result.rating.text == rating.text); //create second editors rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetEditorUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetEditorUserAccount.Cookie, TestUserAccounts.GetEditorUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.text += "SecondOne"; result = _ratings.RatingThreadCreate(ratingForum, rating); int threadID2 = result.id; Assert.IsTrue(result != null); Assert.IsTrue(result.rating.ID > 0); Assert.IsTrue(result.rating.text == rating.text); Assert.IsTrue(threadID1 != threadID2); //1st normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); //Now the comments //set up test data string baseText = "This is a generated test comment on a rating." + Guid.NewGuid().ToString(); CommentInfo comment = new CommentInfo { text = baseText, }; comment.text += "FirstCommentOnFirstRating"; CommentInfo commentResult = _ratings.RatingCommentCreate(ratingForum, threadID1, comment); Assert.IsTrue(commentResult != null); Assert.IsTrue(commentResult.text == comment.text); comment.text = baseText + "FirstCommentOnSecondRating"; commentResult = _ratings.RatingCommentCreate(ratingForum, threadID2, comment); Assert.IsTrue(commentResult != null); Assert.IsTrue(commentResult.text == comment.text); //1st comment by the editor account _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetEditorUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetEditorUserAccount.Cookie, TestUserAccounts.GetEditorUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); comment.text = baseText + "SecondCommentOnFirstRating"; commentResult = _ratings.RatingCommentCreate(ratingForum, threadID1, comment); Assert.IsTrue(commentResult != null); Assert.IsTrue(commentResult.text == comment.text); }
public void RatingCreate_ReactiveModForum() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID, ModerationStatus.ForumStatus.PostMod); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); }
public void RatingCreate_RatingOnEmergencyClosedSite() { //create ratings objects _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); var callingUser = _ratings.CallingUser; //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); try {//turn the site into emergency closed mode _siteList.GetSite(site.ShortName).IsEmergencyClosed = true; using (FullInputContext inputcontext = new FullInputContext("")) { _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList); _ratings.CallingUser = callingUser; } RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.AreEqual(ErrorType.SiteIsClosed, ex.type); } finally {//reset the site into emergency closed mode _siteList.GetSite(site.ShortName).IsEmergencyClosed = false; } }
public void RatingCreate_PostPastClosingDate() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum_good" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //change the closing date for this forum using (FullInputContext _context = new FullInputContext("")) { using (IDnaDataReader dataReader = _context.CreateDnaDataReader("updatecommentforumstatus")) { dataReader.AddParameter("uid", ratingForumID); dataReader.AddParameter("forumclosedate", DateTime.Today.AddDays(-20)); dataReader.Execute(); } } ratingForum = _ratings.RatingForumReadByUID(ratingForumID, site); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.ForumClosed); } }
public void RatingCreate_WithIllegalTags() { //set up test data string illegalTags = "<script/><object/><embed/>"; RatingInfo rating = new RatingInfo { text = String.Format("this is a nunit {0}generated rating.", illegalTags) }; string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text.IndexOf(illegalTags) < 0);//illegal char stripped }
private void BadMaxPostCheck(int maxCharLength) { string ratingForumID = "good" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); //string too large with html ratingForum = RatingForumCreate(Guid.NewGuid().ToString()); //set up test data RatingInfo rating = new RatingInfo { text = String.Format("<div><b><i><u>{0}</u></i></b></div>", "a".PadRight(maxCharLength + 1)) }; RatingInfo result; bool exceptionFlagged = false; try { result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit); exceptionFlagged = true; } //check an exception was raised Assert.IsTrue(exceptionFlagged); //reset flag to say it has raised an exception exceptionFlagged = false; //string too large without html ratingForum = RatingForumCreate(Guid.NewGuid().ToString()); rating.text = String.Format("{0}", "a".PadRight(maxCharLength + 1)); try { result = _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit); exceptionFlagged = true; } }
public void RatingCreate_TestRatingWithALinkWithCRLFInIt() { //set up test data string input = @"blahblahblah<a href=""http:" + "\r\n" + @""">Test Link</a>"; string expectedOutput = @"blahblahblah<a href=""http: "">Test Link</a>"; RatingInfo rating = new RatingInfo { text = input }; string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.AreEqual(expectedOutput, result.text);//illegal char stripped }
public void RatingForumCreate_UserRating() { RatingForum ratingForum = new RatingForum { Id = Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum", SiteName = site.SiteName }; RatingForum result = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ParentUri == ratingForum.ParentUri); Assert.IsTrue(result.Title == ratingForum.Title); //create first rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); byte[] ratings = { 1, 2, 1 }; RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = ratings[0] }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post //create third rating _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNotableUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNotableUserAccount.Cookie, TestUserAccounts.GetNotableUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); rating.rating = ratings[2]; RatingInfo ratingReturned = _ratings.RatingCreate(ratingForum, rating); //get rating for a specific user ratingReturned = _ratings.RatingsReadByDNAUserID(ratingForum.Id, site, TestUserAccounts.GetNotableUserAccount.UserID); Assert.IsTrue(ratingReturned != null); Assert.IsTrue(ratingReturned.User != null); Assert.IsTrue(ratingReturned.User.UserId == TestUserAccounts.GetNotableUserAccount.UserID); //get rating for a specific user who hasn't rated = should be null ratingReturned = _ratings.RatingsReadByDNAUserID(ratingForum.Id, site, TestUserAccounts.GetSuperUserAccount.UserID); Assert.IsTrue(ratingReturned == null); }
public void RatingCreate_TestRichTextPostWithDodgyTagsReportsCorrectErrors() { // DO NOT REFORMAT THE FOLLOWING TEST AS IT CONTAINS /r/n AS INTENDED!!! string input = @"blahblahblah2<b>NormalUser</b><a href="" www.bbc.co.uk/dna/h2g2"">>fail you <bugger</a>with a carrage return."; RatingInfo rating = new RatingInfo { text = input }; string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); bool exceptionThrown = false; try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); rating.text = @"blahblahblah2<b>NormalUser</b><a href=""www.bbc.co.uk/dna/h2g2"" test='blah''>>fail you bugger</a>with an error message!!!."; exceptionThrown = false; try { RatingInfo result = _ratings.RatingCreate(ratingForum, rating); } catch { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); }
public void RatingReadByPostID() { RatingForum ratingForum = new RatingForum { Id = "testRatingForum_RatingReadByPostID", ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testRatingForum" }; //create the forum RatingForum result = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(result != null); Assert.IsTrue(result.Id == ratingForum.Id); Assert.IsTrue(result.ParentUri == ratingForum.ParentUri); Assert.IsTrue(result.Title == ratingForum.Title); //create the rating RatingInfo rating = new RatingInfo { text = "this is a nunit generated review.", rating = 4 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.CreateUserFromDnaUserID(TestUtils.TestUserAccounts.GetNormalUserAccount.UserID, site.SiteID); RatingInfo ratingInfo = _ratings.RatingCreate(result, rating); Assert.IsTrue(ratingInfo != null); Assert.IsTrue(ratingInfo.ID > 0); Assert.IsTrue(ratingInfo.text == rating.text); Assert.IsTrue(ratingInfo.rating == rating.rating); RatingInfo returnedRatingInfo = _ratings.RatingReadByPostID(ratingInfo.ID.ToString(), site); Assert.IsTrue(ratingInfo.text == returnedRatingInfo.text); Assert.IsTrue(ratingInfo.rating == returnedRatingInfo.rating); }
public void RatingCreate_TestRichTextPostsCRLFInLink() { // DO NOT REFORMAT THE FOLLOWING TEST AS IT CONTAINS /r/n AS INTENDED!!! string input = @"blahblahblah2<b>NormalUser</b><a href="" www.bbc.co.uk/dna/h2g2"">fail you bugger</a>with a carrage return."; string expectedOutput = @"blahblahblah2<b>NormalUser</b><a href=""#"">fail you bugger</a>with a carrage<BR />return."; RatingInfo rating = new RatingInfo { text = input }; string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.AreEqual(expectedOutput, result.text);//illegal char stripped }
/// <summary> /// Make the POST data as JSON /// </summary> public static String makeEntryPostJSON_minimal(ref string inputText, ref string inputRating) { System.Random RandNum = new System.Random(); if (inputRating == "") inputRating = RandNum.Next(1, 5).ToString(); if (inputText == "") inputText = "Functional test for Review API " + Guid.NewGuid().ToString(); var rating = new RatingInfo() { text = inputText, rating = byte.Parse(inputRating) }; return StringUtils.SerializeToJsonReturnAsString(rating); }
public void RatingCreate_PreModSiteWithProcessPreMod() { using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=1 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("insert into siteoptions (SiteID,Section,Name,Value,Type, Description) values(" + site.SiteID.ToString() + ",'Moderation', 'ProcessPreMod','1',1,'test premod value')"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList); } try { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID, ModerationStatus.ForumStatus.Unknown);//should override this with the site value //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); try { _ratings.RatingCreate(ratingForum, rating); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidProcessPreModState); } } finally { //reset h2g2 site using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("update sites set premoderation=0 where siteid=" + site.SiteID.ToString());//set premod reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='ProcessPreMod'"); } _siteList = SiteList.GetSiteList(); site = _siteList.GetSite("h2g2"); _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList); } } }
public void CreateRatingHtml(string RatingForumID, string siteName, NameValueCollection formsData) { ErrorType error = ErrorType.Unknown; DnaWebProtocolException _ex = null; RatingInfo ratingInfo = null; try { ratingInfo = new RatingInfo { text = formsData["text"] }; if (!String.IsNullOrEmpty(formsData["PostStyle"])) { try { ratingInfo.PostStyle = (PostStyle.Style)Enum.Parse(typeof(PostStyle.Style), formsData["PostStyle"]); } catch { throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidPostStyle)); } } byte rating = 0; if (!byte.TryParse(formsData["rating"], out rating)) { throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidRatingValue)); } ratingInfo.rating = rating; CreateRating(RatingForumID, siteName, ratingInfo); error = ErrorType.Ok; } catch (DnaWebProtocolException ex) { error = ex.ErrorType; _ex = ex; } string ptrt = WebFormat.GetPtrtWithResponse(error.ToString()); if (String.IsNullOrEmpty(ptrt)) {//none returned... if (error == ErrorType.Ok) { WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Created; return; } else { throw _ex; } } //do response redirect... WebOperationContext.Current.OutgoingResponse.Location = ptrt; WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.MovedPermanently; }
public void RatingCreate_PostModForum() { //set up test data RatingInfo rating = new RatingInfo { text = "this is a nunit generated rating.", rating = 3 }; rating.text += Guid.NewGuid().ToString();//have to randomize the string to post string IPAddress = String.Empty; Guid BBCUid = Guid.NewGuid(); string ratingForumID = "testratingForum" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID, ModerationStatus.ForumStatus.PostMod); //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); RatingInfo result = _ratings.RatingCreate(ratingForum, rating); Assert.IsTrue(result != null); Assert.IsTrue(result.ID > 0); Assert.IsTrue(result.text == rating.text); //check if post in mod queue table using (FullInputContext inputcontext = new FullInputContext("")) { using (IDnaDataReader reader = inputcontext.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from ThreadMod where postid=" + result.ID.ToString()); if (!reader.Read() || !reader.HasRows) { Assert.Fail("Post not in ThreadMod table and moderation queue"); } } } }
public Stream CreateRatingThreadHtml(string RatingForumID, string siteName, NameValueCollection formsData) { RatingInfo ratingInfo = null; try { ratingInfo = new RatingInfo { text = formsData["text"] }; if (!String.IsNullOrEmpty(formsData["PostStyle"])) { try { ratingInfo.PostStyle = (PostStyle.Style)Enum.Parse(typeof(PostStyle.Style), formsData["PostStyle"], true); } catch { throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidPostStyle)); } } byte rating = 0; if (!byte.TryParse(formsData["rating"], out rating)) { throw new DnaWebProtocolException(System.Net.HttpStatusCode.BadRequest, "Rating value must be between 0 and 255", null); } ratingInfo.rating = rating; } catch (DnaException ex) { throw new DnaWebProtocolException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex); } return CreateRatingThread(RatingForumID, siteName, ratingInfo); }
private void GoodMinMaxPostCheck(int minCharLength, int maxCharLength) { string ratingForumID = "good" + Guid.NewGuid().ToString(); RatingForum ratingForum = RatingForumCreate(ratingForumID); string randomString = EncodedRandomString(); string goodText = randomString.Substring(0, maxCharLength); //Test max boundary RatingInfo rating = new RatingInfo(); rating.text = goodText; //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); AssertRatingCreate(ratingForum, rating); //with some markup ratingForum = RatingForumCreate(Guid.NewGuid().ToString()); rating.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", goodText); AssertRatingCreate(ratingForum, rating); ratingForumID = "good" + Guid.NewGuid().ToString(); ratingForum = RatingForumCreate(ratingForumID); goodText = randomString.Substring(0, minCharLength); //Test max boundary rating = new RatingInfo(); rating.text = goodText; //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); AssertRatingCreate(ratingForum, rating); //with some markup ratingForum = RatingForumCreate(Guid.NewGuid().ToString()); rating.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", goodText); AssertRatingCreate(ratingForum, rating); ratingForumID = "good" + Guid.NewGuid().ToString(); ratingForum = RatingForumCreate(ratingForumID); goodText = randomString.Substring(0, (minCharLength + ((maxCharLength - minCharLength) / 2))); //Test max boundary rating = new RatingInfo(); rating.text = goodText; //normal user _ratings.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList); _ratings.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty); AssertRatingCreate(ratingForum, rating); //with some markup ratingForum = RatingForumCreate(Guid.NewGuid().ToString()); rating.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", goodText); AssertRatingCreate(ratingForum, rating); }