コード例 #1
0
        public void ProcessResults_WithErrors_PopulatesErrorList()
        {
            var searchProc = new TwitterSearchRequestProcessor <TwitterSearch> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <TwitterSearch> searches = searchProc.ProcessResults(SearchErrorJson);

            Assert.IsNotNull(searches);
            TwitterSearch search = searches.SingleOrDefault();

            Assert.IsNotNull(search);
            List <TwitterError> errors = search.Errors;

            Assert.IsNotNull(errors);
            Assert.AreEqual(2, errors.Count);
            TwitterError error = errors.FirstOrDefault();

            Assert.IsNotNull(error);
            Assert.AreEqual("tweet", error.ResourceType);
            Assert.AreEqual("non_public_metrics.impression_count", error.Field);
            Assert.AreEqual("Field Authorization Error", error.Title);
            Assert.AreEqual("data", error.Section);
            Assert.AreEqual("Sorry, you are not authorized to access non_public_metrics.impression_count on a Tweet.", error.Detail);
            Assert.AreEqual("https://api.twitter.com/2/problems/not-authorized-for-field", error.Type);
        }
コード例 #2
0
        public void ProcessResults_Populates_Input_Parameters()
        {
            var searchProc = new TwitterSearchRequestProcessor <TwitterSearch>()
            {
                BaseUrl     = BaseUrl2,
                Type        = SearchType.RecentSearch,
                EndTime     = new DateTime(2020, 12, 31),
                Expansions  = "123",
                MaxResults  = 100,
                MediaFields = "456",
                NextToken   = "789",
                PlaceFields = "012",
                PollFields  = "345",
                Query       = "JoeMayo",
                SinceID     = "1",
                StartTime   = new DateTime(2020, 1, 1),
                TweetFields = "678",
                UntilID     = "901",
                UserFields  = "234"
            };

            var searchResult = searchProc.ProcessResults(SearchDefaultJson);

            Assert.IsNotNull(searchResult);
            Assert.AreEqual(1, searchResult.Count);
            var search = searchResult.Single();

            Assert.IsNotNull(search);
            Assert.AreEqual(SearchType.RecentSearch, search.Type);
            Assert.AreEqual(new DateTime(2020, 12, 31), search.EndTime);
            Assert.AreEqual("123", search.Expansions);
            Assert.AreEqual(100, search.MaxResults);
            Assert.AreEqual("456", search.MediaFields);
            Assert.AreEqual("789", search.NextToken);
            Assert.AreEqual("012", search.PlaceFields);
            Assert.AreEqual("345", search.PollFields);
            Assert.AreEqual("JoeMayo", search.Query);
            Assert.AreEqual("1", search.SinceID);
            Assert.AreEqual(new DateTime(2020, 1, 1), search.StartTime);
            Assert.AreEqual("678", search.TweetFields);
            Assert.AreEqual("901", search.UntilID);
            Assert.AreEqual("234", search.UserFields);
        }
コード例 #3
0
        public void ProcessResults_Populates_Meta()
        {
            var searchProc = new TwitterSearchRequestProcessor <TwitterSearch> {
                BaseUrl = BaseUrl2
            };

            List <TwitterSearch> results = searchProc.ProcessResults(SearchDefaultJson);

            Assert.IsNotNull(results);
            TwitterSearch search = results.SingleOrDefault();

            Assert.IsNotNull(search);
            TwitterSearchMeta meta = search.Meta;

            Assert.IsNotNull(meta);
            Assert.AreEqual("1317802724407316480", meta.NewestID);
            Assert.AreEqual("1316030424850800640", meta.OldestID);
            Assert.AreEqual(4, meta.Count);
        }
コード例 #4
0
        public void ProcessResults_Populates_DefaultTweets()
        {
            var searchProc = new TwitterSearchRequestProcessor <TwitterSearch> {
                BaseUrl = BaseUrl2
            };

            List <TwitterSearch> results = searchProc.ProcessResults(SearchDefaultJson);

            Assert.IsNotNull(results);
            TwitterSearch search = results.SingleOrDefault();

            Assert.IsNotNull(search);
            List <Tweet> tweets = search.Tweets;

            Assert.IsNotNull(tweets);
            Assert.AreEqual(4, tweets.Count);
            Tweet firstTweet = tweets.FirstOrDefault();

            Assert.IsNotNull(firstTweet);
            Assert.AreEqual("1317802724407316480", firstTweet.ID);
            Assert.AreEqual("Test Data 1", firstTweet.Text);
        }
コード例 #5
0
        public void ProcessResults_Handles_Response_With_No_Results()
        {
            var searchProc = new TwitterSearchRequestProcessor <TwitterSearch> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <TwitterSearch> searches = searchProc.ProcessResults(EmptyResponse);

            Assert.IsNotNull(searches);
            TwitterSearch search = searches.SingleOrDefault();

            Assert.IsNotNull(search);
            List <Tweet> results = search.Tweets;

            Assert.IsNull(results);

            TwitterSearchMeta meta = search.Meta;

            Assert.IsNotNull(meta);
            Assert.IsNull(meta.NewestID);
            Assert.IsNull(meta.OldestID);
            Assert.AreEqual(0, meta.Count);
        }