예제 #1
0
        public async Task Test_NavigateBackWhileAction_Causes_Rotuer_To_Navigate_Backwards_While_The_Func_Is_True()
        {
            Resolver.Register(() => new TestViewModel(), typeof(TestViewModel));
            var navigator = new Navigator();

            Router = new Router(navigator);
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new[]
                            {
                                RouteActions.NavigateBackWhile(transition => transition.ViewModel is TestViewModel),
                                RouteActions.Navigate()
                            }
                        }
                    }
                }
            };

            await Router.InitAsync(initParams);

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

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

            Assert.Collection(navigator.TransitionStack,
                              t => t.ViewModel.Should().BeAssignableTo <TestViewModel>());
        }
예제 #2
0
        public async Task Test_NavigateBackAction_Causes_Router_To_Navigate_Backwards()
        {
            Resolver.Register(() => new TestViewModel(), typeof(TestViewModel));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Navigate()
                            }
                        }
                    }
                }
            };

            await Router.InitAsync(initParams);

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

            await Router.BackAsync();

            Navigator.Received(1).PopAsync();
        }
예제 #3
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);
        }
예제 #4
0
        public void Test_Can_Serialize_RouterParams()
        {
            var str = JsonConvert.SerializeObject(new RouterConfig()
            {
                DefaultParameters    = new TestParams(),
                DefaultViewModelType = typeof(TestViewModel),
                ViewModelMap         = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new IRouteAction[]
                            {
                                RouteActions.Navigate()
                            }
                        }
                    }
                }
            }, new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Auto
            });

            str.Should().NotBeNull();
        }
예제 #5
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();
        }
예제 #6
0
        public async Task Test_ShowAsync_Pipes_Transition_To_Navigator_If_Router_Actions_Specify_Navigate()
        {
            Locator.CurrentMutable.Register(() => new TestViewModel(), typeof(TestViewModel));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(TestViewModel),
                        new RouteActions()
                        {
                            Actions = new [] { RouteActions.Navigate() }
                        }
                    }
                }
            };

            await Router.InitAsync(initParams);

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

            Navigator.Received(1)
            .PushAsync(Arg.Is <Transition>(t => t.ViewModel is TestViewModel));
        }
예제 #7
0
        public async Task Test_ShowAsync_Works_With_Unit_Params()
        {
            Locator.CurrentMutable.Register(() => new UnitViewModel(), typeof(UnitViewModel));
            var initParams = new RouterConfig()
            {
                ViewModelMap = new Dictionary <Type, RouteActions>()
                {
                    {
                        typeof(UnitViewModel),
                        new RouteActions()
                        {
                            Actions = new [] { RouteActions.Navigate() }
                        }
                    }
                }
            };

            await Router.InitAsync(initParams);

            await Router.ShowAsync <UnitViewModel>();

            Navigator.Received(1)
            .PushAsync(Arg.Is <Transition>(t => t.ViewModel is UnitViewModel));
        }
예제 #8
0
 public IRouteBuilder Navigate()
 {
     actions.Add(RouteActions.Navigate());
     return(this);
 }