Пример #1
0
        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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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());
 }
Пример #4
0
        public void TwitterSearch_Constructor_Sets_IsSearching_True()
        {
            using (var setup = new MockSetup())
            {
                setup.Initialize();

                var viewModel = new TwitterViewModel("mySearchTerm");
                Assert.IsTrue(viewModel.IsSearching);
            }
        }
Пример #5
0
 public void ErrorredSearchCausesChangeInIsSearching()
 {
     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 exception = new Exception("Just for fun");
     storedErrorAction(exception);
     Assert.IsFalse(viewModel.IsSearching);
 }
Пример #6
0
 public void SuccessfulSearchCausesListToBeBroadcast()
 {
     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.IsNotNull(viewModel.Tweets);
     Assert.AreEqual(1, viewModel.Tweets.Count());
 }
        public void SuccessfulSearchCausesChangeInIsSearching()
        {
            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.IsFalse(viewModel.IsSearching);
        }