public void SuccessfulSearchCausesListToBeBroadcast()
        {
            ClearAll();
            CreateMockNavigation();

            var twitterService = new Mock <ITwitterSearchProvider>();
            var searchText     = "To search for";
            Action <IEnumerable <Tweet> > storedSuccessAction = null;
            Action <Exception>            storedErrorAction   = null;

            twitterService.Setup(x => x.StartAsyncSearch(It.Is <string>(s => s == searchText), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()))
            .Callback((string s, Action <IEnumerable <Tweet> > suc, Action <Exception> err) =>
            {
                storedSuccessAction = suc;
                storedErrorAction   = err;
            });
            var viewModel = new TwitterViewModel(twitterService.Object);

            viewModel.Init(searchText);
            var list = new List <Tweet>()
            {
                new Tweet()
                {
                }
            };

            storedSuccessAction(list);
            Assert.IsNotNull(viewModel.Tweets);
            Assert.AreEqual(1, viewModel.Tweets.Count());
        }
Exemplo n.º 2
0
        public void TwitterSearch_Error_Callback_Clears_IsSearching()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                string search = null;
                Action <IEnumerable <Tweet> > success = null;
                Action <Exception>            error   = null;
                setup
                .Twitter
                .Setup(x => x.StartAsyncSearch(It.IsAny <string>(), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()))
                .Callback <string, Action <IEnumerable <Tweet> >, Action <Exception> >((s, s2, e) =>
                {
                    search  = s;
                    success = s2;
                    error   = e;
                });
                var viewModel = new TwitterViewModel("mySearchTerm");

                var calledChanges = new List <string>();
                viewModel.PropertyChanged += (s, a) => calledChanges.Add(a.PropertyName);

                error(new Exception("Test exception"));
                Assert.AreEqual(1, calledChanges.Count);
                CollectionAssert.Contains(calledChanges, "IsSearching");
                Assert.IsFalse(viewModel.IsSearching);
                Assert.IsNull(viewModel.Tweets);
            }
        }
Exemplo n.º 3
0
        public JsonResult GetCityTweets(string cityName)
        {
            TwitterViewModel model = new TwitterViewModel
            {
                ProfileName    = string.Empty,
                FollowerCount  = 0,
                FollowingCount = 0,
                TweetList      = new List <TweetViewModel>()
            };

            var searchParameter = new TweetSearchParameters("")
            {
                Lang = Language.English,
                //hard coding the geo location for newyork
                GeoCode = Geo.GenerateGeoCode(Geo.GenerateCoordinates(-74.006, 40.742), 1000, DistanceMeasure.Miles)
            };
            var tweets = Search.SearchTweets(searchParameter);



            foreach (var item in tweets.OrderByDescending(res => res.CreatedAt))
            {
                model.TweetList.Add(new TweetViewModel
                {
                    TweetText = item.Text,
                    CreatedAt = String.Format("{0:d/M/yyyy HH:mm:ss}", item.CreatedAt),
                    CreatedBy = item.CreatedBy.Id.ToString(),
                    HashTag   = item.Hashtags.Any() ? item.Hashtags[0].Text : ""
                });
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public void Init()
        {
            var tweets = new ObservableCollection <Tweet>()
            {
                new Tweet
                {
                    created_at = "1/1/2012",
                    entities   = new TwitterUserEntities
                    {
                        media = new List <TwitterUserMedia>()
                        {
                            new TwitterUserMedia
                            {
                                media_url = "http://www.google.com/google.jpg"
                            },
                        },
                    },

                    text = "Tweet from RealTimeWWII",
                    user = new TwitterUser
                    {
                        screen_name       = "RealTimeWWII",
                        name              = "Real Tweets From WWII",
                        profile_image_url = "http://www.twitter.com/twitter.jpg"
                    },
                }
            };

            _mock = MockRepository.GenerateMock <ITwitterService>();
            _mock.Stub(s => s.GetNextTwentyTweetsFromUserId("RealTimeWWII")).Return(tweets);

            _tvm = new TwitterViewModel(_mock);
        }
Exemplo n.º 5
0
        public TwitterPage()
        {
            InitializeComponent();

            BindingContext = new TwitterViewModel();


            listView.ItemTapped += async(sender, args) =>
            {
                if (listView.SelectedItem == null)
                {
                    return;
                }


                var tweet = listView.SelectedItem as Tweet;

                //try to launch twitter or tweetbot app, else launch browser
                var launch = DependencyService.Get <ILaunchTwitter>();
                if (launch == null || !launch.OpenStatus(tweet.StatusID.ToString()))
                {
                    await Browser.OpenAsync("http://twitter.com/shanselman/status/" + tweet.StatusID);
                }

                listView.SelectedItem = null;
            };
        }
Exemplo n.º 6
0
        public void TwitterSearch_Success_Callback_Sets_Tweets()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                string search = null;
                Action <IEnumerable <Tweet> > success = null;
                Action <Exception>            error   = null;
                setup
                .Twitter
                .Setup(x => x.StartAsyncSearch(It.IsAny <string>(), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()))
                .Callback <string, Action <IEnumerable <Tweet> >, Action <Exception> >((s, s2, e) =>
                {
                    search  = s;
                    success = s2;
                    error   = e;
                });
                var viewModel = new TwitterViewModel("mySearchTerm");

                var calledChanges = new List <string>();
                viewModel.PropertyChanged += (s, a) => calledChanges.Add(a.PropertyName);


                var result = new[] { new Tweet(), new Tweet() };
                success(result);
                Assert.AreEqual(2, calledChanges.Count);
                CollectionAssert.Contains(calledChanges, "Tweets");

                Assert.AreEqual(2, viewModel.Tweets.Count());
                CollectionAssert.Contains(viewModel.Tweets.ToList(), result[0]);
                CollectionAssert.Contains(viewModel.Tweets.ToList(), result[1]);
            }
        }
