Ejemplo n.º 1
0
        public void HasPhotoUrl_ReturnsTrue_WhenUrlsContainsAtLeastOneTwitterPicUrl()
        {
            var tweet = new TweetEntities {
                Urls = new Url[] {
                    new Url {
                        DisplayUrl = "pic.twitter.com/QNCBu0LkFx"
                    },
                    new Url {
                        DisplayUrl = "not.twitter.com/ABC"
                    }
                }
            };

            Assert.IsTrue(tweet.HasPhotoUrl());
        }
Ejemplo n.º 2
0
        public void HasPhotoUrl_ReturnsFalse_WhenThereAreNoPhotoUrls()
        {
            var tweet = new TweetEntities {
                Urls = new Url[] {
                    new Url {
                        DisplayUrl = "pc.twitter.com/QNCBu0LkFx"
                    },
                    new Url {
                        DisplayUrl = "pc.twitter.com/ABC"
                    }
                }
            };

            Assert.IsFalse(tweet.HasPhotoUrl());
        }
 protected void AssertTweetEntities(TweetEntities entities)
 {
     Assert.IsNotNull(entities);
     // Hashtags
     Assert.IsNotNull(entities.Hashtags);
     Assert.AreEqual(1, entities.Hashtags.Count);
     Assert.AreEqual("Twitterbird", entities.Hashtags[0].Text);
     Assert.AreEqual(19, entities.Hashtags[0].BeginOffset);
     Assert.AreEqual(31, entities.Hashtags[0].EndOffset);
     // User mentions
     Assert.IsNotNull(entities.UserMentions);
     Assert.AreEqual(2, entities.UserMentions.Count);
     Assert.AreEqual(11223344, entities.UserMentions[0].ID);
     Assert.AreEqual("ukuleleman", entities.UserMentions[0].ScreenName);
     Assert.AreEqual("Bucky Greenhorn", entities.UserMentions[0].Name);
     Assert.AreEqual(3, entities.UserMentions[0].BeginOffset);
     Assert.AreEqual(18, entities.UserMentions[0].EndOffset);
     // URLs
     Assert.IsNotNull(entities.Urls);
     Assert.AreEqual(1, entities.Urls.Count);
     Assert.AreEqual(10, entities.Urls[0].BeginOffset);
     Assert.AreEqual(30, entities.Urls[0].EndOffset);
     Assert.AreEqual("http://t.co/t35tur1", entities.Urls[0].Url);
     Assert.AreEqual("fb.me/t35tur1", entities.Urls[0].DisplayUrl);
     Assert.AreEqual("http://fb.me/t35tur1", entities.Urls[0].ExpandedUrl);
     // Media
     Assert.IsNotNull(entities.Media);
     Assert.AreEqual(1, entities.Media.Count);
     Assert.AreEqual(15, entities.Media[0].BeginOffset);
     Assert.AreEqual(35, entities.Media[0].EndOffset);
     Assert.AreEqual(114080493040967680, entities.Media[0].ID);
     Assert.AreEqual("http://t.co/rJC5Pxsu", entities.Media[0].Url);
     Assert.AreEqual("pic.twitter.com/rJC5Pxsu", entities.Media[0].DisplayUrl);
     Assert.AreEqual("http://twitter.com/yunorno/status/114080493036773378/photo/1", entities.Media[0].ExpandedUrl);
     Assert.AreEqual("http://p.twimg.com/AZVLmp-CIAAbkyy.jpg", entities.Media[0].MediaUrl);
     Assert.AreEqual("https://p.twimg.com/AZVLmp-CIAAbkyy.jpg", entities.Media[0].MediaHttpsUrl);
     Assert.AreEqual(205282515685081088, entities.Media[0].SourceStatusId);
 }
