コード例 #1
0
        public void Monitoring()
        {
            User patsy = GetTargetUser();

            reddit.User(patsy).InviteToLiveThread(LiveThread.Id, "+update", "liveupdate_contributor_invite");

            // Create a new live thread.  --Kris
            Validate(LiveThread);

            // Monitor the thread for any configuration changes.  --Kris
            LiveThread.MonitorThread();
            LiveThread.ThreadUpdated += C_LiveThreadUpdated;

            // Monitor the thread for new and abdicated/removed contributors.  --Kris
            LiveThread.GetContributors();
            LiveThread.MonitorContributors();
            LiveThread.ContributorsUpdated += C_LiveThreadContributorsUpdated;

            // Monitor the thread for new and deleted updates.  --Kris
            // TODO - Trigger an event if one of the NewUpdates list has a stricken value that differs from its OldUpdates list counterpart.  --Kris
            LiveThread.MonitorUpdates();
            LiveThread.UpdatesUpdated += C_LiveThreadUpdatesUpdated;

            // Make changes to trigger all three monitors and validate the results.  --Kris
            patsy.AcceptLiveThreadInvite(LiveThread.Id);

            // Despite what VS says, we don't want to use await here.  --Kris
            LiveThread.EditAsync(LiveThread.Title, LiveThread.Description, !LiveThread.NSFW, LiveThread.Resources);

            LiveThreadUpdates = new List <Reddit.Things.LiveUpdate>();
            for (int i = 1; i <= 5; i++)
            {
                // Despite what VS says, we don't want to use await here.  --Kris
                LiveThread.UpdateAsync("Primary user test update #" + i.ToString());
                patsy.UpdateLiveThreadAsync(LiveThread.Id, "Secondary user test update #" + i.ToString());
            }

            DateTime start = DateTime.Now;

            while ((!LiveThreadUpdated || !LiveThreadContributorsUpdated || LiveThreadUpdates.Count < 10) &&
                   start.AddMinutes(1) > DateTime.Now)
            {
            }

            // Stop monitoring and close the thread.  --Kris
            LiveThread.MonitorUpdates();
            LiveThread.UpdatesUpdated -= C_LiveThreadUpdatesUpdated;

            LiveThread.MonitorContributors();
            LiveThread.ContributorsUpdated -= C_LiveThreadContributorsUpdated;

            LiveThread.MonitorThread();
            LiveThread.ThreadUpdated -= C_LiveThreadUpdated;

            LiveThread.Close();

            Assert.IsTrue(LiveThreadUpdated);
            Assert.IsTrue(LiveThreadContributorsUpdated);
            Assert.AreEqual(10, LiveThreadUpdates.Count);
        }