示例#1
0
        public void checkMassPostings()
        {
            AuthorManager.Maxmanagedusers = int.MaxValue;
            Utilities.Runningintestmode   = true;
            AuthorManager  authors  = new AuthorManager();
            PostingManager postings = new PostingManager();

            NLog.LogManager.DisableLogging();

            for (int i = 0; i < 5000; i++)
            {
                authors.getCoolDownTimer(10000 + i, "autor_" + i, Author.InteractionCooldownTimer.Default);
            }

            int authorid = 10000;

            for (int monat = 1; monat <= 6; monat++)
            {
                for (int tag = 1; tag <= 30; tag++)
                {
                    for (int postcount = 0; postcount < 200; postcount++)
                    {
                        postings.addPosting("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt " +
                                            "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo " +
                                            "dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " +
                                            "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor " +
                                            "invidunt ut labor" + postcount + ":" + tag + ":" + monat, authorid);
                        authorid++;
                        if (authorid > 14999)
                        {
                            authorid = 10000;
                        }
                    }
                }
            }

            DateTime     before     = DateTime.Now;
            FileStream   backupfile = File.Create("testposts.json");
            StreamWriter sr         = new StreamWriter(backupfile);

            sr.Write(JsonConvert.SerializeObject(postings, Formatting.Indented));
            sr.Close();
            TimeSpan durationToStore = DateTime.Now - before;

            Console.Out.WriteLine("Speichern dauerte " + durationToStore.TotalSeconds + " Sekunden.");

            before = DateTime.Now;
            FileStream   inputFilestream = File.OpenRead("testposts.json");
            StreamReader sreader         = new StreamReader(inputFilestream);
            string       jsonstring      = sreader.ReadToEnd();

            sreader.Close();
            postings        = JsonConvert.DeserializeObject <PostingManager>(jsonstring);
            durationToStore = DateTime.Now - before;

            Console.Out.WriteLine("Laden dauerte " + durationToStore.TotalSeconds + " Sekunden.");

            Assert.IsTrue(true);
        }
示例#2
0
        public void postDoubleVoteDenyTest()
        {
            PostingManager pmgr = new PostingManager();
            AuthorManager  amgr = new AuthorManager();

            Utilities.Runningintestmode = false;
            amgr.setPostMode(10, "user1");
            amgr.setPostMode(20, "user2");
            pmgr.addPosting("testpost", 10);
            KeyValuePair <long, string> kvp = pmgr.getNextPostToCheck();
            long postingId = kvp.Key;

            pmgr.acceptPost(postingId, PostingPublishManager.PublishHourType.Normal);
            Assert.IsFalse(pmgr.isAuthor(postingId, 20));
            Assert.IsTrue(amgr.canUserVote(postingId, 20, "hans"));
            amgr.vote(postingId, 20);
            pmgr.upvote(postingId, 5);
            Assert.IsFalse(!pmgr.isAuthor(postingId, 20) && amgr.canUserVote(postingId, 20, "hans"));
            Assert.IsFalse(!pmgr.isAuthor(postingId, 10) && amgr.canUserVote(postingId, 10, "hans"));
        }
示例#3
0
        public void topPostingFilterTest()
        {
            PostingManager  pmgr     = new PostingManager();
            DRaumStatistics drs      = new DRaumStatistics();
            const int       numposts = 20;

            for (int i = 0; i < numposts; i++)
            {
                // ein paar posts anlegen
                pmgr.addPosting("Bla bla bla", 10 + i * 10);
            }

            int count = 0;
            KeyValuePair <long, string> pair;

            do
            {
                pair = pmgr.getNextPostToCheck();
                if (pair.Key != -1)
                {
                    count++;
                    string res = pmgr.acceptPost(pair.Key, PostingPublishManager.PublishHourType.Normal);
                    Assert.IsTrue(res.StartsWith("Veröffentlichung"));
                    pmgr.testPublishing(pair.Key, DateTime.Now.AddHours(-24));
                    for (int i = 0; i < count * 3; i++)
                    {
                        if (count > numposts / 2)
                        {
                            pmgr.downvote(pair.Key, 200 + i);
                        }
                        else
                        {
                            pmgr.upvote(pair.Key, 200 + i);
                        }
                    }
                }
            } while (pair.Key != -1);

            Assert.AreEqual(numposts, count);
            IEnumerable <long> list = pmgr.getDailyTopPostsFromYesterday();
            bool found10            = false;
            bool found09            = false;
            bool found08            = false;

            foreach (long postingId in list)
            {
                if (postingId == 10)
                {
                    found10 = true;
                }
                if (postingId == 9)
                {
                    found09 = true;
                }
                if (postingId == 8)
                {
                    found08 = true;
                }
            }

            Assert.IsTrue(found10 && found09 && found08);
        }