コード例 #1
0
ファイル: Context.cs プロジェクト: rocketeerbkw/DNA
 public Context(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
 {
     DnaDiagnostics = dnaDiagnostics;
     DnaDataReaderCreator = dataReaderCreator;
     CacheManager = cacheManager;
     SiteList = siteList;
 }
コード例 #2
0
ファイル: commentforums_v1.cs プロジェクト: rocketeerbkw/DNA
        public void StartUp()
        {
            SnapshotInitialisation.RestoreFromSnapshot();
            FullInputContext context = new FullInputContext("");

            _siteList = context.SiteList;
        }
コード例 #3
0
ファイル: CallingUser.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Debug constructor
 /// </summary>
 /// <param name="signInSystem">The sign in system to use</param>
 /// <param name="dnaDataReaderCreator">A DnaDataReaderCreator object for creating the procedure this class needs.
 /// If NULL, it uses the connection stringsfrom the configuration manager</param>
 /// <param name="dnaDiagnostics">A DnaDiagnostics object for logging purposes</param>
 /// <param name="caching">The caching object that the class can use for caching</param>
 /// <param name="debugUserID">A userid for debugging/testing purposes</param>
 /// <param name="siteList">A SiteList object for getting siteoption values</param>
 public CallingUser(SignInSystem signInSystem, IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager caching, string debugUserID, ISiteList siteList)
     : base(dnaDataReaderCreator, dnaDiagnostics, caching)
 {
     _signInSystem = signInSystem;
     _debugUserID = debugUserID;
     _siteList = siteList;
 }
コード例 #4
0
ファイル: CommentCreate.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Constructor
 /// </summary>
 public CommentCreateTests()
 {
     using (FullInputContext inputcontext = new FullInputContext(""))
     {
         _siteList = SiteList.GetSiteList();
         site = _siteList.GetSite("h2g2");
         _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
     }
     
 }
コード例 #5
0
ファイル: Global.asax.cs プロジェクト: rocketeerbkw/DNA
        protected void Application_Start(object sender, EventArgs e)
        {
            //System.Diagnostics.Debugger.Launch();
            if (ConfigurationManager.AppSettings["MaintenanceMode"] == "1")
            {//do nothing if in maintenance
                return;
            }

            Statistics.InitialiseIfEmpty(null, false);
            dnaDiagnostics = new DnaDiagnostics(RequestIdGenerator.GetNextRequestId(), DateTime.Now);
            connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
            readerCreator = new DnaDataReaderCreator(connectionString, dnaDiagnostics);

            try
            {
                emailServerAddress = ConfigurationManager.AppSettings["EmailServer"];
            }
            catch
            {
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to find config email server address - no emails will be sent!");
            }

            try
            {
                fileCacheFolder = ConfigurationManager.AppSettings["FileCacheFolder"];
            }
            catch
            {
                fileCacheFolder = Environment.GetEnvironmentVariable("Temp");
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to find config file cache folder - Defaulting to the system temp folder!");
            }

            ICacheManager cacheManager = null;
            try
            {
                cacheManager = CacheFactory.GetCacheManager("Memcached");
            }
            catch (Exception error)
            {
                dnaDiagnostics.WriteWarningToLog("BBC.Dna.Services.Application_Start", "Unable to use memcached cachemanager - falling back to static inmemory");
                dnaDiagnostics.WriteExceptionToLog(error);
                cacheManager = new StaticCacheManager();
            }


            siteList = new SiteList(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var bannedEmails = new BannedEmails(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var userGroups = new UserGroups(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var profanityFilter = new ProfanityFilter(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            var moderationClasses = new ModerationClassListCache(readerCreator, dnaDiagnostics, cacheManager, null, null);//no sending signals from here
            BBC.Dna.Objects.SmileyTranslator.LoadSmileys(readerCreator);
        }
コード例 #6
0
ファイル: SiteListTests.cs プロジェクト: rocketeerbkw/DNA
 private static void InitialiseSiteList()
 {
     if (!_siteListloaded)
     {
         using (FullInputContext inputcontext = new FullInputContext(""))
         {
             _testSiteList = SiteList.GetSiteList();
             inputcontext.SetCurrentSite("h2g2");
             inputcontext.InitDefaultUser();
             _siteListloaded = true;
         }
     }
 }
コード例 #7
0
ファイル: RatingForum.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Constructor
        /// </summary>
        public RatingForumTests()
        {
            using (FullInputContext inputcontext = new FullInputContext(""))
            {
                _siteList = SiteList.GetSiteList();
                site = _siteList.GetSite("h2g2");

                _ratings = new Reviews(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                var b = new BannedEmails(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);
                var g = new UserGroups(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);
            }
            
        }
コード例 #8
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Creates Site XML for site list
 /// </summary>
 /// <param name="sites">The site list</param>
 public void CreateXmlSiteList(ISiteList sites)
 {
     XmlNode sitesxml = AddElementTag(RootElement, "SITE-LIST");
     foreach (BBC.Dna.Sites.Site site in sites.Ids.Values)
     {
         XmlNode sitexml = AddElementTag(sitesxml, "SITE");
         AddAttribute(sitexml, "ID", site.SiteID);
         AddTextTag(sitexml, "NAME", site.SiteName);
         AddTextTag(sitexml, "DESCRIPTION", site.Description);
         AddTextTag(sitexml, "SHORTNAME", site.ShortName);
         AddTextTag(sitexml, "SSOSERVICE", site.SSOService);
         AddTextTag(sitexml, "MODERATIONSTATUS", ((int)site.ModerationStatus).ToString());
     }
 }
コード例 #9
0
ファイル: TwitterTests.cs プロジェクト: rocketeerbkw/DNA
        public void StartUp()
        {
            SnapshotInitialisation.RestoreFromSnapshot();
            _context = new FullInputContext("");

            _siteList = _context.SiteList;

            // Create a comment forums to post tweets to, and the corresponding URLs
            CommentsTests_V1 ct = new CommentsTests_V1();
            _commentForumReactive = ct.CommentForumCreate("Tests Reactive", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.Reactive);
            _tweetPostUrlReactive= String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/",_sitename, _commentForumReactive.Id);

            _commentForumPremod = ct.CommentForumCreate("Tests Premod", Guid.NewGuid().ToString(),ModerationStatus.ForumStatus.PreMod);
            _tweetPostUrlPremod = String.Format("http://" + _server + "/dna/api/comments/TwitterService.svc/V1/site/{0}/commentsforums/{1}/", _sitename, _commentForumPremod.Id);
        }
コード例 #10
0
ファイル: CommentForum.cs プロジェクト: rocketeerbkw/DNA
        public void StartUp()
        {
            SnapshotInitialisation.ForceRestore();
            Statistics.InitialiseIfEmpty();

            using (FullInputContext inputcontext = new FullInputContext(""))
            {
                _siteList = SiteList.GetSiteList();
                site = _siteList.GetSite("h2g2");

                _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                
                ICacheManager groupsCache = new StaticCacheManager();
                var g = new UserGroups(DnaMockery.CreateDatabaseReaderCreator(), null, groupsCache, null, null);
                var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), null, groupsCache, null, null);
                var b = new BannedEmails(DnaMockery.CreateDatabaseReaderCreator(), null, groupsCache, null, null);
            }
        }
コード例 #11
0
ファイル: Context.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dnaDiagnostics"></param>
        /// <param name="dataReaderCreator"></param>
        /// <param name="cacheManager"></param>
        /// <param name="siteList"></param>
        public Context(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
        {
            BasePath = String.Empty;
            IpAddress = string.Empty;
            SummaryLength = 256;
            FilterBy = FilterBy.None;
            SortDirection = SortDirection.Ascending;
            SortBy = SortBy.Created;
            SignOnType = String.Empty;
            ItemsPerPage = 20;
            _dnaDiagnostics = dnaDiagnostics;
            _dnaDataReaderCreator = dataReaderCreator;

            if (_dnaDiagnostics == null)
            {
                _dnaDiagnostics = new DnaDiagnostics(RequestIdGenerator.GetNextRequestId(), DateTime.Now);
            }

            _cacheManager = cacheManager;
            _siteList = siteList;
        }
コード例 #12
0
        public void StartUp()
        {
            SnapshotInitialisation.RestoreFromSnapshot();
            Statistics.InitialiseIfEmpty(null,false);
            Statistics.ResetCounters();

            using (FullInputContext inputcontext = new FullInputContext(""))
            {
                using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                {//force processpremod out...
                    reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=1 and Name='ProcessPreMod'");
                }
                _siteList = SiteList.GetSiteList();
                site = _siteList.GetSite("h2g2");

                _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                var bannedEmails = new BannedEmails(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here
                var userGroups = new UserGroups(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here
                var profanityFilter = new ProfanityFilter(inputcontext.ReaderCreator, inputcontext.dnaDiagnostics, CacheFactory.GetCacheManager(), null, null);//no sending signals from here            
            }
        }
コード例 #13
0
ファイル: CommentCreate.cs プロジェクト: rocketeerbkw/DNA
 private void RemoveCharLimitForSite()
 {
     using (FullInputContext inputcontext = new FullInputContext(""))
     {
         using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
         {
             reader.ExecuteDEBUGONLY("delete from siteoptions where SiteID=" + site.SiteID.ToString() + " and Name='MaxCommentCharacterLength'");
             _siteList = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
             _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
         }
     }
 }
コード例 #14
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Generate a list of site options for all sites.
        /// Does not include Global Site Options for each site to avoid duplication of XML.
        /// </summary>
        /// <param name="sites"></param>
        /// <returns></returns>
        public XmlNode GetSiteOptionListXml(ISiteList sites)
        {
            if (RootElement.HasChildNodes)
            {
                RootElement.RemoveAll();
            }

            XmlNode siteOptionsListXml = AddElementTag(RootElement, "SITEOPTIONSLIST");

            foreach ( KeyValuePair<int, BBC.Dna.Sites.Site> site in sites.Ids)
            {
                XmlNode siteOptionsXml = AddElementTag(siteOptionsListXml, "SITEOPTIONS");
                AddAttribute(siteOptionsXml, "SITEID", site.Key);
                
                List<SiteOption> list = sites.GetSiteOptionListForSite(site.Key);
                foreach (SiteOption so in list)
                {
                    if (!so.IsGlobal)
                    {
                        XmlNode siteOptionXml = AddElementTag(siteOptionsXml, "SITEOPTION");
                        AddAttribute(siteOptionXml, "GLOBAL", Convert.ToInt32(so.IsGlobal));
                        AddTextTag(siteOptionXml, "SECTION", so.Section);
                        AddTextTag(siteOptionXml, "NAME", so.Name);
                        AddTextTag(siteOptionXml, "VALUE", so.GetRawValue());
                        AddTextTag(siteOptionXml, "TYPE", ((int)so.OptionType).ToString());
                        AddTextTag(siteOptionXml, "DESCRIPTION", so.Description);
                    }
                }
            }
            return siteOptionsListXml;
        }
コード例 #15
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sites"></param>
        /// <param name="fullSiteDetails"></param>
        /// <param name="rootTagName"></param>
        /// <returns></returns>
        public XmlNode GenerateSitesForUserAsEditorXml(ISiteList sites, bool fullSiteDetails, string rootTagName)
        {
            if (IsEmpty)
            {

                XmlElement root = AddElementTag(RootElement, rootTagName);
                foreach (var id in sites.Ids.Values)
                {
                    if (InputContext.ViewingUser.IsSuperUser || UserGroupsHelper.IsUserEditorForSite(InputContext.ViewingUser.UserID, id.SiteID, InputContext))
                    {
                        GenerateXml(null, id, root, fullSiteDetails);
                    }
                }
            }
            return RootElement;
        }
コード例 #16
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Returns all sites that the user is an editor for
 /// </summary>
 /// <param name="sites"></param>
 /// <returns></returns>
 public XmlNode GenerateSitesForUserAsEditorXml(ISiteList sites)
 {
     return GenerateSitesForUserAsEditorXml(sites, true, "SITE-LIST");
 }
コード例 #17
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Create an Xml representation of the whole site list
        /// <param name="sites">The site list</param>
        /// </summary>
        /// <returns>XmlNode pointing to the root of the document</returns>
        public XmlNode GenerateAllSitesXml(ISiteList sites)
        {
            /*
             * <SITE-LIST>
                    <SITE ID="17">
                <NAME>1xtra</NAME>
                <DESCRIPTION>1xtra messageboard</DESCRIPTION>
                <SHORTNAME>1xtra</SHORTNAME>
                </SITE>
                    <SITE ID="3">
                <NAME>360</NAME>
                <DESCRIPTION>360</DESCRIPTION>
                <SHORTNAME>360</SHORTNAME>
                </SITE>
             * </SITE-LIST>
             */

            if (IsEmpty)
            {
                XmlElement root = AddElementTag(RootElement, "SITE-LIST");
                foreach (var id in sites.Ids.Values)
                {
                    GenerateXml(null, id, root, true);
                }
            }
            return RootElement;
        }
コード例 #18
0
ファイル: ForumThreadsTest.cs プロジェクト: rocketeerbkw/DNA
        private static void GetSiteForForumIdTestSetup(out MockRepository mocks, out IDnaDataReaderCreator creator,
                                                       out ISiteList siteList)
        {
            const int siteId = 1;
            mocks = new MockRepository();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("SiteID")).Return(siteId);

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


            var site = mocks.DynamicMock<ISite>();
            site.Stub(x => x.SiteID).Return(siteId);

            siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSite(siteId)).Return(site);
            mocks.ReplayAll();
        }
コード例 #19
0
ファイル: RatingCreate.cs プロジェクト: rocketeerbkw/DNA
        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);
                    }
                }
            }
        }
