Exemple #1
0
        public void Setup()
        {
            _scheduler = new TestScheduler();

            var routingState = new RoutingState();
            var screenMock   = new Mock <IScreen>()
            {
                DefaultValue = DefaultValue.Mock
            };

            screenMock.SetupGet(x => x.Router).Returns(routingState);
            _screen = screenMock.Object;

            _movieService = new Mock <IMovieService>()
            {
                DefaultValue = DefaultValue.Mock
            };
            _movieService.Setup(x => x.LoadUpcomingMovies(It.Is <int>(y => y >= 0 && y < 100))).Returns(() => Observable.Return(Unit.Default));
            _movieService.Setup(x => x.LoadUpcomingMovies(It.Is <int>(y => y >= 100))).Returns(() => throw new Exception("Boom!"));

            var movies = new List <Movie>();

            for (int i = 0; i < 20; i++)
            {
                movies.Add(new Movie
                {
                    Id          = i,
                    Overview    = $"Overview {i}",
                    PosterBig   = "PosterPath/",
                    PosterSmall = "PosterPath/",
                    ReleaseDate = DateTime.Now,
                    Title       = $"Title {i}"
                });
            }

            _moviesSourceCache = new SourceCache <Movie, int>(x => x.Id);
            _moviesSourceCache.AddOrUpdate(movies);
            _movieService.Setup(x => x.UpcomingMovies).Returns(_moviesSourceCache);

            _target = new UpcomingMoviesListViewModel(_scheduler, _scheduler, _movieService.Object, _screen);

            _alertOutput = null;
            _target.ShowAlert.RegisterHandler(handler =>
            {
                _alertOutput = handler.Input;
                handler.SetOutput(Unit.Default);
            });

            _screen.Router.NavigateAndReset.Execute(_target);
        }
 public UpcomingMoviesListPage()
 {
     InitializeComponent();
     BindingContext = new UpcomingMoviesListViewModel(this);
 }