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); }
/// <summary> /// Creates a new comment forum for a specificed site. Note if the RatingForum id already exists, then nothing will be created /// </summary> /// <param name="RatingForum">The comment forum object</param> /// <param name="siteName">The site shortname</param> /// <returns>The comment forum (either new or existing) which matches to the </returns> public RatingForum RatingForumCreate(RatingForum RatingForum, ISite site) { //create the forum... CreateForum((Forum)RatingForum, site); return RatingForumReadByUID(RatingForum.Id, site); }
private ThreadInfo CreateRatingThreadAndComments(DnaTestURLRequest request, RatingForum ratingForum) { string text = "FunctionTest Title" + Guid.NewGuid().ToString(); string ratingForumXml = String.Format("<rating xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text><rating>{1}</rating>" + "</rating>", text, 5); // Setup the request url string url = String.Format("https://" + _secureserver + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/thread", _sitename, ratingForum.Id); // now get the response request.RequestPageWithFullURL(url, ratingForumXml, "text/xml"); ThreadInfo returnedThread = (ThreadInfo)StringUtils.DeserializeObject(request.GetLastResponseAsString(), typeof(ThreadInfo)); string comment = "Here is my comment on this rating." + Guid.NewGuid().ToString(); string commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text>" + "</comment>", comment); // Setup the comment url string commenturl = String.Format("https://" + _secureserver + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/thread/{2}", _sitename, ratingForum.Id, returnedThread.id); // now get the response request.RequestPageWithFullURL(commenturl, commentForumXml, "text/xml"); comment = "Here is a second comment on this rating." + Guid.NewGuid().ToString(); commentForumXml = String.Format("<comment xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text>" + "</comment>", comment); // Setup the 2nd comment url commenturl = String.Format("https://" + _secureserver + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/thread/{2}", _sitename, ratingForum.Id, returnedThread.id); // now get the response request.RequestPageWithFullURL(commenturl, commentForumXml, "text/xml"); return returnedThread; }
public Stream CreateRatingForum(string sitename, RatingForum RatingForum) { RatingForum RatingForumData = null; try { ISite site = GetSite(sitename); _ratingObj.CallingUser = GetCallingUser(site); if (_ratingObj.CallingUser.IsUserA(UserTypes.Editor)) { RatingForumData = _ratingObj.RatingForumCreate(RatingForum, site); } else { throw new DnaWebProtocolException(ApiException.GetError(ErrorType.MissingEditorCredentials)); } } catch (ApiException ex) { throw new DnaWebProtocolException(ex); } return GetOutputStream(RatingForumData); }
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 RatingForumCreate_InReactive() { RatingForum ratingForum = new RatingForum { Id = "CommentForumCreate_InReactive", ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum", ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive }; 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); Assert.IsTrue(result.ModerationServiceGroup == ModerationStatus.ForumStatus.Reactive); }
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); }
/// <summary> /// Returns the comment forum uid from cache /// </summary> /// <param name="uid">The uid of the forum</param> /// <param name="site">the site of the forum</param> /// <param name="forum">The return forum</param> /// <returns>true if found in cache otherwise false</returns> private bool RatingForumReadByUIDFromCache(string uid, ISite site, ref RatingForum forum) { string cacheKey = RatingForumCacheKey(uid, site.SiteID); object tempLastUpdated = CacheManager.GetData(cacheKey + CacheLastupdated); if (tempLastUpdated == null) {//not found forum = null; Statistics.AddCacheMiss(); return false; } DateTime lastUpdated = (DateTime)tempLastUpdated; //check if cache is up to date if (DateTime.Compare(lastUpdated, RatingForumGetLastUpdate(new object[2]{uid, site.SiteID})) != 0 ) {//cache out of date so delete DeleteRatingForumFromCache(uid, site); forum = null; Statistics.AddCacheMiss(); return false; } //get actual cached object forum = (RatingForum)CacheManager.GetData(cacheKey); if (forum == null) {//cache out of date so delete DeleteRatingForumFromCache(uid, site); forum = null; Statistics.AddCacheMiss(); return false; } //apply site variables forum = ApplySiteVariables(forum, site); Statistics.AddCacheHit(); //readd to cache to add sliding window affect RatingForumAddToCache(forum, site); return true; }
/// <summary> /// Returns the comment forum uid from cache /// </summary> /// <param name="uid">The uid of the forum</param> /// <param name="site">the site of the forum</param> /// <param name="forum">The return forum</param> /// <returns>true if found in cache otherwise false</returns> private void RatingForumAddToCache(RatingForum forum, ISite site) { string cacheKey = RatingForumCacheKey(forum.Id, site.SiteID); //ICacheItemExpiration expiry = SlidingTime. CacheManager.Add(cacheKey + CacheLastupdated, forum.LastUpdate, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes))); CacheManager.Add(cacheKey, forum, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes))); }
/// <summary> /// Creates a comment on a rating for a particular rating forum /// </summary> /// <param name="RatingForum">The forum to post to</param> /// <param name="int">The thread to add the comment to</param> /// <param name="comment">The comment to add</param> /// <returns>The created comment object</returns> public CommentInfo RatingCommentCreate(RatingForum ratingForum, int threadID, CommentInfo comment) { ISite site = SiteList.GetSite(ratingForum.SiteName); Comments commentsObj = new Comments(DnaDiagnostics, DnaDataReaderCreator, CacheManager, SiteList); commentsObj.CallingUser = CallingUser; commentsObj.BbcUid = BbcUid; commentsObj.IpAddress = IpAddress; CommentInfo createdRatingComment = commentsObj.CommentReplyCreate((Forum)ratingForum, threadID, comment); return createdRatingComment; }
/// <summary> /// Creates the RatingForumdata from a given reader /// </summary> /// <param name="reader">The database reaser</param> /// <returns>A Filled comment forum object</returns> private RatingForum RatingForumCreateFromReader(IDnaDataReader reader) { DateTime closingDate = reader.GetDateTime("forumclosedate"); //if (closingDate == null) //{ // closingDate = DateTime.MaxValue; //} ISite site = SiteList.GetSite(reader.GetStringNullAsEmpty("sitename")); RatingForum RatingForum = new RatingForum(); RatingForum.Title = reader.GetStringNullAsEmpty("Title"); RatingForum.Id = reader.GetStringNullAsEmpty("UID"); RatingForum.CanRead = reader.GetByteNullAsZero("canRead")==1; RatingForum.CanWrite = reader.GetByteNullAsZero("canWrite") == 1; RatingForum.ParentUri = reader.GetStringNullAsEmpty("Url"); RatingForum.SiteName = reader.GetStringNullAsEmpty("sitename"); RatingForum.CloseDate = closingDate; RatingForum.LastUpdate = (DateTime)reader.GetDateTime("LastUpdated"); if ((DateTime)reader.GetDateTime("lastposted") > RatingForum.LastUpdate) {//use last posted as it is newer RatingForum.LastUpdate = (DateTime)reader.GetDateTime("lastposted"); } RatingForum.Updated = new DateTimeHelper(RatingForum.LastUpdate); RatingForum.Created = new DateTimeHelper((DateTime)reader.GetDateTime("DateCreated")); RatingForum.ratingsSummary = new RatingsSummary { Total = reader.GetInt32NullAsZero("ForumPostCount"), Average = reader.GetInt32NullAsZero("average"), EditorPicksTotal = reader.GetInt32NullAsZero("editorpickcount") }; RatingForum.ForumID = reader.GetInt32NullAsZero("forumid"); RatingForum.isClosed = !RatingForum.CanWrite || site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now) || (closingDate != null && DateTime.Now > closingDate); //MaxCharacterCount = siteList.GetSiteOptionValueInt(site.SiteID, "RatingForum", "'MaxCommentCharacterLength") Dictionary<string, string> replacements = new Dictionary<string, string>(); replacements.Add("uid", reader.GetStringNullAsEmpty("uid")); replacements.Add("sitename", site.SiteName); RatingForum.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.RatingForumById, replacements); RatingForum.ratingsSummary.Uri = UriDiscoverability.GetUriWithReplacments(BasePath, UriDiscoverability.UriType.RatingsByRatingForumId, replacements); //get moderation status RatingForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Unknown; if (!reader.IsDBNull("moderationstatus")) {//if it is set for the specific forum RatingForum.ModerationServiceGroup = (ModerationStatus.ForumStatus)(reader.GetTinyIntAsInt("moderationstatus")); } if(RatingForum.ModerationServiceGroup == ModerationStatus.ForumStatus.Unknown) {//else fall back to site moderation status switch(site.ModerationStatus) { case ModerationStatus.SiteStatus.UnMod: RatingForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive; break; case ModerationStatus.SiteStatus.PreMod: RatingForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod; break; case ModerationStatus.SiteStatus.PostMod: RatingForum.ModerationServiceGroup = ModerationStatus.ForumStatus.PostMod; break; default: RatingForum.ModerationServiceGroup = ModerationStatus.ForumStatus.Reactive; break; } } RatingForum.NotSignedInUserId = reader.GetInt32NullAsZero("NotSignedInUserId"); RatingForum.allowNotSignedInCommenting = RatingForum.NotSignedInUserId != 0; return RatingForum; }
/// <summary> /// Creates a threaded rating for the given rating forum /// </summary> /// <param name="RatingForum">The forum to post to</param> /// <param name="rating">The rating to add</param> /// <returns>The created rating object</returns> public ThreadInfo RatingThreadCreate(RatingForum ratingForum, RatingInfo rating) { ISite site = SiteList.GetSite(ratingForum.SiteName); //check for repeat posting ValidateRating(ratingForum, rating, site); Threads threadsObj = new Threads(DnaDiagnostics, DnaDataReaderCreator, CacheManager, SiteList); threadsObj.CallingUser = CallingUser; threadsObj.BbcUid = BbcUid; threadsObj.IpAddress = IpAddress; //create the thread entry ThreadInfo createdThread = threadsObj.ThreadCreate((Forum)ratingForum, (RatingInfo)rating); using (var reader = CreateReader("ratingscreate")) { reader.AddParameter("entryid", createdThread.rating.ID); reader.AddParameter("uid", ratingForum.Id); reader.AddParameter("rating", rating.rating); reader.AddParameter("userid", CallingUser.UserID); reader.AddParameter("siteid", site.SiteID); reader.Execute(); } createdThread.rating.rating = rating.rating; return createdThread; }
private void ValidateRating(RatingForum RatingForum, RatingInfo rating, ISite site) { if (CallingUser == null || CallingUser.UserID == 0) { throw ApiException.GetError(ErrorType.MissingUserCredentials); } if (RatingsReadByDNAUserID(RatingForum.Id, site, CallingUser.UserID) != null) { throw ApiException.GetError(ErrorType.MultipleRatingByUser); } //check if processpremod option is set... if (RatingForum.ModerationServiceGroup == ModerationStatus.ForumStatus.PreMod && SiteList.GetSiteOptionValueBool(site.SiteID, "Moderation", "ProcessPreMod")) { throw ApiException.GetError(ErrorType.InvalidProcessPreModState); } int max_rating = SiteList.GetSiteOptionValueInt(site.SiteID, "CommentForum", "MaxForumRatingScore"); if (rating.rating > max_rating) { throw ApiException.GetError(ErrorType.RatingExceedsMaximumAllowed); } }
/// <summary> /// Creates a rating for the given rating forum /// </summary> /// <param name="RatingForum">The forum to post to</param> /// <param name="rating">The rating to add</param> /// <returns>The created rating object</returns> public RatingInfo RatingCreate(RatingForum RatingForum, RatingInfo rating) { ISite site = SiteList.GetSite(RatingForum.SiteName); //check for repeat posting ValidateRating(RatingForum, rating, site); Comments commentsObj = new Comments(DnaDiagnostics, DnaDataReaderCreator, CacheManager, SiteList); commentsObj.CallingUser = CallingUser; commentsObj.BbcUid = BbcUid; commentsObj.IpAddress = IpAddress; //create the thread entry RatingInfo createdRating = (RatingInfo)commentsObj.CreateComment((Forum)RatingForum, (CommentInfo)rating); using (var reader = CreateReader("ratingscreate")) { reader.AddParameter("entryid", createdRating.ID); reader.AddParameter("uid", RatingForum.Id); reader.AddParameter("rating", rating.rating); reader.AddParameter("userid", CallingUser.UserID); reader.AddParameter("siteid", site.SiteID); reader.Execute(); } createdRating.rating = rating.rating; return createdRating; }
public void RatingForumCreate_MissingTitle() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_MissingTitle", ParentUri = "http://www.bbc.co.uk/dna/h2g2/" }; try { RatingForum result = _ratings.RatingForumCreate(ratingForum, site); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidForumTitle); } }
/// <summary> /// applies the site specific items /// </summary> /// <param name="comments"></param> /// <returns></returns> private RatingForum ApplySiteVariables(RatingForum forum, ISite site) { forum.isClosed = site.IsEmergencyClosed || site.IsSiteScheduledClosed(DateTime.Now) || (forum.CloseDate != null && DateTime.Now > forum.CloseDate); return forum; }
public void RatingForumCreate_MissingSiteName() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_missingSitename", ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; try { RatingForum result = _ratings.RatingForumCreate(ratingForum, null); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.UnknownSite); } }
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 RatingForumCreate_WithFixedClosedDate() { RatingForum ratingForum = new RatingForum { Id = "CommentForumCreate_InReactive" + Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum", CloseDate = DateTime.Now.AddDays(2) }; DateTime expectedCloseDate = ratingForum.CloseDate.AddDays(1);//add a day expectedCloseDate = new DateTime(expectedCloseDate.Year, expectedCloseDate.Month, expectedCloseDate.Day);//force to midnight 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); Assert.IsTrue(result.CloseDate == expectedCloseDate); }
/// <summary> /// tests successful RatingForumCreate /// </summary> public RatingForum RatingForumCreate(string id, ModerationStatus.ForumStatus moderationStatus, DateTime closingDate) { RatingForum ratingForum = new RatingForum { Id = id, ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testratingForum", ModerationServiceGroup = moderationStatus, CloseDate = closingDate }; 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); return result; }
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 RatingsReadByForumID() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_good" + Guid.NewGuid().ToString(), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; RatingForum resultCommentForum = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(resultCommentForum != null); Assert.IsTrue(resultCommentForum.Id == ratingForum.Id); Assert.IsTrue(resultCommentForum.ParentUri == ratingForum.ParentUri); Assert.IsTrue(resultCommentForum.Title == ratingForum.Title); }
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 RatingForumCreate_WithTooManyUIDChars() { //create namespace and ID which equal 255 RatingForum ratingForum = new RatingForum { Id = "".PadRight(256, 'I'), ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; try { //should throw error stating uid length too long RatingForum result = _ratings.RatingForumCreate(ratingForum, site); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidForumUid); } }
public Stream CreateRatingForumWithRating(string sitename, RatingForum ratingForum, string reviewForumId) { RatingForum RatingForumData = null; try { ratingForum.Id = reviewForumId; ISite site = GetSite(sitename); _ratingObj.CallingUser = GetCallingUser(site); RatingForumData = _ratingObj.RatingForumCreate(ratingForum, site); if (ratingForum.ratingsList != null && ratingForum.ratingsList.ratings != null && ratingForum.ratingsList.ratings.Count > 0) {//check if there is a rating to add RatingInfo ratingInfo = _ratingObj.RatingCreate(RatingForumData, ratingForum.ratingsList.ratings[0]); return GetOutputStream(ratingInfo); } else { return GetOutputStream(RatingForumData); } } catch (ApiException ex) { throw new DnaWebProtocolException(ex); } }
public void RatingForumCreate_Duplicate() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_dupe", ParentUri = "http://www.bbc.co.uk/dna/h2g2/", Title = "testCommentForum" }; 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); RatingForum dupResult = _ratings.RatingForumCreate(ratingForum, site); Assert.IsTrue(dupResult.Created.At == result.Created.At); }
public void CreateRatingForumPostData(string sitename, NameValueCollection formsData) { RatingForum RatingForumData = null; ErrorType error = ErrorType.Unknown; DnaWebProtocolException _ex = null; try { RatingForumData = new RatingForum { Id = formsData["id"], Title = formsData["title"], ParentUri = formsData["parentUri"] }; if(!String.IsNullOrEmpty(formsData["moderationServiceGroup"])) { try { RatingForumData.ModerationServiceGroup = (ModerationStatus.ForumStatus)Enum.Parse(ModerationStatus.ForumStatus.Unknown.GetType(), formsData["moderationServiceGroup"]); } catch { throw new DnaWebProtocolException(ApiException.GetError(ErrorType.InvalidModerationStatus)); } } if (!String.IsNullOrEmpty(formsData["closeDate"])) { DateTime closed = DateTime.Now; if (!DateTime.TryParse(formsData["closeDate"], out closed)) { throw ApiException.GetError(ErrorType.InvalidForumClosedDate); } RatingForumData.CloseDate = closed; } CreateRatingForum(sitename, RatingForumData); 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 RatingForumCreate_MissingUri() { RatingForum ratingForum = new RatingForum { Id = "testCommentForum_MissingParentUri", Title = "testCommentForum_MissingParentUri" }; try { RatingForum result = _ratings.RatingForumCreate(ratingForum, site); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidForumParentUri); } //check that parentUri is from bbc.co.uk ratingForum = new RatingForum { Id = "testCommentForum_MissingParentUri", Title = "testCommentForum_MissingParentUri", ParentUri = "http://www.google.com" }; try { RatingForum result = _ratings.RatingForumCreate(ratingForum, site); } catch (ApiException ex) { Assert.IsTrue(ex.type == ErrorType.InvalidForumParentUri); } }
private void PostToRatingForumAsIdentityUser(RatingForum ratingForum, DnaTestURLRequest request, string sitename) { string text = "Functiontest Title" + Guid.NewGuid().ToString(); string ratingXml = String.Format("<rating xmlns=\"BBC.Dna.Api\">" + "<text>{0}</text><rating>{1}</rating>" + "</rating>", text, 5); // Setup the request url string url = String.Format("https://" + _secureserver + "/dna/api/comments/ReviewService.svc/V1/site/{0}/reviewforum/{1}/", sitename, ratingForum.Id); string userName = "******" + DateTime.Now.Ticks.ToString(); string userEmail = userName + "@bbc.co.uk"; Assert.IsTrue(request.SetCurrentUserAsNewIdentityUser(userName, "password", "RatingForumCommenter", userEmail, "1989-12-31", TestUserCreator.IdentityPolicies.Adult, 1, TestUserCreator.UserType.IdentityOnly), "Failed to create a test identity user"); // now get the response request.RequestPageWithFullURL(url, ratingXml, "text/xml"); }
/// <summary> /// Reads a specific rating by the forum ID and **IDENTITY** user id list /// </summary> /// <param name="forumid">The forums internal id</param> /// <param name="site">The sites internal id</param> /// <param name="userids">The user ids - A LIST OF IDENTITY USER IDs</param> /// <returns>The list of comments</returns> private RatingForum RatingsReadByUserIDs(RatingForum ratingForum, ISite site, int[] userIds) { if (userIds == null || userIds.Length == 0) {// check if the user id list is valid throw ApiException.GetError(ErrorType.MissingUserList); } //set up paging items ratingForum.ratingsList = new RatingsList(); ratingForum.ratingsList.ratings = new List<RatingInfo>(); ratingForum.ratingsList.TotalCount = 0; ratingForum.ratingsList.ItemsPerPage = ItemsPerPage; ratingForum.ratingsList.StartIndex = StartIndex; ratingForum.ratingsList.SortBy = SortBy; ratingForum.ratingsList.SortDirection = SortDirection; ratingForum.ratingsList.FilterBy = FilterBy; string userList = String.Join("|", Array.ConvertAll<int, string>(userIds, delegate(int s) { return s.ToString(); })); using (var reader = CreateReader("RatingsReadByForumandUsers")) { reader.AddParameter("forumid", ratingForum.ForumID); reader.AddParameter("userlist", userList); reader.AddParameter("startindex", StartIndex); reader.AddParameter("itemsperpage", ItemsPerPage); reader.AddParameter("SortBy", SortBy.ToString()); reader.AddParameter("SortDirection", SortDirection.ToString()); reader.Execute(); if (reader.HasRows) { while (reader.Read()) { //set the summary total and average ratingForum.ratingsSummary.Total = reader.GetInt32NullAsZero("totalresults"); ratingForum.ratingsSummary.Average = reader.GetInt32NullAsZero("average"); ratingForum.ratingsList.ratings.Add(RatingCreateFromReader(reader, site)); ratingForum.ratingsList.TotalCount = reader.GetInt32NullAsZero("totalresults"); } } else { ratingForum.ratingsSummary.Total = 0; ratingForum.ratingsSummary.Average = 0; } } //return null if no ratings return ratingForum; }