Esempio n. 1
0
        public async void GetItems()
        {
            string consumerKey = "YourConsumerKey";
            string consumerSecret = "YourConsumerSecret";
            string accessToken = "YourAccessToken";
            string accessTokenSecret = "YourAccessTokenSecret";
            string twitterQueryParam = "WindowsAppStudio";
            TwitterQueryType queryType = TwitterQueryType.Search;
            int maxRecordsParam = 20;

            Items.Clear();

            _twitterDataProvider = new TwitterDataProvider(new TwitterOAuthTokens
            {
                AccessToken = accessToken,
                AccessTokenSecret = accessTokenSecret,
                ConsumerKey = consumerKey,
                ConsumerSecret = consumerSecret
            });

            var config = new TwitterDataConfig
            {
                Query = twitterQueryParam,
                QueryType = queryType
            };          

            var items = await _twitterDataProvider.LoadDataAsync(config, maxRecordsParam);
            foreach (var item in items)
            {
                Items.Add(item);
            }
        }
Esempio n. 2
0
        public async Task TestRevokedOAuth()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };

            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterRevokedKeys);

            await ExceptionsAssert.ThrowsAsync<OAuthKeysRevokedException>(async () => await dataProvider.LoadDataAsync(config));
        }
Esempio n. 3
0
        public async Task TestHomeTimeLine()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.Home
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            IEnumerable<TwitterSchema> result = await dataProvider.LoadDataAsync(config);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
Esempio n. 4
0
        public async Task TestInvalidOAuth()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };

            var tokens = new TwitterOAuthTokens
            {
                ConsumerKey = "INVALID",
                ConsumerSecret = "INVALID",
                AccessToken = "INVALID",
                AccessTokenSecret = "INVALID"
            };

            var dataProvider = new TwitterDataProvider(tokens);

            await ExceptionsAssert.ThrowsAsync<OAuthKeysRevokedException>(async () => await dataProvider.LoadDataAsync(config));
        }
Esempio n. 5
0
        public async Task TestEmptyOAuth()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };
            var dataProvider = new TwitterDataProvider(new TwitterOAuthTokens());

            OAuthKeysNotPresentException exception = await ExceptionsAssert.ThrowsAsync<OAuthKeysNotPresentException>(async () => await dataProvider.LoadDataAsync(config));
            Assert.IsTrue(exception.Message.Contains("ConsumerKey"));
        }
Esempio n. 6
0
 public async Task LoadMoreDataInvalidOperationTwitterSearch()
 {
     var config = new TwitterDataConfig
     {
         QueryType = TwitterQueryType.Search,
         Query = "lumia"
     };
     var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
     InvalidOperationException exception = await ExceptionsAssert.ThrowsAsync<InvalidOperationException>(async () => await dataProvider.LoadMoreDataAsync());
 }
Esempio n. 7
0
        public async Task LoadPaginationTwitterSearch()
        {

            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.Search,
                Query = "microsoft"
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            await dataProvider.LoadDataAsync(config, 2);

            Assert.IsTrue(dataProvider.HasMoreItems, "HasMoreItems is false");

            IEnumerable <TwitterSchema> result = await dataProvider.LoadMoreDataAsync();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any(), "There aren't any elements");
        }
Esempio n. 8
0
        public async Task LoadPaginationTwitterUserTimeLine()
        {

            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            await dataProvider.LoadDataAsync(config, 5);

            Assert.IsTrue(dataProvider.HasMoreItems);

            IEnumerable<TwitterSchema> result = await dataProvider.LoadMoreDataAsync();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
Esempio n. 9
0
        public async Task TestMaxRecordsSearch()
        {
            int maxRecords = 70;
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.Search,
                Query = "microsoft"
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            IEnumerable<TwitterSchema> result = await dataProvider.LoadDataAsync(config, maxRecords);

            Assert.IsTrue(result.Count() > 15, $"There are {result.Count()} elements");
        }
Esempio n. 10
0
        public async Task TestMaxRecordsUserTimeLine()
        {
            int maxRecords = 70;
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            IEnumerable<TwitterSchema> result = await dataProvider.LoadDataAsync(config, maxRecords);

            Assert.AreEqual(maxRecords, result.Count());

            Assert.IsTrue(result.Count() > 15, $"There are {result.Count()} elements");
        }
Esempio n. 11
0
        public async Task TestMaxRecordsUserTimeLine_Min()
        {
            int maxRecords = 1;
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };
            var dataProvider = new TwitterDataProvider(OAuthKeys.TwitterValidKeys);
            IEnumerable<TwitterSchema> result = await dataProvider.LoadDataAsync(config, maxRecords);

            Assert.IsTrue(result.Count() <= maxRecords);
        }
Esempio n. 12
0
        public async Task TestNullOAuth()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User,
                Query = "lumia"
            };
            var dataProvider = new TwitterDataProvider(null);

            await ExceptionsAssert.ThrowsAsync<ConfigParameterNullException>(async () => await dataProvider.LoadDataAsync(config));
        }
Esempio n. 13
0
        public async Task TestNullQuery()
        {
            var config = new TwitterDataConfig
            {
                QueryType = TwitterQueryType.User
            };
            var dataProvider = new TwitterDataProvider(new TwitterOAuthTokens());

            ConfigParameterNullException exception = await ExceptionsAssert.ThrowsAsync<ConfigParameterNullException>(async () => await dataProvider.LoadDataAsync(config));
            Assert.IsTrue(exception.Message.Contains("Query"));
        }
Esempio n. 14
0
        private async void Request()
        {
            try
            {
                IsBusy = true;
                HasErrors = false;
                NoItems = false;
                DataProviderRawData = string.Empty;
                Items.Clear();

                var config = new TwitterDataConfig
                {
                    Query = TwitterQueryParam,
                    QueryType = TwitterQueryTypeSelectedItem
                };                

                var items = await twitterDataProvider.LoadDataAsync(config, MaxRecordsParam);

                NoItems = !items.Any();

                foreach (var item in items)
                {
                    Items.Add(item);
                }
               
                var rawParser = new RawParser();
                var rawData = await rawDataProvider.LoadDataAsync(config, MaxRecordsParam, rawParser);
                DataProviderRawData = rawData.FirstOrDefault()?.Raw;
            }
            catch (Exception ex)
            {
                DataProviderRawData += ex.Message;
                DataProviderRawData += ex.StackTrace;
                HasErrors = true;
            }
            finally
            {
                IsBusy = false;
            }
        }