public void it_should_keep_searching_backwards_until_a_viewable_match_is_found()
        {
            const FormSection validSection     = FormSection.OrganisationDetails;
            const string      startActionName  = "startName";
            const string      noViewActionName = "no";
            const string      lastActionName   = "last";

            config.Fields = new Dictionary <FormSection, FormPageDefinition[]>
            {
                {
                    validSection,
                    new[]
                    {
                        new FormPageDefinition(nameof(ExampleViewModel.Populated), startActionName),
                        new FormPageDefinition(nameof(ExampleViewModel.SubModel), noViewActionName),
                        new FormPageDefinition(nameof(ExampleViewModel.Populated), lastActionName)
                    }
                }
            };

            var parent = new ExampleViewModel {
                CanView = false
            };

            var result = form.GetPreviousPossiblePage(validSection, lastActionName, parent);

            Assert.IsTrue(result.MatchesName(startActionName));
        }
Пример #2
0
        /// <summary>
        /// Returns a redirect action for the first view previous to the supplied view that
        /// can be viewed based on the state of the parent view model.
        /// </summary>
        /// <typeparam name="T">The type of the parent view model.</typeparam>
        /// <param name="section">The forms section.</param>
        /// <param name="actionName">The name of the action to look for views before.</param>
        /// <param name="model">The parent view model.</param>
        /// <returns>A redirect <see cref="RedirectToActionResult"/> for the previous possible view with the <code>back</code> indicator.</returns>
        protected IActionResult RedirectToPreviousPossibleView <T>(FormSection section, string actionName, T model)
        {
            var nextPage = FormDefinition.GetPreviousPossiblePage(section, actionName, model);

            return(RedirectBackToAction(section, nextPage.ActionName));
        }