Пример #1
0
        public void ProcessResults_Populates_Status_MetaData()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.SingleOrDefault());
            Search search = results.Single();

            Assert.IsNotNull(search);
            List <Status> statuses = search.Statuses;

            Assert.IsNotNull(statuses);
            Assert.IsTrue(statuses.Any());
            Status status = search.Statuses.First();

            Assert.IsNotNull(status);
            StatusMetaData metaData = status.MetaData;

            Assert.IsNotNull(metaData);
            Assert.AreEqual("recent", metaData.ResultType);
            Assert.AreEqual("en", metaData.IsoLanguageCode);
        }
        public void BuildURLTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            Dictionary <string, string> parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "GeoCode", "40.757929,-73.985506,25km" },
                { "SearchLanguage", "en" },
                { "Page", "1" },
                { "PageSize", "10" },
                { "Query", "LINQ to Twitter" },
                { "ShowUser", "true" },
                { "SinceID", "1" },
                { "Since", "7/4/2010" },
                { "Until", "7/4/2011" },
                { "ResultType", ResultType.Popular.ToString() },
            };
            string expected = "http://search.twitter.com/search.atom?geocode=40.757929%2c-73.985506%2c25km&lang=en&page=1&rpp=10&q=LINQ+to+Twitter&show_user=true&since=2010-07-04&until=2011-07-04&since_id=1&result_type=Popular";
            string actual;

            actual = target.BuildURL(parameters);
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void ProcessResults_Populates_Entity_Media()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            List <MediaEntity> media = results.First().Statuses[0].Entities.MediaEntities;

            Assert.IsNotNull(media);
            Assert.AreEqual(1, media.Count);
            MediaEntity firstMedia = media.First();

            Assert.AreEqual(155683816676134913ul, firstMedia.ID);
            Assert.AreEqual("http://p.twimg.com/AikZmz5CEAESBHD.jpg", firstMedia.MediaUrl);
            Assert.AreEqual("https://p.twimg.com/AikZmz5CEAESBHD.jpg", firstMedia.MediaUrlHttps);
            Assert.AreEqual("http://t.co/36MZIOyW", firstMedia.Url);
            Assert.AreEqual("pic.twitter.com/36MZIOyW", firstMedia.DisplayUrl);
            Assert.AreEqual("http://twitter.com/rschu/status/155683816671940609/photo/1", firstMedia.ExpandedUrl);
            Assert.AreEqual("photo", firstMedia.Type);
            Assert.IsNotNull(firstMedia.Sizes);
            Assert.AreEqual(5, firstMedia.Sizes.Count);
            PhotoSize firstSize = firstMedia.Sizes.First();

            Assert.AreEqual("orig", firstSize.Type);
            Assert.AreEqual(1161, firstSize.Width);
            Assert.AreEqual(925, firstSize.Height);
            Assert.AreEqual("fit", firstSize.Resize);
            Assert.AreEqual(59, firstMedia.Start);
            Assert.AreEqual(79, firstMedia.End);
        }
Пример #4
0
        public void ProcessResults_Populates_Search_MetaData()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.SingleOrDefault());
            Search search = results.Single();

            Assert.IsNotNull(search);
            SearchMetaData metaData = search.SearchMetaData;

            Assert.IsNotNull(metaData);
            Assert.AreEqual(0.046m, metaData.CompletedIn);
            Assert.AreEqual(281604225014824960ul, metaData.MaxID);
            Assert.AreEqual(5ul, metaData.SinceID);
            Assert.AreEqual(10, metaData.Count);
            Assert.AreEqual("Twitter", metaData.Query);
            Assert.AreEqual(
                "?max_id=281562053162979328&q=Twitter&geocode=37.781157%2C-122.398720%2C1mi&include_entities=1",
                metaData.NextResults);
            Assert.AreEqual(
                "?since_id=281604225014824960&q=Twitter&geocode=37.781157%2C-122.398720%2C1mi&include_entities=1",
                metaData.RefreshUrl);
        }
        public void BuildUrl_Handles_String_TweetMode()
        {
            const string ExpectedUrl   = "https://api.twitter.com/1.1/search/tweets.json?q=LINQ%20to%20Twitter&geocode=40.757929%2C-73.985506%2C25km&lang=en&count=10&until=2011-07-04&since_id=1&result_type=popular&include_entities=false&tweet_mode=extended";
            var          searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/"
            };
            var parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "GeoCode", "40.757929,-73.985506,25km" },
                { "SearchLanguage", "en" },
                { "Count", "10" },
                { "Query", "LINQ to Twitter" },
                { "SinceID", "1" },
                { "Until", new DateTime(2011, 7, 4).ToString() },
                { "ResultType", ResultType.Popular.ToString() },
                { "IncludeEntities", false.ToString() },
                { nameof(Search.TweetMode), TweetMode.Extended.ToString().ToLower() }     // "extended" string, not "1"
            };

            Request req = searchReqProc.BuildUrl(parameters);

            Assert.AreEqual(ExpectedUrl, req.FullUrl);
        }