コード例 #20
0
ファイル: CommentCreate.cs プロジェクト: rocketeerbkw/DNA
        public void CommentCreate_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");
                _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), inputcontext.SiteList);
            }

            try
            {

                //set up test data
                CommentInfo comment = new CommentInfo
                {
                    text = "this is a nunit generated comment."
                };
                comment.text += Guid.NewGuid().ToString();//have to randomize the string to post

                string IPAddress = String.Empty;
                Guid BBCUid = Guid.NewGuid();
                string commentForumID = "testCommentForum" + Guid.NewGuid().ToString();

                CommentForum commentForum = CommentForumCreate(commentForumID, ModerationStatus.ForumStatus.Unknown);//should override this with the site value
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.IsUserSignedInSecure(TestUtils.TestUserAccounts.GetNormalUserAccount.Cookie, TestUtils.TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);

                CommentInfo result = _comments.CreateComment(commentForum, comment);

                Assert.IsTrue(result != null);
                Assert.IsTrue(result.ID == 0);//should be have no post ID
                Assert.IsTrue(result.text == "This post is awaiting moderation.");

                //check if post in PreModPostings queue table
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    using (IDnaDataReader reader = inputcontext.CreateDnaDataReader(""))
                    {
                        reader.ExecuteDEBUGONLY("select top 1 * from PreModPostings where dateposted > DATEADD(mi, -1, getdate())");//must be within 2 mins of post date
                        if (!reader.Read() || !reader.HasRows)
                        {
                            Assert.Fail("Post not in ThreadMod PreModPostings and moderation queue");
                        }
                    }
                }
            }
            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 = new SiteList(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);
                    site = _siteList.GetSite("h2g2");
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                }
            }
        }
