Exemplo n.º 1
0
        public void NavigationPage()
        {
            var eventRecoder       = new EventRecorder();
            var contentPageMock1   = new ContentPageMock(eventRecoder);
            var contentPageMock2   = new ContentPageMock(eventRecoder);
            var viewModelMock      = new ViewModelMock(eventRecoder);
            var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder)
            {
                BindingContext = viewModelMock
            };

            contentPageMock1.Navigation.PushAsync(contentPageMock2);

            LifecycleNoticeService.OnUnloaded(navigationPageMock);

            Assert.Equal(3, eventRecoder.Count);

            Assert.NotNull(eventRecoder[0]);
            Assert.Equal(contentPageMock2, eventRecoder[0].Sender);
            Assert.Equal("OnUnloaded", eventRecoder[0].CallerMemberName);
            Assert.Null(eventRecoder[0].Parameter);

            Assert.NotNull(eventRecoder[1]);
            Assert.Equal(viewModelMock, eventRecoder[1].Sender);
            Assert.Equal("OnUnloaded", eventRecoder[1].CallerMemberName);
            Assert.Null(eventRecoder[1].Parameter);

            Assert.NotNull(eventRecoder[2]);
            Assert.Equal(navigationPageMock, eventRecoder[2].Sender);
            Assert.Equal("OnUnloaded", eventRecoder[2].CallerMemberName);
            Assert.Null(eventRecoder[2].Parameter);
        }
Exemplo n.º 2
0
        public async Task PushAsync_WithParameter()
        {
            var eventRecorder    = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecorder);
            // ReSharper disable once UnusedVariable
            var navigationPageMock   = new NavigationPageMock(contentPageMock1, eventRecorder);
            var navigationMock       = new Mock <INavigation>();
            var navigator            = new Navigator(contentPageMock1, navigationMock.Object);
            var behaviorInjectorMock = new Mock <IBehaviorInjector>();

            navigator.BehaviorInjector = behaviorInjectorMock.Object;

            var contentPageMock2 = new ContentPageMock(eventRecorder);
            var parameter        = new object();
            await navigator.PushAsync(contentPageMock2, parameter);


            behaviorInjectorMock.Verify(x => x.Inject(contentPageMock2), Times.Once);
            navigationMock.Verify(x => x.PushAsync(contentPageMock2, true), Times.Once);

            Assert.Equal(3, eventRecorder.Count);

            Assert.Equal(contentPageMock2, eventRecorder[0].Sender);
            Assert.Equal("OnInitialize", eventRecorder[0].CallerMemberName);
            Assert.Equal(parameter, eventRecorder[0].Parameter);

            Assert.Equal(contentPageMock2, eventRecorder[1].Sender);
            Assert.Equal("OnLoaded", eventRecorder[1].CallerMemberName);
            Assert.Null(eventRecorder[1].Parameter);

            Assert.Equal(contentPageMock1, eventRecorder[2].Sender);
            Assert.Equal("OnUnloaded", eventRecorder[2].CallerMemberName);
            Assert.Null(eventRecorder[2].Parameter);
        }
Exemplo n.º 3
0
        public void OnCurrentPageChanged()
        {
            var eventRecoder     = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecoder)
            {
                Title = "contentPageMock1"
            };
            var contentPageMock2 = new ContentPageMock(eventRecoder)
            {
                Title = "contentPageMock2"
            };
            var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder);

            contentPageMock1.Navigation.PushAsync(contentPageMock2);

            navigationPageMock.Behaviors.Add(new NavigationPageBehavior());

            contentPageMock2.Navigation.PopAsync();

            Assert.Equal(2, eventRecoder.Count);

            Assert.NotNull(eventRecoder[0]);
            Assert.Equal(contentPageMock1, eventRecoder[0].Sender);
            Assert.Equal("OnLoaded", eventRecoder[0].CallerMemberName);
            Assert.Null(eventRecoder[0].Parameter);

            Assert.NotNull(eventRecoder[1]);
            Assert.Equal(contentPageMock2, eventRecoder[1].Sender);
            Assert.Equal("OnClosed", eventRecoder[1].CallerMemberName);
            Assert.Null(eventRecoder[1].Parameter);
        }
Exemplo n.º 4
0
        public async Task PopToRootAsync_WhenAnimatedIsFalse()
        {
            var eventRecorder    = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock1"
            };
            var contentPageMock2 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock2"
            };
            var contentPageMock3 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock3"
            };
            // ReSharper disable once UnusedVariable
            var navigationPage = new NavigationPageMock(contentPageMock1, eventRecorder);
            await contentPageMock1.Navigation.PushAsync(contentPageMock2);

            await contentPageMock2.Navigation.PushAsync(contentPageMock3);

            var navigationMock = new Mock <INavigation>();

            navigationMock
            .Setup(m => m.PopToRootAsync(false))
            .Returns(() => Task.FromResult(false))
            .Callback(() => contentPageMock3.Navigation.PopToRootAsync(false).Wait());

            var navigator = new Navigator(contentPageMock3, navigationMock.Object);
            await navigator.PopToRootAsync(false);

            navigationMock.Verify(x => x.PopToRootAsync(false), Times.Once);
        }
