Пример #1
0
        /// <summary>
        /// Returns a redirect action for the first view following 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 after.</param>
        /// <param name="model">The parent view model.</param>
        /// <returns>A redirect <see cref="RedirectToActionResult"/> for the next possible view.</returns>
        protected IActionResult RedirectToNextPossibleView <T>(FormSection section, string actionName, T model)
            where T : IValidatable
        {
            var nextPage = FormDefinition.GetNextPossiblePage(section, actionName, model);

            return(RedirectToAction(section, nextPage.ActionName));
        }
        public void it_should_keep_searching_forwards_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.GetNextPossiblePage(validSection, startActionName, parent);

            Assert.IsTrue(result.MatchesName(lastActionName));
        }