コード例 #21
0
 public ExternalLinkModeration(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
     : base(dnaDiagnostics, dataReaderCreator, cacheManager, siteList)
 {
 }
コード例 #22
0
        public void CommentForum_SiteEmergencyClose()
        {
            try
            {
                CommentForum commentForum = new CommentForum
                {
                    Id = Guid.NewGuid().ToString(),
                    ParentUri = "http://www.bbc.co.uk/dna/h2g2/",
                    Title = "testCommentForum"
                };

                CommentForum result = _comments.CreateCommentForum(commentForum, site);
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.Id == commentForum.Id);
                Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
                Assert.IsTrue(result.Title == commentForum.Title);
                Assert.IsTrue(result.commentSummary.Total == 0);

                //add a comment 
                CommentInfo comment = new CommentInfo { text = "this is a nunit generated comment." + Guid.NewGuid().ToString() };
                //normal user
                _comments.CallingUser = new CallingUser(SignInSystem.DebugIdentity, null, null, null, TestUserAccounts.GetNormalUserAccount.UserName, _siteList);
                _comments.CallingUser.IsUserSignedInSecure(TestUserAccounts.GetNormalUserAccount.Cookie, TestUserAccounts.GetNormalUserAccount.SecureCookie, site.IdentityPolicy, site.SiteID, null, Guid.Empty);
                _comments.CreateComment(result, comment);

                //get forum again
                result = _comments.GetCommentForumByUid(result.Id, site);
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.Id == commentForum.Id);
                Assert.IsTrue(result.ParentUri == commentForum.ParentUri);
                Assert.IsTrue(result.Title == commentForum.Title);
                Assert.IsTrue(result.commentSummary.Total == 1);

                //close site
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = true;
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                    
                }

                result = _comments.GetCommentForumByUid(result.Id, site);
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.isClosed);

                //reopen site
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = false;
            }
            finally
            {
                _siteList.GetSite(site.ShortName).IsEmergencyClosed = false;
                using (FullInputContext inputcontext = new FullInputContext(""))
                {
                    _siteList = SiteList.GetSiteList();
                    site = _siteList.GetSite("h2g2");
                    _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
                }
            }
        }
