Example #1
0
        public void DestroyStatusTest()
        {
            string   id       = "1";
            XElement expected = XElement.Parse(m_testStatusQueryResponse);

            Expect.Once.On(m_twitterExecute)
            .Method("ExecuteTwitter")
            .Will(Return.Value(expected));

            Status actual = m_ctx.DestroyStatus(id);

            Assert.AreEqual(expected.Element("status").Element("id").Value, actual.StatusID);
        }
Example #2
0
        public void DestroyStatusTest()
        {
            string id           = "1";
            Status expected     = new Status();
            var    expectedList =
                new List <Status>
            {
                expected
            };

            Expect.Once.On(m_twitterExecute)
            .Method("ExecuteTwitter")
            .Will(Return.Value(expectedList));
            Status actual = m_ctx.DestroyStatus(id);

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        /// <summary>
        /// shows how to delete a status
        /// </summary>
        /// <param name="twitterCtx">TwitterContext</param>
        private static void DestroyStatusDemo(TwitterContext twitterCtx)
        {
            var status = twitterCtx.DestroyStatus("280433519057068033");

            Console.WriteLine(
                "(" + status.StatusID + ")" +
                "[" + status.User.ID + "]" +
                status.User.Name + ", " +
                status.Text + ", " +
                status.CreatedAt);
        }
        //We start multiple actions in parallel to delete tweets
        void EraseTweetsAction(TwitterContext ctx, CancellationToken cancelToken)
        {
            int nextTweetID = getNextTweetIDSync();

            //Are we done?
            while (nextTweetID != Int32.MinValue)
            {
                //We can't cancel here, we have already fetched a new ID and if we cancel here it will never be deteled

                Tweet tweet = tweets[nextTweetID];

                //Clear Tweets logic here
                try
                {
#if DEBUG
                    Thread.Sleep(sleepFakeWaitMilliseconds);
#else
                    Status ret = ctx.DestroyStatus(tweet.ID);
#endif
                    tweet.Status = "[DELETED ✔]";
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Sorry, that page does not exist"))
                    {
                        tweet.Status = "[NOT FOUND ǃ]";
                    }
                    else if (ex.Message.Contains("You may not delete another user's status"))
                    {
                        tweet.Status = "[NOT ALLOWED ❌]";
                    }
                    else
                    {
                        tweet.Status = "[ERROR]";
                    }
                }

                onDeletingTweetUIUpdate(tweet);

                //We cancel once a tweet is completely handeled, we make sure not to request for a new one
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                nextTweetID = getNextTweetIDSync();
            }
        }
Example #5
0
        //We start multiple actions in parallel to delete tweets
        void EraseTweetsAction(TwitterContext ctx, CancellationToken cancelToken)
        {
            int nextTweetID = getNextTweetIDSync();

#if DEBUG
            Random rnd = new Random();
#endif

            //Are we done?
            while (nextTweetID != Int32.MinValue)
            {
                //We can't cancel here, we have already fetched a new ID and if we cancel here it will never be deteled

                Tweet tweet = tweets[nextTweetID];

                //Clear Tweets logic here
                try
                {
#if DEBUG
                    Thread.Sleep(sleepFakeWaitMilliseconds);
                    if (rnd.Next() % 3 == 0)    // Simulate error
                    {
                        throw new ArgumentNullException();
                    }
                    else
                    {
                        throw new Exception("Sorry, that page does not exist");
                    }
#else
                    Status ret = ctx.DestroyStatus(tweet.ID);
#endif
                    tweet.Status = STATUS_DELETED;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Sorry, that page does not exist"))
                    {
                        tweet.Status = STATUS_NOT_FOUND;
                    }
                    else if (ex.Message.Contains("You may not delete another user's status"))
                    {
                        tweet.Status = STATUS_NOT_ALLOWED;
                    }
                    else
                    {
                        tweet.Status = STATUS_ERROR;
                        var tmp = new tweetTJson()
                        {
                            created_at = tweet.Date.ToString("yyyy-MM-dd H:m:s zzz"), id_str = tweet.ID, text = tweet.Text
                        };

                        lock (_lockerNotDeletedTweetsLst)
                        {
                            notDeletedTweets.Add(tmp);
                        }
                    }
                }

                onDeletingTweetUIUpdate(tweet);

                //We cancel once a tweet is completely handeled, we make sure not to request for a new one
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                nextTweetID = getNextTweetIDSync();
            }
        }