Exemplo n.º 5
0
        public void CanNotPop()
        {
            var eventRecoder     = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecoder)
            {
                Title = "contentPageMock1"
            };
            var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder);

            navigationPageMock.Behaviors.Add(new NavigationPageBehavior());

            contentPageMock1.Navigation.PopAsync();

            Assert.Equal(0, eventRecoder.Count);
        }
Exemplo n.º 6
0
        public void NavigationPage()
        {
            var eventRecoder              = new EventRecorder();
            var contentPageMock1          = new ContentPageMock(eventRecoder);
            var contentPageMock2ViewModel = new ViewModelMock(eventRecoder);
            var contentPageMock2          = new ContentPageMock(eventRecoder)
            {
                BindingContext = contentPageMock2ViewModel
            };
            var viewModelMock      = new ViewModelMock(eventRecoder);
            var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder)
            {
                BindingContext = viewModelMock
            };

            contentPageMock1.Navigation.PushAsync(contentPageMock2);
            var parameter = "Hello, Parameter!";

            LifecycleNoticeService.OnInitialize(navigationPageMock, parameter);

            Assert.Equal(5, eventRecoder.Count);

            Assert.NotNull(eventRecoder[0]);
            Assert.Equal(navigationPageMock, eventRecoder[0].Sender);
            Assert.Equal("OnInitialize", eventRecoder[0].CallerMemberName);
            Assert.Equal(parameter, eventRecoder[0].Parameter);

            Assert.NotNull(eventRecoder[1]);
            Assert.Equal(viewModelMock, eventRecoder[1].Sender);
            Assert.Equal("OnInitialize", eventRecoder[1].CallerMemberName);
            Assert.Equal(parameter, eventRecoder[1].Parameter);

            Assert.NotNull(eventRecoder[2]);
            Assert.Equal(contentPageMock1, eventRecoder[2].Sender);
            Assert.Equal("OnInitialize", eventRecoder[2].CallerMemberName);
            Assert.Equal(parameter, eventRecoder[2].Parameter);

            Assert.NotNull(eventRecoder[3]);
            Assert.Equal(contentPageMock2, eventRecoder[3].Sender);
            Assert.Equal("OnInitialize", eventRecoder[3].CallerMemberName);
            Assert.Equal(parameter, eventRecoder[3].Parameter);

            Assert.NotNull(eventRecoder[4]);
            Assert.Equal(contentPageMock2ViewModel, eventRecoder[4].Sender);
            Assert.Equal("OnInitialize", eventRecoder[4].CallerMemberName);
            Assert.Equal(parameter, eventRecoder[4].Parameter);
        }
Exemplo n.º 7
0
        public async Task PopToRootAsync()
        {
            var eventRecorder    = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock1"
            };
            var contentPageMock2 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock2"
            };
            var contentPageMock3 = new ContentPageMock(eventRecorder)
            {
                Title = "contentPageMock3"
            };
            // ReSharper disable once UnusedVariable
            var navigationPage = new NavigationPageMock(contentPageMock1, eventRecorder);
            await contentPageMock1.Navigation.PushAsync(contentPageMock2);

            await contentPageMock2.Navigation.PushAsync(contentPageMock3);

            var navigationMock = new Mock <INavigation>();

            navigationMock
            .Setup(m => m.PopToRootAsync(true))
            .Returns(() => Task.FromResult(true))
            .Callback(() => contentPageMock3.Navigation.PopToRootAsync(true).Wait());

            var navigator = new Navigator(contentPageMock3, navigationMock.Object);
            await navigator.PopToRootAsync();

            navigationMock.Verify(x => x.PopToRootAsync(true), Times.Once);

            Assert.Equal(3, eventRecorder.Count);

            Assert.Equal(contentPageMock1, eventRecorder[0].Sender);
            Assert.Equal("OnLoaded", eventRecorder[0].CallerMemberName);
            Assert.Null(eventRecorder[0].Parameter);

            Assert.Equal(contentPageMock3, eventRecorder[1].Sender);
            Assert.Equal("OnClosed", eventRecorder[1].CallerMemberName);
            Assert.Null(eventRecorder[1].Parameter);

            Assert.Equal(contentPageMock2, eventRecorder[2].Sender);
            Assert.Equal("OnClosed", eventRecorder[2].CallerMemberName);
            Assert.Null(eventRecorder[2].Parameter);
        }