コード例 #23
0
ファイル: ForumThreadsTest.cs プロジェクト: rocketeerbkw/DNA
        private static void CreateJournalTestSetup(out int userId, out string identityUserName, out int forumId, out int threadId,
                                                           out int itemsPerPage, out int startIndex,
                                                           out ThreadOrder threadOrder, out bool overFlow,
                                                           out IDnaDataReaderCreator creator,
                                                           out ISiteList siteList, out int siteId)
        {
            var mocks = new MockRepository();
            siteId = 1;
            userId = 6;
            identityUserName = "******";
            forumId = 7;
            threadId = 0;
            itemsPerPage = 10;
            startIndex = 0;
            threadOrder = ThreadOrder.LatestPost;
            overFlow = true;

            var reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("Journal")).Return(forumId);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadID")).Return(threadId);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadCount")).Return(itemsPerPage + 1);
            reader.Stub(x => x.GetInt32NullAsZero("SiteID")).Return(siteId);
            reader.Stub(x => x.DoesFieldExist("ForumPostCount")).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ForumPostCount")).Return(itemsPerPage + 1);
            reader.Stub(x => x.GetDateTime("ThreadLastUpdated")).Return(DateTime.MinValue);
            reader.Stub(x => x.GetDateTime("ForumLastUpdated")).Return(DateTime.MinValue);



            creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("finduserfromidentityusername")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("finduserfromid")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("forumgetthreadlist")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("GetForumSiteID")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("cachegetforumlastupdate")).Return(reader);

            var site = mocks.DynamicMock<ISite>();
            site.Stub(x => x.SiteID).Return(siteId);

            siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSite(1)).Return(site);
            mocks.ReplayAll();
        }