Пример #6
0
        public void ProcessEmptyResultsTest()
        {
            SearchRequestProcessor target = new SearchRequestProcessor();
            XElement twitterResponse      = XElement.Parse(m_emptyResponse);
            IList    actual = target.ProcessResults(twitterResponse);
            var      result = actual.Cast <Search>().First();

            Assert.AreEqual(0, result.Entries.Count);
        }
        public void ProcessResultsNextTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>();
            XElement twitterResponse = XElement.Parse(m_testQueryResponse);
            IList    actual          = target.ProcessResults(twitterResponse);
            var      result          = actual.Cast <Search>().First();

            Assert.AreEqual("http://search.twitter.com/search.atom?lang=en&max_id=1600414821&page=2&q=LINQ+to+Twitter&rpp=2", result.Next);
        }
Пример #8
0
        public void ProcessResults_Instantiates_Entities()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.IsNotNull(results.First().Statuses.First().Entities);
        }
Пример #9
0
        public void ProcessResults_Populates_Source()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.AreEqual(@"<a href=""http://www.csharp-station.com/"" rel=""nofollow"">C# Station</a>", results.First().Statuses.First().Source);
        }
Пример #10
0
        public void ProcessResults_Populates_Text()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.AreEqual("RT @JoeMayo: Blogged - Working with Timelines with LINQ to Twitter: http://t.co/Cc85Yzpj #twitterapi #linq #linq2twitter", results.First().Statuses.First().Text);
        }
Пример #11
0
        public void ProcessResults_Creates_List_Of_Status()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.IsNotNull(results.First().Statuses);
            Assert.IsTrue(results.First().Statuses.Any());
        }
Пример #12
0
        public void BuildUrl_Throws_When_Parameters_Null()
        {
            var searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            L2TAssert.Throws <NullReferenceException>(() =>
            {
                searchReqProc.BuildUrl(null);
            });
        }
Пример #13
0
        public void ProcessResults_Populates_CreatedAt()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            Assert.AreEqual(
                new DateTimeOffset(2012, 9, 6, 0, 10, 12, new TimeSpan(0, 0, 0)),
                results.First().Statuses.First().CreatedAt);
        }
Пример #14
0
        public void BuildUrl_Throws_When_Parameters_Null()
        {
            var searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            ArgumentException ex =
                Assert.Throws <ArgumentException>(() =>
            {
                searchReqProc.BuildUrl(null);
            });

            Assert.Equal("Type", ex.ParamName);
        }
        public void GetParametersTest()
        {
            var target = new SearchRequestProcessor <Search>();
            Expression <Func <Search, bool> > expression =
                search =>
                search.Type == SearchType.Search &&
                search.GeoCode == "40.757929,-73.985506,25km" &&
                search.SearchLanguage == "en" &&
                search.Count == 10 &&
                search.Query == "LINQ to Twitter" &&
                search.SinceID == 123 &&
                search.MaxID == 200 &&
                search.ResultType == ResultType.Popular &&
                search.IncludeEntities == true &&
                search.TweetMode == TweetMode.Extended;
            var lambdaExpression = expression as LambdaExpression;

            Dictionary <string, string> queryParams = target.GetParameters(lambdaExpression);

            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Type", ((int)SearchType.Search).ToString(CultureInfo.InvariantCulture))));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("GeoCode", "40.757929,-73.985506,25km")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("SearchLanguage", "en")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Count", "10")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Query", "LINQ to Twitter")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("SinceID", "123")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("MaxID", "200")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("ResultType", ((int)ResultType.Popular).ToString(CultureInfo.InvariantCulture))));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("IncludeEntities", "True")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>(nameof(Search.TweetMode), ((int)TweetMode.Extended).ToString(CultureInfo.InvariantCulture))));
        }
 public void QueryTooLongTest()
 {
     SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
     {
         BaseUrl = "http://search.twitter.com/"
     };
     string expected = target.BaseUrl + "search.atom?q=Contains+Space";
     Dictionary <string, string> parameters =
         new Dictionary <string, string>
     {
         { "Type", SearchType.Search.ToString() },
         { "Query", "x01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" }
     };
     string actual = target.BuildURL(parameters);
 }
