Example #1
0
        static async Task LoadTweets(string tweetServiceUrl, string resultFileName, DateTime startDate, DateTime endDate)
        {
            TweetService        service  = new TweetService(tweetServiceUrl);
            TweetLoader         loader   = new TweetLoader(service);
            TweetLoaderResponse response = await loader.LoadTweetsByDate(startDate, endDate).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(response.ErrorMessage))
            {
                Console.WriteLine("Error while loading tweets: " + response.ErrorMessage);
            }
            else
            {
                Console.WriteLine("Loaded tweets count: " + response.Tweets.Count);
            }
            if (!string.IsNullOrEmpty(resultFileName) && response.Tweets != null)
            {
                try
                {
                    loader.SaveToFile(response.Tweets, resultFileName);
                    Console.WriteLine("Saved tweets to: " + resultFileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while saving tweets: " + ex.Message);
                }
            }
        }
Example #2
0
        public void CheckLoader()
        {
            TestTweetService testService = new TestTweetService("Mock\\testData.txt");
            TweetLoader      loader      = new TweetLoader(testService);
            DateTime         startDate   = new DateTime(2016, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            DateTime         endDate     = new DateTime(2018, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddTicks(-1);
            var response = loader.LoadTweetsByDate(startDate, endDate).GetAwaiter().GetResult();

            Assert.IsTrue(string.IsNullOrEmpty(response.ErrorMessage));
            Assert.IsTrue(response.Tweets.Count == testService.TotalTweetCount);
        }
Example #3
0
        public async Task <IActionResult> Search(SearchViewModel model)
        {
            // test project, so no datetime binders. we assume that incoming dates are treated as UTC dates
            model.StartDate = DateTime.SpecifyKind(model.StartDate, DateTimeKind.Utc);
            model.EndDate   = DateTime.SpecifyKind(model.EndDate, DateTimeKind.Utc);
            var response = await _loader.LoadTweetsByDate(model.StartDate, model.EndDate);

            model.Tweets       = response.Tweets;
            model.ErrorMessage = response.ErrorMessage;

            if (Request.IsAjaxRequest())
            {
                return(View("_SearchPartial", model));
            }
            else
            {
                return(View(model));
            }
        }