コード例 #24
0
ファイル: ForumThreadsTest.cs プロジェクト: rocketeerbkw/DNA
        private static void CreateForumThreadsFromDatabaseTestSetup(out int forumId, out int threadId,
                                                                   out int itemsPerPage, out int startIndex,
                                                                   out ThreadOrder threadOrder, out bool overFlow,
                                                                   out IDnaDataReaderCreator creator,
                                                                   out ISiteList siteList, out int siteId)
        {
            var mocks = new MockRepository();
            siteId = 1;
            forumId = 1;
            threadId = 0;
            itemsPerPage = 10;
            startIndex = 0;
            threadOrder = ThreadOrder.LatestPost;
            overFlow = true;

            var reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadID")).Return(threadId);
            reader.Stub(x => x.GetInt32NullAsZero("ThreadCount")).Return(itemsPerPage + 1);
            reader.Stub(x => x.GetInt32NullAsZero("SiteID")).Return(siteId);
            reader.Stub(x => x.DoesFieldExist("ForumPostCount")).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("ForumPostCount")).Return(itemsPerPage + 1);
            reader.Stub(x => x.GetDateTime("ThreadLastUpdated")).Return(DateTime.MinValue);
            reader.Stub(x => x.GetDateTime("ForumLastUpdated")).Return(DateTime.MinValue);



            creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("forumgetthreadlist")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("GetForumSiteID")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("cachegetforumlastupdate")).Return(reader);



            var site = mocks.DynamicMock<ISite>();
            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Constraints(Is.Anything()).Return(false);

            siteList = mocks.DynamicMock<ISiteList>();
            siteList.Stub(x => x.GetSite(1)).Return(site);
            mocks.ReplayAll();
        }