Exemplo n.º 7
0
        public void TwitterSearch_Constructor_Requests_A_TwitterSearch()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                string search = null;
                Action <IEnumerable <Tweet> > success = null;
                Action <Exception>            error   = null;
                setup
                .Twitter
                .Setup(x => x.StartAsyncSearch(It.IsAny <string>(), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()))
                .Callback <string, Action <IEnumerable <Tweet> >, Action <Exception> >((s, s2, e) =>
                {
                    search  = s;
                    success = s2;
                    error   = e;
                });
                var viewModel = new TwitterViewModel("mySearchTerm");
                setup
                .Twitter
                .Verify(x => x.StartAsyncSearch(It.IsAny <string>(), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()), Times.Once());
                Assert.AreEqual("mySearchTerm", search);
                Assert.IsNotNull(success);
                Assert.IsNotNull(error);
            }
        }
Exemplo n.º 8
0
        public TweetsView(string ticker)
        {
            InitializeComponent();
            var viewModel = new TwitterViewModel(ticker);

            BindingContext = viewModel;
            viewModel.LoadTweetsCommand();

            TweetList.ItemSelected += (sender, args) =>
            {
                if (TweetList.SelectedItem == null)
                {
                    return;
                }

                Navigation.PushAsync(new ContentPage
                {
                    Content = new WebView
                    {
                        Source = new UrlWebViewSource
                        {
                            Url = ((Tweet)TweetList.SelectedItem).Url
                        }
                    }
                });

                TweetList.SelectedItem = null;
            };
        }
Exemplo n.º 9
0
        public TwitterPage()
        {
            InitializeComponent();

            ListTweets.RowHeight = Device.OnPlatform <int>(110, 110, 150);
            this.BindingContext  = viewModel = new TwitterViewModel();
        }
Exemplo n.º 10
0
 public HomeViewModel()
 {
     Welcome   = new WelcomeViewModel();
     Sessions  = new SessionsViewModel();
     Twitter   = new TwitterViewModel();
     Favorites = new FavoritesViewModel();
 }
Exemplo n.º 11
0
        public void SuccessfulSearchCausesChangeInIsSearching()
        {
            CreateMockNavigation();
            var twitterService = new Mock <ITwitterSearchProvider>();

            Ioc.RegisterServiceInstance <ITwitterSearchProvider>(twitterService.Object);
            var searchText = "To search for";
            Action <IEnumerable <Tweet> > storedSuccessAction = null;
            Action <Exception>            storedErrorAction   = null;

            twitterService.Setup(x => x.StartAsyncSearch(It.Is <string>(s => s == searchText), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()))
            .Callback((string s, Action <IEnumerable <Tweet> > suc, Action <Exception> err) =>
            {
                storedSuccessAction = suc;
                storedErrorAction   = err;
            });
            var viewModel = new TwitterViewModel(searchText);
            var list      = new List <Tweet>()
            {
                new Tweet()
                {
                }
            };

            storedSuccessAction(list);
            Assert.IsFalse(viewModel.IsSearching);
        }
