Example #1
0
        public void NavigateToBack_Test()
        {
            using (var container = new UnityContainer())
            {
                FakeAppContent fakeAppContent = new Fakes.FakeAppContent()
                {
                    Value = 10
                };
                AppMainViewModel mainAppViewModel = new AppMainViewModel();
                FakeAppContent   homeContent      = new Fakes.FakeAppContent()
                {
                    Value = -1
                };
                var target = new NavigationService(container, mainAppViewModel, homeContent);

                Assert.IsFalse(target.CanNavigateBack());

                target.NavigateHome();
                Assert.IsTrue(homeContent.NavigationIn);
                Assert.IsFalse(target.CanNavigateBack());

                target.NavigateTo(fakeAppContent); //10
                Assert.IsTrue(fakeAppContent.NavigationIn);
                Assert.IsTrue(homeContent.NavigationOut);
                Assert.IsTrue(target.CanNavigateBack());

                homeContent.NavigationOut = false; homeContent.NavigationIn = false; fakeAppContent.NavigationOut = false;
                target.NavigateBack(); //-1

                Assert.IsTrue(homeContent.NavigationIn);
                Assert.IsTrue(fakeAppContent.NavigationOut);
                Assert.IsFalse(target.CanNavigateBack());
                Assert.AreEqual(-1, (mainAppViewModel.AppContent as Fakes.FakeAppContent).Value);

                target.NavigateTo(fakeAppContent); //10
                Assert.IsTrue(target.CanNavigateBack());

                target.NavigateTo(typeof(Fakes.FakeAppContent)); //0
                Assert.IsTrue(target.CanNavigateBack());

                target.NavigateTo(new Fakes.FakeAppContent()
                {
                    Value = 15
                });                                                           //15
                Assert.IsTrue(target.CanNavigateBack());

                target.NavigateBack(); //0
                Assert.AreEqual(0, (mainAppViewModel.AppContent as Fakes.FakeAppContent).Value);
                Assert.IsTrue(target.CanNavigateBack());

                target.NavigateBack(); //10
                Assert.AreEqual(10, (mainAppViewModel.AppContent as Fakes.FakeAppContent).Value);
                Assert.IsTrue(target.CanNavigateBack());

                target.NavigateBack(); //-1
                Assert.AreEqual(-1, (mainAppViewModel.AppContent as Fakes.FakeAppContent).Value);
                Assert.IsFalse(target.CanNavigateBack());
            }
        }