コード例 #25
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// 
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="sites"></param>
        /// <param name="includeGlobal"></param>
        /// <returns></returns>
        public XmlNode GetSiteOptionListForSiteXml(int siteId, ISiteList sites, bool includeGlobal)
        {
            List<SiteOption> list = sites.GetSiteOptionListForSite(siteId);

            if (RootElement.HasChildNodes)
            {
                RootElement.RemoveAll();
            }

            XmlNode siteOptionsNode = AddElementTag(RootElement, "SITEOPTIONS");

            if (siteId > 0)
            {
                AddAttribute(siteOptionsNode, "SITEID", siteId);
            }
            else
            {
                AddAttribute(siteOptionsNode, "DEFAULTS", 1);
            }

            foreach (SiteOption so in list)
            {
                int global = 0;
                if (so.IsGlobal)
                {
                    global = 1;
                }

                if (includeGlobal || global == 0)
                {
                    XmlNode siteOptionXml = AddElementTag(siteOptionsNode, "SITEOPTION");
                    AddAttribute(siteOptionXml, "GLOBAL", global);
                    if (siteId > 0)
                    {
                        AddTextTag(siteOptionXml, "SITEID", siteId);
                    }
                    else
                    {
                        AddTextTag(siteOptionXml, "DEFINITION", 1);
                    }
                    AddTextTag(siteOptionXml, "SECTION", so.Section);
                    AddTextTag(siteOptionXml, "NAME", so.Name);
                    AddTextTag(siteOptionXml, "VALUE", so.GetRawValue());
                    AddTextTag(siteOptionXml, "TYPE", ((int)so.OptionType).ToString());
                    AddTextTag(siteOptionXml, "DESCRIPTION", so.Description);
                }
            }

            return siteOptionsNode;
        }