Пример #17
0
        public void BuildUrl_Throws_With_Missing_Type_Parameter()
        {
            var searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };
            var parameters = new Dictionary <string, string> {
            };

            ArgumentException ex =
                Assert.Throws <ArgumentException>(() =>
            {
                searchReqProc.BuildUrl(parameters);
            });

            Assert.Equal("Type", ex.ParamName);
        }
        public void UrlEncodedQueryTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            string expected = target.BaseUrl + "search.atom?q=Contains+Space";
            Dictionary <string, string> parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "Query", "Contains Space" }
            };
            string actual = target.BuildURL(parameters);

            Assert.AreEqual(expected, actual);
        }
Пример #19
0
        public void BuildUrl_Encodes_Query()
        {
            var searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/"
            };
            string expected   = searchReqProc.BaseUrl + "search/tweets.json?q=Contains%20Space";
            var    parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "Query", "Contains Space" }
            };

            Request req = searchReqProc.BuildUrl(parameters);

            Assert.AreEqual(expected, req.FullUrl);
        }
        public void GetParametersTest()
        {
            var target = new SearchRequestProcessor<Search>();
            Expression<Func<Search, bool>> expression =
                search =>
                    search.Type == SearchType.Search &&
                    search.GeoCode == "40.757929,-73.985506,25km" &&
                    search.SearchLanguage == "en" &&
                    search.Count == 10 &&
                    search.Query == "LINQ to Twitter" &&
                    search.SinceID == 123 &&
                    search.MaxID == 200 &&
                    search.ResultType == ResultType.Popular &&
                    search.IncludeEntities == true;
            var lambdaExpression = expression as LambdaExpression;

            var queryParams = target.GetParameters(lambdaExpression);

            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Type", ((int)SearchType.Search).ToString(CultureInfo.InvariantCulture))));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("GeoCode", "40.757929,-73.985506,25km")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("SearchLanguage", "en")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Count", "10")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Query", "LINQ to Twitter")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("SinceID", "123")));
            Assert.IsTrue(
               queryParams.Contains(
                   new KeyValuePair<string, string>("MaxID", "200")));
            Assert.IsTrue(
               queryParams.Contains(
                   new KeyValuePair<string, string>("ResultType", ((int)ResultType.Popular).ToString(CultureInfo.InvariantCulture))));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("IncludeEntities", "True")));
        }
Пример #21
0
        public void BuildUrl_Requires_Query()
        {
            var searchReqProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };
            var parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "Query", null }
            };

            ArgumentException ex =
                L2TAssert.Throws <ArgumentNullException>(() =>
                                                         searchReqProc.BuildUrl(parameters));

            Assert.AreEqual("Query", ex.ParamName);
        }
Пример #22
0
        public void BuildUrl_Adds_True_IncludeEntities()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/"
            };
            const string Expected   = "https://api.twitter.com/1.1/search/tweets.json?q=LINQ%20to%20Twitter&include_entities=true";
            var          parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "Query", "LINQ to Twitter" },
                { "IncludeEntities", true.ToString(CultureInfo.InvariantCulture) }
            };

            Request req = searchProc.BuildUrl(parameters);

            Assert.AreEqual(Expected, req.FullUrl);
        }
Пример #23
0
        public void ProcessResults_Handles_Response_With_No_Results()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

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

            Assert.IsNotNull(searches);
            Assert.IsNotNull(searches.SingleOrDefault());
            var search = searches.Single();

            Assert.IsNotNull(search);
            var results = search.Statuses;

            Assert.IsNotNull(results);
            Assert.IsFalse(results.Any());
        }
