public async Task It_produces_failed_notifications_when_a_section_navigates()
        {
            var sut       = new BlindSectionsNavigator("defaultSection1", "defaultSection2");
            var eventList = new List <(object sender, SectionsNavigatorEventArgs args)>();

            var section = await sut.SetActiveSection(CancellationToken.None, SectionsNavigatorRequest.GetSetActiveSectionRequest("defaultSection1"));

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

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await section.Navigate(CancellationToken.None, StackNavigatorRequest.GetNavigateRequest(() => TestVM.Throw(), suppressTransition: true)));

            Assert.Equal(2, eventList.Count);
            Assert.Equal(NavigatorRequestState.Processing, eventList[0].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.ReportSectionStateChanged, eventList[0].args.CurrentState.LastRequest.RequestType);
            Assert.Equal(NavigatorRequestState.FailedToProcess, eventList[1].args.CurrentState.LastRequestState);
            Assert.Equal(SectionsNavigatorRequestType.ReportSectionStateChanged, eventList[1].args.CurrentState.LastRequest.RequestType);
        }
        public async Task It_produces_failed_notifications_for_SetActiveSection()
        {
            var sut = new BlindSectionsNavigator("defaultSection1", "defaultSection2");

            var eventList = new List <(object sender, SectionsNavigatorEventArgs args)>();

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

            Assert.Null(sut.State.ActiveSection);

            await Assert.ThrowsAsync <KeyNotFoundException>(async() => await sut.SetActiveSection(CancellationToken.None, SectionsNavigatorRequest.GetSetActiveSectionRequest("Invalid section name")));

            sut.StateChanged -= OnStateChanged;

            Assert.Null(sut.State.ActiveSection);

            Assert.Equal(2, eventList.Count);
            Assert.Equal(NavigatorRequestState.Processing, eventList[0].args.CurrentState.LastRequestState);
            Assert.Equal(NavigatorRequestState.FailedToProcess, eventList[1].args.CurrentState.LastRequestState);
        }
        public async Task It_produces_2_notifications_for_SetActiveSection()
        {
            var sut = new BlindSectionsNavigator("defaultSection1", "defaultSection2");

            var eventList = new List <(object sender, SectionsNavigatorEventArgs args)>();

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

            Assert.Null(sut.State.ActiveSection);

            const string sectionName   = "defaultSection1";
            var          activeSection = await sut.SetActiveSection(CancellationToken.None, SectionsNavigatorRequest.GetSetActiveSectionRequest(sectionName));

            sut.StateChanged -= OnStateChanged;

            Assert.NotNull(sut.State.ActiveSection);
            Assert.Equal(sut.State.ActiveSection, activeSection);

            Assert.Equal(2, eventList.Count);
            Assert.Equal(NavigatorRequestState.Processing, eventList[0].args.CurrentState.LastRequestState);
            Assert.Equal(NavigatorRequestState.Processed, eventList[1].args.CurrentState.LastRequestState);
        }
        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.
            ISectionStackNavigator navigator = await sectionsNavigator.SetActiveSection(ct, SectionsNavigatorRequest.GetSetActiveSectionRequest("Section1"));

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

            Assert.Equal("Section1", navigator.Name);
        }
        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));
        }