コード例 #26
0
ファイル: UserTests.cs プロジェクト: rocketeerbkw/DNA
        private void SetupCallingUserSenario(int siteID, string dnaUserName, string siteSuffix, bool isKidsSite, bool useIdV4, string useUDNG, out ICacheManager mockedCacheManager, out IDnaDiagnostics mockedDiagnostics, out ISiteList mockedSiteList, out IDnaDataReaderCreator mockedCreator)
        {
            mockedCacheManager = _mocks.DynamicMock<ICacheManager>();
            mockedDiagnostics = _mocks.DynamicMock<IDnaDiagnostics>();

            mockedSiteList = _mocks.DynamicMock<ISiteList>();
            mockedSiteList.Stub(x => x.GetSiteOptionValueBool(siteID, "General", "IsKidsSite")).Return(isKidsSite);
            mockedSiteList.Stub(x => x.GetSiteOptionValueBool(siteID, "CommentForum", "UseIDv4")).Return(useIdV4);
            mockedSiteList.Stub(x => x.GetSiteOptionValueString(siteID, "User", "AutoGeneratedNames")).Return(useUDNG);

            mockedCreator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            var mockedReader = _mocks.DynamicMock<IDnaDataReader>();
            var mockedUserReader = _mocks.DynamicMock<IDnaDataReader>();
            var mockedProfileReader = _mocks.DynamicMock<IDnaDataReader>();

            var mockedUpdateReader = _mocks.DynamicMock<IDnaDataReader>();
            mockedCreator.Stub(x => x.CreateDnaDataReader("updateuser2")).Return(mockedUpdateReader);
            mockedUserReader.Stub(x => x.GetInt32("userid")).Return(TestUserAccounts.GetNormalUserAccount.UserID);
            mockedUserReader.Stub(x => x.GetString("username")).Return(dnaUserName);
            mockedUserReader.Stub(x => x.GetStringNullAsEmpty("SiteSuffix")).Return(siteSuffix);
            mockedUserReader.Stub(x => x.Read()).Return(true);
            mockedUserReader.Stub(x => x.HasRows).Return(true);

            mockedCreator.Stub(x => x.CreateDnaDataReader("getbannedemails")).Return(mockedReader);
            mockedCreator.Stub(x => x.CreateDnaDataReader("createnewuserfromidentityid")).Return(mockedUserReader);
            mockedCreator.Stub(x => x.CreateDnaDataReader("synchroniseuserwithprofile")).Return(mockedProfileReader);
        }
コード例 #27
0
ファイル: SiteXmlBuilder.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Returns a list of SiteOptions for the given site.
 /// If a site option is not defined for the given site, a SiteOption with site id of 0 is
 /// given in it's place
 /// </summary>
 /// <param name="siteId">A site id</param>
 /// <param name="sites">The site list</param>
 /// <returns>List of site options for the given site</returns>
 public XmlNode GetSiteOptionListForSiteXml(int siteId, ISiteList sites)
 {
     return GetSiteOptionListForSiteXml(siteId, sites, true);
 }
コード例 #28
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Constructor with dna diagnostic object
 /// </summary>
 /// <param name="dnaDiagnostics"></param>
 /// <param name="dataReaderCreator"></param>
 /// <param name="cacheManager"></param>
 /// <param name="siteList"></param>
 public Comments(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
     : base(dnaDiagnostics, dataReaderCreator, cacheManager, siteList)
 {
 }
コード例 #29
0
ファイル: RatingCreate.cs プロジェクト: rocketeerbkw/DNA
        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);
                }
            }
        }
コード例 #30
0
ファイル: CommentCreate.cs プロジェクト: rocketeerbkw/DNA
 private void SetCharLimitTo15ForSite()
 {
     //set max char option
     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', 'MaxCommentCharacterLength','15',0,'test MaxCommentCharacterLength value')");
             _siteList = SiteList.GetSiteList();
             _comments = new Comments(inputcontext.dnaDiagnostics, inputcontext.ReaderCreator, CacheFactory.GetCacheManager(), _siteList);
         }
     }
 }