Exemplo n.º 12
0
        public void GetNextTwentyTweetsFromUserIdShouldReturnObservableContainerThatContainsInvalidTwitterID()
        {
            var tv = new TwitterViewModel();

            tv.UpdateTweets("____INVALID");

            Assert.IsTrue(tv.Tweets.First().text == "Invalid TwitterID.");
        }
Exemplo n.º 13
0
        public void ShouldGetNextTwentyTweetsFromUserId()
        {
            var tv = new TwitterViewModel();

            tv.UpdateTweets("RealTimeWWII");

            Assert.IsTrue(tv.Tweets.Count == 20);
        }
Exemplo n.º 14
0
        public TweetsView(string ticker)
        {
            InitializeComponent();
            viewModel = new TwitterViewModel(ticker);

            // Assign the async function here, so we can await correctly
            InitializeTweets = InitializeAsync();
        }
Exemplo n.º 15
0
        public TwitterWindow(bool auth)
        {
            InitializeComponent();
            AuthKaijoButton.IsEnabled = auth;

            TwitterViewModel vm = new TwitterViewModel();

            this.DataContext = vm;
        }
Exemplo n.º 16
0
        public TwitterList()
        {
            this.InitializeComponent();
            _navigationHelper = new NavigationHelper(this);

            TwitterModel = new TwitterViewModel();

            SizeChanged += OnSizeChanged;
        }
Exemplo n.º 17
0
        public TwitterList()
        {
            this.InitializeComponent();
            _navigationHelper = new NavigationHelper(this);

            TwitterModel = new TwitterViewModel();

            SizeChanged += OnSizeChanged;
        }
Exemplo n.º 18
0
        public TwitterPage()
        {
            this.InitializeComponent();
            _navigationHelper = new NavigationHelper(this);

            TwitterModel = new TwitterViewModel();
            DataContext  = this;

            SizeChanged += OnSizeChanged;
        }
Exemplo n.º 19
0
        public void TwitterSearch_Constructor_Sets_IsSearching_True()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                var viewModel = new TwitterViewModel("mySearchTerm");
                Assert.IsTrue(viewModel.IsSearching);
            }
        }