Пример #24
0
        public void ProcessResults_Populates_Entity_Symbols()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            List <SymbolEntity> symbols = results.First().Statuses[0].Entities.SymbolEntities;

            Assert.IsNotNull(symbols);
            Assert.AreEqual(2, symbols.Count);
            SymbolEntity symbol = symbols.First();

            Assert.AreEqual("PEP", symbol.Text);
            Assert.AreEqual(114, symbol.Start);
            Assert.AreEqual(118, symbol.End);
        }
        public void BuildShowUserSetToFalseURLTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            Dictionary <string, string> parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "ShowUser", false.ToString() },
            };
            string expected = "http://search.twitter.com/search.atom";
            string actual;

            actual = target.BuildURL(parameters);
            Assert.AreEqual(expected, actual);
        }
        public void BuildAttitudeWithoutPositiveURLTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            Dictionary <string, string> parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "Attitude", (Attitude.Negative | Attitude.Question).ToString() },
            };
            string expected = "http://search.twitter.com/search.atom?tude%5B%5D=%3A%28&tude%5B%5D=%3F";
            string actual;

            actual = target.BuildURL(parameters);
            Assert.AreEqual(expected, actual);
        }
Пример #27
0
        public void ProcessResults_Populates_Entity_Hashtags()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            List <HashTagEntity> hashes = results.First().Statuses[0].Entities.HashTagEntities;

            Assert.IsNotNull(hashes);
            Assert.AreEqual(3, hashes.Count);
            HashTagEntity firstHash = hashes.First();

            Assert.AreEqual("twitterapi", firstHash.Tag);
            Assert.AreEqual(89, firstHash.Start);
            Assert.AreEqual(100, firstHash.End);
        }
        public void NullParametersTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            Dictionary <string, string> parameters = null;
            string actual;

            try
            {
                actual = target.BuildURL(parameters);
                Assert.Fail("Expected ArgumentException.");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual <string>("Type", ae.ParamName);
            }
        }
        public void BuildOtherURLTest()
        {
            SearchRequestProcessor <Search> target = new SearchRequestProcessor <Search>()
            {
                BaseUrl = "http://search.twitter.com/"
            };
            Dictionary <string, string> parameters =
                new Dictionary <string, string>
            {
                { "Type", SearchType.Search.ToString() },
                { "WithLinks", true.ToString() },
                { "WithRetweets", true.ToString() }
            };
            string expected = "http://search.twitter.com/search.atom?filter%5B%5D=links&include%5B%5D=retweets";
            string actual;

            actual = target.BuildURL(parameters);
            Assert.AreEqual(expected, actual);
        }
Пример #30
0
        public void GetParametersTest()
        {
            SearchRequestProcessor            target     = new SearchRequestProcessor();
            Expression <Func <Search, bool> > expression =
                search =>
                search.Type == SearchType.Search &&
                search.GeoCode == "40.757929,-73.985506,25km" &&
                search.Language == "en" &&
                search.Page == 1 &&
                search.PageSize == 10 &&
                search.Query == "LINQ to Twitter" &&
                search.ShowUser == "true" &&
                search.SinceID == 123;
            LambdaExpression lambdaExpression = expression as LambdaExpression;

            var queryParams = target.GetParameters(lambdaExpression);

            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Type", ((int)SearchType.Search).ToString())));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("GeoCode", "40.757929,-73.985506,25km")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Language", "en")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Page", "1")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("PageSize", "10")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("Query", "LINQ to Twitter")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("ShowUser", "true")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair <string, string>("SinceID", "123")));
        }
