Пример #1
0
        public ActionResult Index(TwitterSearch model)
        {
            //search hashtag on twitter
            if (!string.IsNullOrWhiteSpace(model.HashTag))
            {
                var index = new RAMDirectory();
                SessionHelper.SetIndex(index);
                TwitterFlow flow         = new TwitterFlow(SessionHelper.GetIndex());
                var         searchResult = flow.SearchHashTagOnTwitter(model.HashTag);
                //for local testing only!
                //var searchResult = flow.SearchHashTagOnTwitter();
                model.TwitterResult = searchResult;
                flow.IndexSearchResult(searchResult);
                model.HashTag = null;
            }

            //filter search result
            if (!string.IsNullOrWhiteSpace(model.Filter) && SessionHelper.GetIndex() != null && string.IsNullOrWhiteSpace(model.HashTag))
            {
                TwitterFlow flow         = new TwitterFlow(SessionHelper.GetIndex());
                var         filterResult = flow.FilterSearchResult(model.Filter);
                model.TwitterResult = filterResult;
                model.Filter        = null;
            }
            return(View(model));
        }
        public void TestFilterSearchResult()
        {
            // Arrange
            HomeController controller = new HomeController();

            //prepare mocked index
            TwitterFlow flow         = new TwitterFlow(SessionHelper.GetIndex());
            var         searchResult = flow.SearchHashTagOnTwitter();

            flow.IndexSearchResult(searchResult);

            // Act
            var model = new TwitterSearch
            {
                Filter = "tazminat"
            };
            ViewResult result = controller.Index(model) as ViewResult;

            // Assert
            Assert.AreEqual(2, (result.Model as TwitterSearch).TwitterResult.Count);
        }