Ejemplo n.º 1
0
        public async Task Test_Router_Presents_Transition_Resolved_From_OnTransition()
        {
            var        viewModel = new TestViewModel();
            var        subject   = new Subject <TransitionEvent>();
            IPresenter presenter = Substitute.For <IPresenter>();

            Locator.CurrentMutable.Register(() => presenter, typeof(TestPresenterType));
            Locator.CurrentMutable.Register(() => viewModel, typeof(TestViewModel));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Navigate(),
                RouteActions.Present(typeof(TestPresenterType))
                            }
                        }
                    }
                }
            };

            Navigator.OnTransition.Returns(subject);
            await Router.InitAsync(initParams);

            Router.ShowAsync <TestViewModel, TestParams>();

            presenter.Received(1).PresentAsync(viewModel, null);
        }
Ejemplo n.º 2
0
        public async Task Test_ShowAsync_Creates_Presenter_If_Router_Actions_Specify_Present()
        {
            Func <TestPresenterType> presenterConstructor = Substitute.For <Func <TestPresenterType> >();

            presenterConstructor().Returns(new TestPresenterType());
            Locator.CurrentMutable.Register(() => new TestViewModel(), typeof(TestViewModel));
            Locator.CurrentMutable.Register(presenterConstructor, typeof(TestPresenterType));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Present(typeof(TestPresenterType))
                            }
                        }
                    }
                }
            };

            await Router.InitAsync(initParams);

            await Router.ShowAsync(typeof(TestViewModel), new TestParams());

            presenterConstructor.Received(1)();
        }
Ejemplo n.º 3
0
        public async Task Test_Router_Disposes_Of_Presenters_After_Transition()
        {
            IPresenter presenter  = Substitute.For <IPresenter>();
            var        disposable = new BooleanDisposable();

            presenter.PresentAsync(Arg.Any <object>(), Arg.Any <object>()).Returns(disposable);
            Locator.CurrentMutable.Register(() => new TestViewModel(), typeof(TestViewModel));
            Locator.CurrentMutable.Register(() => presenter, typeof(TestPresenterType));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Navigate(),
                RouteActions.Present(typeof(TestPresenterType))
                            }
                        }
                    }
                }
            };
            Transition trans = null;

            Navigator.PushAsync(Arg.Any <Transition>()).Returns(c =>
            {
                trans = c.Arg <Transition>();
                return(Task.FromResult(0));
            });
            Navigator.PopAsync().Returns(c => trans);
            await Router.InitAsync(initParams);

            await Router.ShowAsync <TestViewModel, TestParams>();

            await Router.ShowAsync <TestViewModel, TestParams>();

            disposable.IsDisposed.Should().BeFalse();

            await Router.BackAsync();

            disposable.IsDisposed.Should().BeTrue();
        }
Ejemplo n.º 4
0
        public async Task Test_ShowAsync_Calls_PresentAsync_On_Created_Presenter()
        {
            IPresenter presenter = Substitute.For <IPresenter>();

            Locator.CurrentMutable.Register(() => new TestViewModel(), typeof(TestViewModel));
            Locator.CurrentMutable.Register(() => presenter, typeof(TestPresenterType));
            var subject    = new Subject <Transition>();
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Present(typeof(TestPresenterType))
                            }
                        }
                    }
                }
            };

            Navigator.PushAsync(Arg.Any <Transition>()).Returns(ci =>
            {
                subject.OnNext(ci.Arg <Transition>());
                return(Task.FromResult(0));
            });

            await Router.InitAsync(initParams);

            await Router.ShowAsync(typeof(TestViewModel), new TestParams());

            presenter.Received(1).PresentAsync(Arg.Any <object>(), Arg.Any <object>());
        }
Ejemplo n.º 5
0
 public IRouteBuilder Present(Type presenterType)
 {
     actions.Add(RouteActions.Present(presenterType));
     return(this);
 }