Пример #31
0
        public void ProcessResults_Populates_Entity_Users()
        {
            var searchProc = new SearchRequestProcessor <Search> {
                BaseUrl = "https://api.twitter.com/1.1/search/"
            };

            List <Search> results = searchProc.ProcessResults(SearchJson);

            List <UserMentionEntity> users = results.First().Statuses[0].Entities.UserMentionEntities;

            Assert.IsNotNull(users);
            Assert.AreEqual(1, users.Count);
            UserMentionEntity firstUser = users.First();

            Assert.AreEqual("JoeMayo", firstUser.ScreenName);
            Assert.AreEqual("Joe Mayo", firstUser.Name);
            Assert.AreEqual(15411837ul, firstUser.Id);
            Assert.AreEqual(3, firstUser.Start);
            Assert.AreEqual(11, firstUser.End);
        }
        public void BuildUrl_Includes_Parameters()
        {
            const string ExpectedUrl = "https://api.twitter.com/1.1/search/tweets.json?q=LINQ%20to%20Twitter&geocode=40.757929%2C-73.985506%2C25km&lang=en&count=10&until=2011-07-04&since_id=1&result_type=popular&include_entities=false";
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/" };
            var parameters =
                new Dictionary<string, string>
                {
                    { "Type", SearchType.Search.ToString() },
                    { "GeoCode", "40.757929,-73.985506,25km" },
                    { "SearchLanguage", "en" },
                    { "Count", "10" },
                    { "Query", "LINQ to Twitter" },
                    { "SinceID", "1" },
                    { "Until", new DateTime(2011, 7, 4).ToString() },
                    { "ResultType", ResultType.Popular.ToString() },
                    { "IncludeEntities", false.ToString() }
               };

            Request req = searchReqProc.BuildUrl(parameters);

            Assert.AreEqual(ExpectedUrl, req.FullUrl);
        }
        public void BuildUrl_Throws_When_Parameters_Null()
        {
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            L2TAssert.Throws<NullReferenceException>(() =>
            {
                searchReqProc.BuildUrl(null);
            });
        }
        public void ProcessResults_Handles_Response_With_No_Results()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

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

            Assert.NotNull(searches);
            Assert.Single(searches);
            var search = searches.Single();
            Assert.NotNull(search);
            var results = search.Statuses;
            Assert.NotNull(results);
            Assert.Empty(results);
        }
 public void BuildWordsURLTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
     Dictionary<string, string> parameters =
         new Dictionary<string, string>
         {
             { "Type", SearchType.Search.ToString() },
             { "WordPhrase", "LINQ to Twitter" },
             { "WordAnd", "LINQ Twitter" },
             { "WordOr", "LINQ Twitter" },
             { "WordNot", "LINQ Twitter" },
             { "Hashtag", "linqtotwitter" },
        };
     string expected = "http://search.twitter.com/search.atom?exact=LINQ+to+Twitter&ands=LINQ+Twitter&ors=LINQ+Twitter&nots=LINQ+Twitter&tag=linqtotwitter";
     string actual;
     actual = target.BuildURL(parameters);
     Assert.AreEqual(expected, actual);
 }
 public void NullParametersTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
     Dictionary<string, string> parameters = null;
     string actual;
     try
     {
         actual = target.BuildURL(parameters);
         Assert.Fail("Expected ArgumentException.");
     }
     catch (ArgumentException ae)
     {
         Assert.AreEqual<string>("Type", ae.ParamName);
     }
 }
 public void ProcessResultsTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>();
     XElement twitterResponse = XElement.Parse(m_testQueryResponse);
     IList actual = target.ProcessResults(twitterResponse);
     var result = actual.Cast<Search>().First();
     Assert.AreEqual(2, result.Entries.Count);
 }
        public void UrlEncodedQueryTest()
        {
            SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
            string expected = target.BaseUrl + "search.atom?q=Contains+Space";
            Dictionary<string, string> parameters =
                new Dictionary<string, string>
                {
                    { "Type", SearchType.Search.ToString() },
                    { "Query", "Contains Space" }
                };
            string actual = target.BuildURL(parameters);

            Assert.AreEqual(expected, actual);
        }
        public void BuildUrl_Requires_Query()
        {
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };
            var parameters =
                new Dictionary<string, string>
                {
                    { "Type", SearchType.Search.ToString() },
                    { "Query", null }
                };

            ArgumentException ex =
                L2TAssert.Throws<ArgumentNullException>(() =>
                    searchReqProc.BuildUrl(parameters));

            Assert.AreEqual("Query", ex.ParamName);
        }
        public void ProcessResults_Populates_Search_MetaData()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.NotNull(results);
            Assert.Single(results);
            Search search = results.Single();
            Assert.NotNull(search);
            SearchMetaData metaData = search.SearchMetaData;
            Assert.NotNull(metaData);
            Assert.Equal(0.046m, metaData.CompletedIn);
            Assert.Equal(281604225014824960ul, metaData.MaxID);
            Assert.Equal(5ul, metaData.SinceID);
            Assert.Equal(10, metaData.Count);
            Assert.Equal("Twitter", metaData.Query);
            Assert.Equal(
                "?max_id=281562053162979328&q=Twitter&geocode=37.781157%2C-122.398720%2C1mi&include_entities=1",
                metaData.NextResults);
            Assert.Equal(
                "?since_id=281604225014824960&q=Twitter&geocode=37.781157%2C-122.398720%2C1mi&include_entities=1",
                metaData.RefreshUrl);
        }
        public void ProcessResults_Populates_Entity_Users()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            List<UserMention> users = results.First().Statuses[0].Entities.UserMentions;
            Assert.NotNull(users);
            Assert.Equal(1, users.Count);
            UserMention firstUser = users.First();
            Assert.Equal("JoeMayo", firstUser.ScreenName);
            Assert.Equal("Joe Mayo", firstUser.Name);
            Assert.Equal(15411837ul, firstUser.Id);
            Assert.Equal(3, firstUser.Start);
            Assert.Equal(11, firstUser.End);
        }
        public void ProcessResults_Populates_Entity_Urls()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            List<UrlMention> urls = results.First().Statuses.First().Entities.UrlMentions;
            Assert.NotNull(urls);
            Assert.Equal(1, urls.Count);
            UrlMention firstUrl = urls.First();
            Assert.Equal("http://t.co/Cc85Yzpj", firstUrl.Url);
            Assert.Equal("http://bit.ly/PSOVso", firstUrl.ExpandedUrl);
            Assert.Equal("bit.ly/PSOVso", firstUrl.DisplayUrl);
            Assert.Equal(68, firstUrl.Start);
            Assert.Equal(88, firstUrl.End);
        }
        public void ProcessResults_Populates_Entity_Media()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            List<MediaMention> media = results.First().Statuses[0].Entities.MediaMentions;
            Assert.NotNull(media);
            Assert.Equal(1, media.Count);
            MediaMention firstMedia = media.First();
            Assert.Equal(155683816676134913ul, firstMedia.ID);
            Assert.Equal("http://p.twimg.com/AikZmz5CEAESBHD.jpg", firstMedia.MediaUrl);
            Assert.Equal("https://p.twimg.com/AikZmz5CEAESBHD.jpg", firstMedia.MediaUrlHttps);
            Assert.Equal("http://t.co/36MZIOyW", firstMedia.Url);
            Assert.Equal("pic.twitter.com/36MZIOyW", firstMedia.DisplayUrl);
            Assert.Equal("http://twitter.com/rschu/status/155683816671940609/photo/1", firstMedia.ExpandedUrl);
            Assert.Equal("photo", firstMedia.Type);
            Assert.NotNull(firstMedia.Sizes);
            Assert.Equal(5, firstMedia.Sizes.Count);
            PhotoSize firstSize = firstMedia.Sizes.First();
            Assert.Equal("orig", firstSize.Type);
            Assert.Equal(1161, firstSize.Width);
            Assert.Equal(925, firstSize.Height);
            Assert.Equal("fit", firstSize.Resize);
            Assert.Equal(59, firstMedia.Start);
            Assert.Equal(79, firstMedia.End);
        }
        public void ProcessResults_Populates_Entity_Hashtags()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            List<HashTagMention> hashes = results.First().Statuses[0].Entities.HashTagMentions;
            Assert.NotNull(hashes);
            Assert.Equal(3, hashes.Count);
            HashTagMention firstHash = hashes.First();
            Assert.Equal("twitterapi", firstHash.Tag);
            Assert.Equal(89, firstHash.Start);
            Assert.Equal(100, firstHash.End);
        }
        public void ProcessResults_Populates_CreatedAt()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.Equal(
                new DateTimeOffset(2012, 9, 6, 0, 10, 12, new TimeSpan(0, 0, 0)),
                results.First().Statuses.First().CreatedAt);
        }
        public void ProcessResults_Instantiates_Entities()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.NotNull(results.First().Statuses.First().Entities);
        }
        public void ProcessResults_Populates_Entity_Symbols()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            List<SymbolEntity> symbols = results.First().Statuses[0].Entities.SymbolEntities;
            Assert.IsNotNull(symbols);
            Assert.AreEqual(2, symbols.Count);
            SymbolEntity symbol = symbols.First();
            Assert.AreEqual("PEP", symbol.Text);
            Assert.AreEqual(114, symbol.Start);
            Assert.AreEqual(118, symbol.End);
        }
        public void ProcessResults_Populates_Source()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.Equal(@"<a href=""http://www.csharp-station.com/"" rel=""nofollow"">C# Station</a>", results.First().Statuses.First().Source);
        }
        public void ProcessResults_Populates_Status_MetaData()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.NotNull(results);
            Assert.Single(results);
            Search search = results.Single();
            Assert.NotNull(search);
            List<Status> statuses = search.Statuses;
            Assert.NotNull(statuses);
            Assert.NotEmpty(statuses);
            Status status = search.Statuses.First();
            Assert.NotNull(status);
            StatusMetaData metaData = status.MetaData;
            Assert.NotNull(metaData);
            Assert.Equal("recent", metaData.ResultType);
            Assert.Equal("en", metaData.IsoLanguageCode);
        }
        public void ProcessResults_Populates_Text()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.Equal("RT @JoeMayo: Blogged - Working with Timelines with LINQ to Twitter: http://t.co/Cc85Yzpj #twitterapi #linq #linq2twitter", results.First().Statuses.First().Text);
        }
 public void QueryTooLongTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
     string expected = target.BaseUrl + "search.atom?q=Contains+Space";
     Dictionary<string, string> parameters =
         new Dictionary<string, string>
         {
             { "Type", SearchType.Search.ToString() },
             { "Query", "x01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" }
         };
     string actual = target.BuildURL(parameters);
 }
        public void BuildUrl_Throws_When_Parameters_Null()
        {
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            ArgumentException ex =
                Assert.Throws<ArgumentException>(() =>
                {
                    searchReqProc.BuildUrl(null);
                });

            Assert.Equal("Type", ex.ParamName);
        }
 public void ProcessResultsNextTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>();
     XElement twitterResponse = XElement.Parse(m_testQueryResponse);
     IList actual = target.ProcessResults(twitterResponse);
     var result = actual.Cast<Search>().First();
     Assert.AreEqual("http://search.twitter.com/search.atom?lang=en&max_id=1600414821&page=2&q=LINQ+to+Twitter&rpp=2", result.Next);
 }
        public void BuildUrl_Encodes_Query()
        {
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };
            string expected = searchReqProc.BaseUrl + "tweets.json?q=Contains%20Space";
            var parameters =
                new Dictionary<string, string>
                {
                    { "Type", SearchType.Search.ToString() },
                    { "Query", "Contains Space" }
                };

            Request req = searchReqProc.BuildUrl(parameters);

            Assert.Equal(expected, req.FullUrl);
        }
        public void GetParametersTest()
        {
            SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>();
            Expression<Func<Search, bool>> expression =
                search =>
                    search.Type == SearchType.Search &&
                    search.GeoCode == "40.757929,-73.985506,25km" &&
                    search.SearchLanguage == "en" &&
                    search.Page == 1 &&
                    search.PageSize == 10 &&
                    search.Query == "LINQ to Twitter" &&
                    search.ShowUser == true &&
                    search.SinceID == 123 &&
                    search.MaxID == 200 &&
                    search.ResultType == ResultType.Popular &&
                    search.WordPhrase == "LINQ to Twitter" &&
                    search.WordAnd == "LINQ Twitter" &&
                    search.WordOr == "LINQ Twitter" &&
                    search.WordNot == "LINQ Twitter" &&
                    search.Hashtag == "linqtotwitter" &&
                    search.PersonFrom == "JoeMayo" &&
                    search.PersonTo == "JoeMayo" &&
                    search.PersonReference == "JoeMayo" &&
                    search.Attitude == Attitude.Positive &&
                    search.WithLinks == true &&
                    search.WithRetweets == true;
            LambdaExpression lambdaExpression = expression as LambdaExpression;

            var queryParams = target.GetParameters(lambdaExpression);

            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Type", ((int)SearchType.Search).ToString())));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("GeoCode", "40.757929,-73.985506,25km")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("SearchLanguage", "en")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Page", "1")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("PageSize", "10")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("Query", "LINQ to Twitter")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("ShowUser", "True")));
            Assert.IsTrue(
                queryParams.Contains(
                    new KeyValuePair<string, string>("SinceID", "123")));
            Assert.IsTrue(
               queryParams.Contains(
                   new KeyValuePair<string, string>("MaxID", "200")));
            Assert.IsTrue(
               queryParams.Contains(
                   new KeyValuePair<string, string>("ResultType", ((int)ResultType.Popular).ToString())));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("WordPhrase", "LINQ to Twitter")));
            Assert.IsTrue(
             queryParams.Contains(
                 new KeyValuePair<string, string>("WordAnd", "LINQ Twitter")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("WordOr", "LINQ Twitter")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("WordNot", "LINQ Twitter")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("Hashtag", "linqtotwitter")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("PersonFrom", "JoeMayo")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("PersonTo", "JoeMayo")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("PersonReference", "JoeMayo")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("Attitude", ((int)Attitude.Positive).ToString())));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("WithLinks", "True")));
            Assert.IsTrue(
              queryParams.Contains(
                  new KeyValuePair<string, string>("WithRetweets", "True")));
        }
        public void BuildUrl_Adds_True_IncludeEntities()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };
            var parameters =
                new Dictionary<string, string>
                {
                    { "Type", SearchType.Search.ToString() },
                    { "IncludeEntities", true.ToString(CultureInfo.InvariantCulture) }
                };
            const string Expected = "https://api.twitter.com/1.1/search/tweets.json?include_entities=true";

            Request req = searchProc.BuildUrl(parameters);

            Assert.Equal(Expected, req.FullUrl);
        }
        public void BuildUrl_Throws_With_Missing_Type_Parameter()
        {
            var searchReqProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };
            var parameters = new Dictionary<string, string> { };

            ArgumentException ex =
                Assert.Throws<ArgumentException>(() =>
                {
                    searchReqProc.BuildUrl(parameters);
                });

            Assert.Equal("Type", ex.ParamName);
        }
 public void BuildURLTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
     Dictionary<string, string> parameters =
         new Dictionary<string, string>
         {
             { "Type", SearchType.Search.ToString() },
             { "GeoCode", "40.757929,-73.985506,25km" },
             { "SearchLanguage", "en" },
             { "Page", "1" },
             { "PageSize", "10" },
             { "Query", "LINQ to Twitter" },
             { "ShowUser", "true" },
             { "SinceID", "1" },
             { "Since", "7/4/2010" },
             { "Until", "7/4/2011" },
             { "ResultType", ResultType.Popular.ToString()},
        };
     string expected = "http://search.twitter.com/search.atom?geocode=40.757929%2c-73.985506%2c25km&lang=en&page=1&rpp=10&q=LINQ+to+Twitter&show_user=true&since=2010-07-04&until=2011-07-04&since_id=1&result_type=Popular";
     string actual;
     actual = target.BuildURL(parameters);
     Assert.AreEqual(expected, actual);
 }
        public void ProcessResults_Creates_List_Of_Status()
        {
            var searchProc = new SearchRequestProcessor<Search> { BaseUrl = "https://api.twitter.com/1.1/search/" };

            List<Search> results = searchProc.ProcessResults(SearchJson);

            Assert.NotNull(results.First().Statuses);
            Assert.True(results.First().Statuses.Any());
        }
 public void BuildShowUserSetToFalseURLTest()
 {
     SearchRequestProcessor<Search> target = new SearchRequestProcessor<Search>() { BaseUrl = "http://search.twitter.com/" };
     Dictionary<string, string> parameters =
         new Dictionary<string, string>
         {
             { "Type", SearchType.Search.ToString() },
             { "ShowUser", false.ToString() },
         };
     string expected = "http://search.twitter.com/search.atom";
     string actual;
     actual = target.BuildURL(parameters);
     Assert.AreEqual(expected, actual);
 }