Exemplo n.º 8
0
        public void DestroyNavigationPage()
        {
            var recorder                = new PageNavigationEventRecorder();
            var navigationPage          = new NavigationPageMock(recorder);
            var navigationPageViewModel = navigationPage.BindingContext;
            var contentPage1            = navigationPage.CurrentPage;
            var contentPage1ViewModel   = contentPage1.BindingContext;
            var contentPage2            = new ContentPageMock(recorder);
            var contentPage2ViewModel   = contentPage2.BindingContext;

            contentPage1.Navigation.PushAsync(contentPage2);

            PageUtilities.DestroyPage(navigationPage);

            Assert.Equal(6, recorder.Records.Count);

            // contentPage2
            Assert.Equal(contentPage2, recorder.Records[0].Sender);
            Assert.Null(contentPage2.BindingContext);
            Assert.Equal(0, contentPage2.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[0].Event);

            Assert.Equal(contentPage2ViewModel, recorder.Records[1].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[1].Event);

            // contentPage1
            Assert.Equal(contentPage1, recorder.Records[2].Sender);
            Assert.Null(contentPage1.BindingContext);
            Assert.Equal(0, contentPage1.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[2].Event);

            Assert.Equal(contentPage1ViewModel, recorder.Records[3].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[3].Event);

            // navigationPage
            Assert.Equal(navigationPage, recorder.Records[4].Sender);
            Assert.Null(navigationPage.BindingContext);
            Assert.Equal(0, navigationPage.Behaviors.Count);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[4].Event);

            Assert.Equal(navigationPageViewModel, recorder.Records[5].Sender);
            Assert.Equal(PageNavigationEvent.Destroy, recorder.Records[5].Event);
        }
Exemplo n.º 9
0
        public async Task PushAsync_WhenAnimatedIsFalse()
        {
            var eventRecorder    = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecorder);
            // ReSharper disable once UnusedVariable
            var navigationPageMock   = new NavigationPageMock(contentPageMock1, eventRecorder);
            var navigationMock       = new Mock <INavigation>();
            var navigator            = new Navigator(contentPageMock1, navigationMock.Object);
            var behaviorInjectorMock = new Mock <IBehaviorInjector>();

            navigator.BehaviorInjector = behaviorInjectorMock.Object;

            var contentPageMock2 = new ContentPageMock(eventRecorder);
            await navigator.PushAsync(contentPageMock2, false);


            behaviorInjectorMock.Verify(x => x.Inject(contentPageMock2), Times.Once);
            navigationMock.Verify(x => x.PushAsync(contentPageMock2, false), Times.Once);
        }
Exemplo n.º 10
0
        public void OnDetachingFrom()
        {
            var eventRecoder     = new EventRecorder();
            var contentPageMock1 = new ContentPageMock(eventRecoder)
            {
                Title = "contentPageMock1"
            };
            var contentPageMock2 = new ContentPageMock(eventRecoder)
            {
                Title = "contentPageMock2"
            };
            var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder);

            contentPageMock1.Navigation.PushAsync(contentPageMock2);

            navigationPageMock.Behaviors.Add(new NavigationPageBehavior());
            navigationPageMock.Behaviors.Clear();

            contentPageMock2.Navigation.PopAsync();

            Assert.Equal(0, eventRecoder.Count);
        }
Exemplo n.º 11
0
        public async void RecursiveInject()
        {
            var eventRecoder      = new EventRecorder();
            var carouselPageMock1 = new CarouselPageMock(eventRecoder);
            var tabbedPageMock1   = new TabbedPageMock(eventRecoder);

            tabbedPageMock1.Children.Add(new ContentPage());
            tabbedPageMock1.Children.Add(carouselPageMock1);
            var navigationPage = new NavigationPageMock(tabbedPageMock1, eventRecoder);

            var carouselPageMock2 = new CarouselPageMock(eventRecoder);
            var tabbedPageMock2   = new TabbedPageMock(eventRecoder);

            tabbedPageMock2.Children.Add(new ContentPage());
            tabbedPageMock2.Children.Add(carouselPageMock2);

            await tabbedPageMock1.Navigation.PushAsync(tabbedPageMock2);

            var actual = new BehaviorInjector();

            actual.Inject(navigationPage);

            Assert.Equal(1, navigationPage.Behaviors.Count);
            Assert.IsType <NavigationPageBehavior>(navigationPage.Behaviors.Single());

            Assert.Equal(1, tabbedPageMock1.Behaviors.Count);
            Assert.IsType <MultiPageBehavior <Page> >(tabbedPageMock1.Behaviors.Single());

            Assert.Equal(1, tabbedPageMock2.Behaviors.Count);
            Assert.IsType <MultiPageBehavior <Page> >(tabbedPageMock2.Behaviors.Single());

            Assert.Equal(1, carouselPageMock1.Behaviors.Count);
            Assert.IsType <MultiPageBehavior <ContentPage> >(carouselPageMock1.Behaviors.Single());

            Assert.Equal(1, carouselPageMock2.Behaviors.Count);
            Assert.IsType <MultiPageBehavior <ContentPage> >(carouselPageMock2.Behaviors.Single());
        }