Ejemplo n.º 4
0
        private void fillTweet(Dictionary <String, object> dTweet, bool cleanString = true)
        {
            if (dTweet.GetProp("id") != null)
            {
                created_at = DateTime.ParseExact(dTweet.GetProp("created_at") as string,
                                                 "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.InvariantCulture);
                id                        = dTweet.GetProp("id") as long?;
                id_str                    = dTweet.GetProp("id_str") as string;
                text                      = dTweet.GetProp("text") as string;
                source                    = dTweet.GetProp("source ") as string;
                truncated                 = dTweet.GetProp("truncated") as bool?;
                in_reply_to_status_id     = dTweet.GetProp("in_reply_to_status_id") as int?;
                in_reply_to_status_id_str = dTweet.GetProp("in_reply_to_status_id_str") as string;
                in_reply_to_user_id       = dTweet.GetProp("in_reply_to_user_id") as int?;
                in_reply_to_user_id_str   = dTweet.GetProp("in_reply_to_user_id_str") as string;
                in_reply_to_screen_name   = dTweet.GetProp("in_reply_to_screen_name") as string;
                user                      = User.Create(dTweet.GetProp("user") as object);
                // Create Geo
                var geo = dTweet.GetProp("geo");
                // Create Coordinates
                var coordinates = dTweet.GetProp("coordinates");
                // Create Place
                var place = dTweet.GetProp("place");
                // Create Contributors
                var contributors = dTweet.GetProp("contributors");
                retweet_count      = dTweet.GetProp("retweet_count") as int?;
                entities           = new TweetEntities(dTweet["entities"] as Dictionary <String, object>);
                favorited          = dTweet.GetProp("favorited") as bool?;
                retweeted          = dTweet.GetProp("retweeted") as bool?;
                possibly_sensitive = dTweet.GetProp("possibly_sensitive") as bool?;

                if (cleanString == true)
                {
                    text = text.cleanString();
                }
            }
        }
Ejemplo n.º 5
0
        public void ProcessResults_Populates_Entities()
        {
            var tweetProc = new TweetRequestProcessor <TweetQuery> {
                BaseUrl = BaseUrl2
            };

            List <TweetQuery> results = tweetProc.ProcessResults(SingleTweet);

            Assert.IsNotNull(results);
            TweetQuery tweetQuery = results.SingleOrDefault();

            Assert.IsNotNull(tweetQuery);

            List <Tweet> tweets = tweetQuery.Tweets;

            Assert.IsNotNull(tweets);
            Assert.AreEqual(1, tweets.Count);
            Tweet tweet = tweets.FirstOrDefault();

            Assert.IsNotNull(tweet);
            TweetEntities entities = tweet.Entities;

            Assert.IsNotNull(entities);

            TweetEntityAnnotation annotation = entities?.Annotations?.FirstOrDefault();

            Assert.IsNotNull(annotation);
            Assert.AreEqual(53, annotation.Start);
            Assert.AreEqual(59, annotation.End);
            Assert.AreEqual(0.5865f, annotation.Probability);
            Assert.AreEqual("Organization", annotation.Type);
            Assert.AreEqual("Twitter", annotation.NormalizedText);

            TweetEntityMention mention = entities?.Mentions?.FirstOrDefault();

            Assert.IsNotNull(mention);
            Assert.AreEqual(7, mention.Start);
            Assert.AreEqual(14, mention.End);
            Assert.AreEqual("github", mention.Username);

            TweetEntityUrl url = entities?.Urls?.FirstOrDefault();

            Assert.IsNotNull(url);
            Assert.AreEqual(62, url.Start);
            Assert.AreEqual(85, url.End);
            Assert.AreEqual("https://t.co/jWeDEN07HN", url.Url);
            Assert.AreEqual("http://bit.ly/1b2wrHb", url.ExpandedUrl);
            Assert.AreEqual("bit.ly/1b2wrHb", url.DisplayUrl);
            Assert.AreEqual(200, url.Status);
            Assert.AreEqual("JoeMayo/LinqToTwitter", url.Title);
            Assert.AreEqual("LINQ Provider for the Twitter API (Twitter Library) - JoeMayo/LinqToTwitter", url.Description);
            Assert.AreEqual("https://github.com/JoeMayo/LinqToTwitter", url.UnwoundUrl);
            List <TweetEntityImage> images = url.Images;

            Assert.IsNotNull(images);
            Assert.AreEqual(2, images.Count);
            TweetEntityImage image = images.First();

            Assert.AreEqual("https://pbs.twimg.com/news_img/1321470110356287488/pWdfwBk5?format=png&name=orig", image.Url);
            Assert.AreEqual(100, image.Width);
            Assert.AreEqual(100, image.Height);
        }
 protected void AssertTweetEntities(TweetEntities entities)
 {
     Assert.IsNotNull(entities);
     // Hashtags
     Assert.IsNotNull(entities.Hashtags);
     Assert.AreEqual(1, entities.Hashtags.Count);
     Assert.AreEqual("Twitterbird", entities.Hashtags[0].Text);
     Assert.AreEqual(19, entities.Hashtags[0].BeginOffset);
     Assert.AreEqual(31, entities.Hashtags[0].EndOffset);
     // User mentions
     Assert.IsNotNull(entities.UserMentions);
     Assert.AreEqual(2, entities.UserMentions.Count);
     Assert.AreEqual(11223344, entities.UserMentions[0].ID);
     Assert.AreEqual("ukuleleman", entities.UserMentions[0].ScreenName);
     Assert.AreEqual("Bucky Greenhorn", entities.UserMentions[0].Name);
     Assert.AreEqual(3, entities.UserMentions[0].BeginOffset);
     Assert.AreEqual(18, entities.UserMentions[0].EndOffset);
     // URLs
     Assert.IsNotNull(entities.Urls);
     Assert.AreEqual(1, entities.Urls.Count);
     Assert.AreEqual(10, entities.Urls[0].BeginOffset);
     Assert.AreEqual(30, entities.Urls[0].EndOffset);
     Assert.AreEqual("http://t.co/t35tur1", entities.Urls[0].Url);
     Assert.AreEqual("fb.me/t35tur1", entities.Urls[0].DisplayUrl);
     Assert.AreEqual("http://fb.me/t35tur1", entities.Urls[0].ExpandedUrl);
     // Media
     Assert.IsNotNull(entities.Media);
     Assert.AreEqual(1, entities.Media.Count);
     Assert.AreEqual(15, entities.Media[0].BeginOffset);
     Assert.AreEqual(35, entities.Media[0].EndOffset);
     Assert.AreEqual(114080493040967680, entities.Media[0].ID);
     Assert.AreEqual("http://t.co/rJC5Pxsu", entities.Media[0].Url);
     Assert.AreEqual("pic.twitter.com/rJC5Pxsu", entities.Media[0].DisplayUrl);
     Assert.AreEqual("http://twitter.com/yunorno/status/114080493036773378/photo/1", entities.Media[0].ExpandedUrl);
     Assert.AreEqual("http://p.twimg.com/AZVLmp-CIAAbkyy.jpg", entities.Media[0].MediaUrl);
     Assert.AreEqual("https://p.twimg.com/AZVLmp-CIAAbkyy.jpg", entities.Media[0].MediaHttpsUrl);
     Assert.AreEqual(205282515685081088, entities.Media[0].SourceStatusId);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Populate a tweet from information retrieved from twitter
        /// </summary>
        /// <param name="dTweet">Object containing Tweet information</param>
        /// <param name="cleanString">Does the string needs to be cleanup when retrieved</param>
        protected virtual void Populate(Dictionary <String, object> dTweet, bool cleanString)
        {
            if (dTweet.GetProp("id") != null)
            {
                CreatedAt = DateTime.ParseExact(dTweet.GetProp("created_at") as string,
                                                "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.InvariantCulture);
                Id                   = Convert.ToInt64(dTweet.GetProp("id_str"));
                IdValue              = Convert.ToInt64(dTweet.GetProp("id"));
                IdStr                = dTweet.GetProp("id_str") as string;
                Text                 = dTweet.GetProp("text") as string;
                Source               = dTweet.GetProp("source ") as string;
                Truncated            = dTweet.GetProp("truncated") as bool?;
                InReplyToStatusId    = dTweet.GetProp("in_reply_to_status_id") as int?;
                InReplyToStatusIdStr = dTweet.GetProp("in_reply_to_status_id_str") as string;
                InReplyToUserId      = dTweet.GetProp("in_reply_to_user_id") as int?;
                InReplyToUserIdStr   = dTweet.GetProp("in_reply_to_user_id_str") as string;
                InReplyToScreenName  = dTweet.GetProp("in_reply_to_screen_name") as string;
                Creator              = User.Create(dTweet.GetProp("user"));

                if (_shareTokenWithChild)
                {
                    Creator.ObjectToken = _token;
                }

                Location = Geo.Create(dTweet.GetProp("geo"));

                if (Location != null)
                {
                    LocationCoordinates = Location.GeoCoordinates;
                }

                // Create Place
                _place = dTweet.GetProp("place") as string;

                // Create Contributors
                var contributors = dTweet.GetProp("contributors");

                RetweetCount = dTweet.GetProp("retweet_count") as int?;

                if (dTweet.ContainsKey("entities"))
                {
                    Entities = new TweetEntities(dTweet["entities"] as Dictionary <String, object>);
                }

                Favourited        = dTweet.GetProp("favorited") as bool?;
                Retweeted         = dTweet.GetProp("retweeted") as bool?;
                PossiblySensitive = dTweet.GetProp("possibly_sensitive") as bool?;

                if (dTweet.ContainsKey("retweeted_status"))
                {
                    var retweet = dTweet.GetProp("retweeted_status") as Dictionary <string, object>;

                    if (retweet != null)
                    {
                        Retweeting = new Tweet(retweet);
                    }
                }

                if (cleanString)
                {
                    Text = Text.CleanString();
                }

                _isTweetPublished = true;
            }
        }
Ejemplo n.º 8
0
        public void HasPhotoUrl_ReturnsFalse_WhenThereAreNoUrls()
        {
            var tweet = new TweetEntities();

            Assert.IsFalse(tweet.HasPhotoUrl());
        }