Exemplo n.º 20
0
        public JsonResult GetUserDetails(string id, string key, string geo)
        {
            string           message = "";
            TwitterViewModel model   = new TwitterViewModel {
                TweetList = new List <TweetViewModel>()
            };

            if (!string.IsNullOrEmpty(id))
            {
                var user = Tweetinvi.User.GetUserFromScreenName(id);

                model.ProfileName    = user.Name;
                model.FollowerCount  = user.FollowersCount;
                model.FollowingCount = user.FriendsCount;
            }

            string query = string.IsNullOrEmpty(key) ? "" : key + " ";

            query += string.IsNullOrEmpty(id) ? "" : "from:" + id;



            var searchParameter = new TweetSearchParameters("")
            {
                Lang = Language.English,

                SearchQuery = query.TrimEnd()
            };

            if (!string.IsNullOrEmpty(geo))
            {
                string[] result = geo.Split(',');
                if (!string.IsNullOrEmpty(result[0].Trim()))
                {
                    searchParameter.GeoCode = new GeoCode(double.Parse(result[1].TrimEnd()), double.Parse(result[0].TrimEnd()), double.Parse(result[2].TrimEnd()), DistanceMeasure.Miles);
                }
            }

            var tweets = Search.SearchTweets(searchParameter);

            foreach (var item in tweets.OrderByDescending(res => res.CreatedAt))
            {
                model.TweetList.Add(new TweetViewModel
                {
                    TweetText = item.Text,
                    CreatedAt = String.Format("{0:d/M/yyyy HH:mm:ss}", item.CreatedAt),
                    CreatedBy = item.CreatedBy.Name,
                    HashTag   = item.Hashtags.Any() ? item.Hashtags[0].Text : ""
                });
            }



            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 21
0
        async void HandleMessage(IMessageEvent message)
        {
            try
            {
                Android.Util.Log.Info("WearIntegration", "Received Message");
                var client = new GoogleApiClientBuilder(this)
                             .AddApi(WearableClass.Api)
                             .Build();

                var result = client.BlockingConnect(30, Java.Util.Concurrent.TimeUnit.Seconds);
                if (!result.IsSuccess)
                {
                    return;
                }

                var path = message.Path;

                try
                {
                    if (path.StartsWith(TweetsPath))
                    {
                        var viewModel = new TwitterViewModel();

                        await viewModel.ExecuteLoadTweetsCommand();

                        var request = PutDataMapRequest.Create(TweetsPath + "/Answer");
                        var map     = request.DataMap;

                        var tweetMap = new List <DataMap>();
                        foreach (var tweet in viewModel.Tweets)
                        {
                            var itemMap = new DataMap();

                            itemMap.PutLong("CreatedAt", tweet.CreatedAt.Ticks);
                            itemMap.PutString("ScreenName", tweet.ScreenName);
                            itemMap.PutString("Text", tweet.Text);

                            tweetMap.Add(itemMap);
                        }
                        map.PutDataMapArrayList("Tweets", tweetMap);
                        map.PutLong("UpdatedAt", DateTime.UtcNow.Ticks);

                        WearableClass.DataApi.PutDataItem(client, request.AsPutDataRequest());
                    }
                }
                finally
                {
                    client.Disconnect();
                }
            }
            catch (Exception e)
            {
                Android.Util.Log.Error("WearIntegration", e.ToString());
            }
        }
Exemplo n.º 22
0
        // GET: Twitter Feeds
        public ActionResult TwitterFeed()
        {
            var twitterSettings = Sitecore.Context.Database.GetItem("/sitecore/content/Home/Twitter Settings");

            var twitterViewModel = new TwitterViewModel()
            {
                Tweets = GetTweets(twitterSettings)
            };

            return(View(twitterViewModel));
        }
Exemplo n.º 23
0
        public void ConstructionStartsSearch()
        {
            var twitterService = new Mock <ITwitterSearchProvider>();

            Ioc.RegisterServiceInstance <ITwitterSearchProvider>(twitterService.Object);
            var searchText = "To search for";
            var viewModel  = new TwitterViewModel(searchText);

            Assert.IsTrue(viewModel.IsSearching);
            twitterService.Verify(x => x.StartAsyncSearch(It.Is <string>(s => s == searchText), It.IsAny <Action <IEnumerable <Tweet> > >(), It.IsAny <Action <Exception> >()), Times.Once());
        }
Exemplo n.º 24
0
        public TwitterPage()
        {
            this.InitializeComponent();
            _navigationHelper = new NavigationHelper(this);

            TwitterModel = new TwitterViewModel();
            DataContext  = this;

            ApplicationView.GetForCurrentView().
            SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
        }
Exemplo n.º 25
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            viewModel = new TwitterViewModel();

            Search.EditingEnded      += OnLoadPressed;
            LoadTweets.Activated     += OnLoadPressed;
            TweetTable.WeakDataSource = this;
            TweetTable.WeakDelegate   = this;
            TweetTable.HeaderView     = null;
        }
Exemplo n.º 26
0
        public TwitterPage()
        {
            InitializeComponent();
            VM      = BindingContext as TwitterViewModel;
            service = new TwitterService(Key, Secret, AccessToken, AccessTokenSecret);
            TwitterStatus CurrentTweet = SendTweet("Hello World");

            TweetsToDelete.Add(CurrentTweet);
            tweets = GetTweetsFromHome();
            foreach (TwitterStatus tweet in tweets)
            {
                VM.TweetsPickerSource.Add(tweet.Text);
            }
        }
Exemplo n.º 27
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.list = new List <TweetInfo>();
            TwitterViewModel viewmodel = new TwitterViewModel();

            list = viewmodel.Get(textbox.Text);
            List <KeyValuePair <string, string> > temp = new List <KeyValuePair <string, string> >();

            foreach (var item in list)
            {
                temp.Add(new KeyValuePair <string, string>(item.Username, item.Tweet));
            }

            listbox.ItemsSource = temp;
        }
Exemplo n.º 28
0
        public Twitter()
        {
            InitializeComponent();
            BindingContext = new TwitterViewModel();

            var htmlSource = new HtmlWebViewSource();

            //htmlSource.Html = @"<html><body>
            //                          <h1>Twitter Feed</h1>
            //                          <p>ILCE</p>
            //                          <a class='twitter - timeline' href='https://mobile.twitter.com/ILCEedu'>Twitter ILCE</a>
            //                    <script async src = 'https://platform.twitter.com/widgets.js' charset = 'utf-8' ></ script >
            //                          </body></html>";
            //TwitterWebView.Source = htmlSource;
            TwitterWebView.Source = "https://mobile.twitter.com/ILCEedu";
        }
