public void TwitterSearch_Success_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);


                var result = new [] { new Tweet(), new Tweet() };
                success(result);
                Assert.AreEqual(2, calledChanges.Count);
                CollectionAssert.Contains(calledChanges, "IsSearching");
                Assert.IsFalse(viewModel.IsSearching);
            }
        }
        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);
            }
        }
        public void PickRandom_Changes_SearchText()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                var viewModel = new HomeViewModel();
                Assert.IsNotNull(viewModel.SearchText);
                var calledProperties = new List<string>();
                viewModel.PropertyChanged += (sender, args) => calledProperties.Add(args.PropertyName);
                Assert.AreEqual(0, calledProperties.Count);
                
                var existingSearchText = viewModel.SearchText;
                viewModel.PickRandomCommand.Execute();
                Assert.AreEqual(1, calledProperties.Count);
                Assert.AreEqual("SearchText", calledProperties[0]);
                Assert.AreNotEqual(existingSearchText, viewModel.SearchText);

                existingSearchText = viewModel.SearchText;
                viewModel.PickRandomCommand.Execute();
                Assert.AreEqual(2, calledProperties.Count);
                Assert.AreEqual("SearchText", calledProperties[0]);
                Assert.AreEqual("SearchText", calledProperties[1]);
                Assert.AreNotEqual(existingSearchText, viewModel.SearchText);
            }
        }
        public void TwitterSearch_Constructor_Sets_IsSearching_True()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                var viewModel = new TwitterViewModel("mySearchTerm");
                Assert.IsTrue(viewModel.IsSearching);
            }
        }
        public void User_Can_Change_SearchText()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                var viewModel = new HomeViewModel();
                Assert.IsNotNull(viewModel.SearchText);
                viewModel.SearchText = "MyTestString";
                Assert.AreEqual("MyTestString", viewModel.SearchText);
            }
        }
        public void SearchCommand_Calls_RequestNavigate()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();
                var requests = new List<MvxShowViewModelRequest>();
                setup.Dispatcher
                    .Setup(x => x.RequestNavigate(It.IsAny<MvxShowViewModelRequest>()))
                    .Callback<MvxShowViewModelRequest>((request) => requests.Add(request));

                var viewModel = new HomeViewModel();
                viewModel.SearchText = "MyTestValue";
                viewModel.SearchCommand.Execute();

                setup.Dispatcher
                    .Verify(x => x.RequestNavigate(It.IsAny<MvxShowViewModelRequest>()), Times.Once());
                Assert.AreEqual(1, requests.Count);
                Assert.AreEqual(typeof(TwitterViewModel), requests[0].ViewModelType);
                Assert.AreEqual(false, requests[0].ClearTop);
                Assert.AreEqual(MvxRequestedBy.UserAction, requests[0].RequestedBy);
                Assert.AreEqual(1, requests[0].ParameterValues.Count);
                Assert.AreEqual("MyTestValue", requests[0].ParameterValues["searchTerm"]);
            }
        }