コード例 #1
0
        public async Task It_stacks_modals_navigators()
        {
            var sut = new BlindSectionsNavigator();

            var modalNavigator = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(1), suppressTransition: true)));

            Assert.NotNull(modalNavigator);
            Assert.Equal(1, modalNavigator.Priority);
            Assert.Single(modalNavigator.State.Stack);

            Assert.Single(sut.State.Modals);
            Assert.NotNull(sut.State.ActiveModal);
            Assert.Equal(modalNavigator, sut.State.ActiveModal);
            Assert.Equal(modalNavigator, sut.State.Modals[0]);

            var modalNavigator2 = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(2), suppressTransition: true)));

            Assert.NotNull(modalNavigator2);
            Assert.Equal(2, modalNavigator2.Priority);
            Assert.Single(modalNavigator2.State.Stack);

            Assert.Equal(2, sut.State.Modals.Count);
            Assert.NotNull(sut.State.ActiveModal);
            Assert.Equal(modalNavigator2, sut.State.ActiveModal);
            Assert.Equal(modalNavigator, sut.State.Modals[0]);
            Assert.Equal(modalNavigator2, sut.State.Modals[1]);
        }
コード例 #2
0
        public async Task It_fails_to_open_2_modals_with_same_priority()
        {
            var sut = new BlindSectionsNavigator();

            await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), suppressTransition: true), modalPriority: 1));

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(), suppressTransition: true), modalPriority: 1));
            });
        }
コード例 #3
0
        public async Task It_orders_modals()
        {
            var sut = new BlindSectionsNavigator();

            var modalNavigator3 = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(3), suppressTransition: true), modalPriority: 3));

            var modalNavigator1 = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(1), suppressTransition: true), modalPriority: 1));

            Assert.Equal(sut.State.Modals[0], modalNavigator1);
            Assert.Equal(sut.State.Modals[1], modalNavigator3);

            var modalNavigator2 = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(2), suppressTransition: true), modalPriority: 2));

            Assert.Equal(sut.State.Modals[0], modalNavigator1);
            Assert.Equal(sut.State.Modals[1], modalNavigator2);
            Assert.Equal(sut.State.Modals[2], modalNavigator3);
        }
コード例 #4
0
        public async Task It_disposes_modal_VM_when_closing_modals()
        {
            var sut = new BlindSectionsNavigator();

            var modalNavigator = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(1), suppressTransition: true)));

            var vm = (TestVM)modalNavigator.State.Stack.Last().ViewModel;

            await sut.CloseModal(CancellationToken.None, SectionsNavigatorRequest.GetCloseModalRequest(null));

            Assert.True(vm.IsDisposed);
        }
コード例 #5
0
        public async Task Interface_contract_changes_can_be_detected()
        {
            var ct        = CancellationToken.None;
            var navigator = new BlindSectionsNavigator("Section1", "Section2");

            // If the core contract changes, we get compilation errors here.
            ISectionStackNavigator sectionNavigator = await navigator.SetActiveSection(ct, SectionsNavigatorRequest.GetSetActiveSectionRequest("Section1"));

            IModalStackNavigator modalNavigator = await navigator.OpenModal(ct, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigation.StackNavigatorRequest.GetNavigateRequest(() => new TestVM()), "modalName", 0));

            await navigator.CloseModal(ct, SectionsNavigatorRequest.GetCloseModalRequest("modalName", 0));
        }
コード例 #6
0
        public async Task Interface_contract_changes_can_be_detected()
        {
            var ct = CancellationToken.None;
            var sectionsNavigator = new BlindSectionsNavigator("Section1", "Section2");

            // If the core contract changes, we get compilation errors here.
            IModalStackNavigator navigator = await sectionsNavigator.OpenModal(ct, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigation.StackNavigatorRequest.GetNavigateRequest(() => new TestVM()), "modalName", 0));

            // Make sure IModalStackNavigator inherits from IStackNavigator
            StackNavigation.IStackNavigator stackNavigator = navigator;

            Assert.Equal("modalName", navigator.Name);
            Assert.Equal(0, navigator.Priority);
        }
コード例 #7
0
        public async Task It_produces_failed_notifications_for_OpenModal()
        {
            var sut       = new BlindSectionsNavigator();
            var eventList = new List <(object sender, SectionsNavigatorEventArgs args)>();

            sut.StateChanged += OnStateChanged;
            void OnStateChanged(object sender, SectionsNavigatorEventArgs args)
            {
                eventList.Add((sender, args));
            }

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => TestVM.Throw(), suppressTransition: true))));

            sut.StateChanged -= OnStateChanged;

            Assert.Equal(2, eventList.Count);
            Assert.Equal(NavigatorRequestState.Processing, eventList[0].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.OpenModal, eventList[0].args.CurrentState.LastRequest.RequestType);

            Assert.Equal(NavigatorRequestState.FailedToProcess, eventList[1].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.OpenModal, eventList[1].args.CurrentState.LastRequest.RequestType);
        }
コード例 #8
0
        public async Task It_produces_2_notifications_for_OpenModal()
        {
            var sut       = new BlindSectionsNavigator();
            var eventList = new List <(object sender, SectionsNavigatorEventArgs args)>();

            sut.StateChanged += OnStateChanged;
            void OnStateChanged(object sender, SectionsNavigatorEventArgs args)
            {
                eventList.Add((sender, args));
            }

            var modalNavigator = await sut.OpenModal(CancellationToken.None, SectionsNavigatorRequest.GetOpenModalRequest(StackNavigatorRequest.GetNavigateRequest(() => new TestVM(1), suppressTransition: true)));

            sut.StateChanged -= OnStateChanged;

            Assert.Equal(2, eventList.Count);
            Assert.Equal(NavigatorRequestState.Processing, eventList[0].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.OpenModal, eventList[0].args.CurrentState.LastRequest.RequestType);

            Assert.Equal(NavigatorRequestState.Processed, eventList[1].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.OpenModal, eventList[1].args.CurrentState.LastRequest.RequestType);
        }
コード例 #9
0
        public async Task Extended_interface_contract_changes_can_be_detected()
        {
            var ct        = CancellationToken.None;
            var navigator = new BlindSectionsNavigator("Section1", "Section2");

            // If the extension methods available in the abstraction package change their signatures, we get compilation errors here.

            // Only test extensions specific to ISectionStackNavigator

            ISectionStackNavigator sectionNavigator1 = await navigator.SetActiveSection(ct, "Section1");

            ISectionStackNavigator sectionNavigator2 = await navigator.SetActiveSection(ct, "Section1", () => new TestVM(), true);

            StackNavigation.IStackNavigator stackNavigator = navigator.GetActiveStackNavigator();
            await navigator.OpenModal(ct, () => new TestVM(), 0, "modalName");

            bool canNavigateBackOrCloseModal = navigator.CanNavigateBackOrCloseModal();
            await navigator.NavigateBackOrCloseModal(ct);

            IObservable <EventPattern <SectionsNavigatorEventArgs> > ob1 = navigator.ObserveStateChanged();
            IObservable <SectionsNavigatorState> ob2 = navigator.ObserveCurrentState();
        }