Exemplo n.º 29
0
        public TwitterPage()
        {
            InitializeComponent();

            BindingContext = new TwitterViewModel();


            listView.ItemTapped += (sender, args) =>
            {
                if (listView.SelectedItem == null)
                    return;
                var tweet = listView.SelectedItem as Tweet;
                this.Navigation.PushAsync(new WebsiteView("http://m.twitter.com/shanselman/status/" + tweet.StatusID, tweet.Date));
                listView.SelectedItem = null;
            };
        }
        public IActionResult GetHomeTimeline()
        {
            TwitterViewModel homeView = new TwitterViewModel();

            try
            {
                if (config.TwitterConfiguration.Access_Token == null)
                {
                    throw new Tweetinvi.Exceptions.TwitterNullCredentialsException();
                }
                if (config.TwitterConfiguration.Access_Secret == null)
                {
                    throw new Tweetinvi.Exceptions.TwitterNullCredentialsException();
                }

                var userCredentials = Auth.CreateCredentials(
                    config.TwitterConfiguration.Consumer_Key
                    , config.TwitterConfiguration.Consumer_Secret
                    , config.TwitterConfiguration.Access_Token
                    , config.TwitterConfiguration.Access_Secret);

                var authenticatedUser = Tweetinvi.User.GetAuthenticatedUser(userCredentials);

                IEnumerable <ITweet> twitterFeed = authenticatedUser.GetHomeTimeline(config.TweetFeedLimit);

                List <TweetItem> tweets = new List <TweetItem>();
                foreach (ITweet tweet in twitterFeed)
                {
                    TweetItem tweetItem = new TweetItem();

                    tweetItem.Url = tweet.Url;
                    tweets.Add(tweetItem);
                }

                homeView.HomeTimelineTweets = tweets;
            }
            catch (Tweetinvi.Exceptions.TwitterNullCredentialsException ex)
            {
                return(RedirectToAction("AuthenticateTwitter"));
            }
            catch (Exception ex)
            {
            }

            return(View("Views/Twitter/HomeTimeline.cshtml", homeView));
        }
Exemplo n.º 31
0
        public TwitterPage()
        {
            InitializeComponent();

            BindingContext = new TwitterViewModel();


            listView.ItemTapped += (sender, args) =>
            {
                if (listView.SelectedItem == null)
                {
                    return;
                }
                var tweet = listView.SelectedItem as Tweet;
                this.Navigation.PushAsync(new WebsiteView("http://m.twitter.com/shanselman/status/" + tweet.StatusID, tweet.Date));
                listView.SelectedItem = null;
            };
        }
Exemplo n.º 32
0
        public void Setup()
        {
            _repo = MockRepository.GenerateMock <ITwitterRepository>();

            // Stub list to return when GetAll or GetPredicate is called
            var list = new List <TweetFromUser>()
            {
                new TweetFromUser
                {
                    TweetText = "This is my tweet",
                    User      = new User
                    {
                        Name = "mark"
                    }
                },
                new TweetFromUser
                {
                    TweetText = "This is Tom's tweet"
                    , User    = new User
                    {
                        Name = "Tom"
                    }
                },
                new TweetFromUser
                {
                    TweetText = "This is another tweet"
                    , User    = new User
                    {
                        Name = "mark"
                    }
                }
            };

            _repo.Stub(d => d.GetAll()).Return(list);

            // when they use UserName == "mark"
            //  _repo.Stub(d => d.GetTweetsByScreenName("mark")).Return(list.Where(d => d.User.Name == "mark"));

            _vm = new TwitterViewModel(_repo);
        }
Exemplo n.º 33
0
 public TwitterSettingsViewModel(TwitterViewModel viewModel)
 {
     SearchStringIsNotNull();
     ViewModel = viewModel;
     Search = new DelegateCommand {CanExecuteDelegate = CanSearchOrSave};
     Save.CanExecuteDelegate = CanSearchOrSave;
     ReloadSettings.CanExecuteDelegate = CanReloadSettings;
 }
Exemplo n.º 34
0
            public void Setup()
            {
                _guid = Guid.NewGuid();

                _timerMock = new Mock<ITimer>();
                _progressbarMock = new Mock<IProgressbar>();
                CreateTweetFetcherMock(MakeTwitterSearchResult(20));
                defaultConfiguration = TwitterController.GetDefaultConfiguration();
                _twitterViewModel = new TwitterViewModel();
                _twitterSettingsViewModel = new TwitterSettingsViewModel(_twitterViewModel);
                CreateController();
                Before();
            }
Exemplo n.º 35
0
 public void Setup()
 {
     _twitterViewModel = new TwitterViewModel();
 }