public void EditSupervisorPost_redirects_to_correct_action(
            DelegateAccessRoute accessedVia,
            string expectedController,
            string expectedAction
            )
        {
            // Given
            const int supervisorId = 1;
            var       formData     = new EditSupervisorFormData
            {
                SupervisorId    = supervisorId,
                ReturnPageQuery = ReturnPageQueryHelper.GetDefaultReturnPageQuery(itemIdToReturnTo: CardId),
            };

            A.CallTo(() => progressService.UpdateSupervisor(ProgressId, supervisorId)).DoesNothing();

            // When
            var result = delegateProgressController.EditSupervisor(formData, ProgressId, accessedVia);

            // Then
            var expectedFragment = accessedVia.Equals(DelegateAccessRoute.CourseDelegates) ? CardId : null;

            result.Should().BeRedirectToActionResult().WithControllerName(expectedController)
            .WithActionName(expectedAction).WithFragment(expectedFragment);
        }
        public void EditDelegateCourseAdminField_POST_calls_service_and_redirects_to_correct_action(
            DelegateAccessRoute accessedVia,
            string expectedController,
            string expectedAction
            )
        {
            // Given
            const int    promptNumber = 1;
            const string answer       = "Test Answer";
            var          formData     = new EditDelegateCourseAdminFieldFormData
            {
                Answer          = answer,
                ReturnPageQuery = ReturnPageQueryHelper.GetDefaultReturnPageQuery(itemIdToReturnTo: CardId),
            };

            A.CallTo(() => progressService.UpdateCourseAdminFieldForDelegate(A <int> ._, A <int> ._, A <string> ._))
            .DoesNothing();

            // When
            var result = delegateProgressController.EditDelegateCourseAdminField(
                formData,
                promptNumber,
                ProgressId,
                accessedVia
                );

            // Then
            A.CallTo(() => progressService.UpdateCourseAdminFieldForDelegate(ProgressId, promptNumber, answer))
            .MustHaveHappenedOnceExactly();
            var expectedFragment = accessedVia.Equals(DelegateAccessRoute.CourseDelegates) ? CardId : null;

            result.Should().BeRedirectToActionResult().WithControllerName(expectedController)
            .WithActionName(expectedAction).WithFragment(expectedFragment);
        }
        public void UnlockCourseProgress_redirects_to_correct_action_and_unlocks_progress_and_sends_notification(
            DelegateAccessRoute accessedVia,
            string expectedController,
            string expectedAction,
            ReturnPageQuery?returnPageQuery
            )
        {
            // Given
            A.CallTo(() => progressService.UnlockProgress(ProgressId)).DoesNothing();

            // When
            var result = delegateProgressController.UnlockProgress(
                ProgressId,
                CustomisationId,
                DelegateId,
                accessedVia,
                returnPageQuery
                );

            // Then
            A.CallTo(() => progressService.UnlockProgress(ProgressId)).MustHaveHappened();
            var expectedFragment = accessedVia.Equals(DelegateAccessRoute.CourseDelegates)
                ? returnPageQuery !.Value.ItemIdToReturnTo
                : null;

            result.Should().BeRedirectToActionResult().WithControllerName(expectedController)
            .WithActionName(expectedAction).WithFragment(expectedFragment);
        }
        public void EditCompleteByDatePost_redirects_to_correct_action(
            DelegateAccessRoute accessedVia,
            string expectedController,
            string expectedAction
            )
        {
            // Given
            var formData = new EditCompleteByDateFormData
            {
                Day             = 1,
                Month           = 1,
                Year            = 2021,
                ReturnPageQuery = ReturnPageQueryHelper.GetDefaultReturnPageQuery(itemIdToReturnTo: CardId),
            };

            A.CallTo(() => progressService.UpdateCompleteByDate(ProgressId, A <DateTime?> ._)).DoesNothing();

            // When
            var result = delegateProgressController.EditCompleteByDate(formData, ProgressId, accessedVia);

            // Then
            var expectedFragment = accessedVia.Equals(DelegateAccessRoute.CourseDelegates) ? CardId : null;

            result.Should().BeRedirectToActionResult().WithControllerName(expectedController)
            .WithActionName(expectedAction).WithFragment(expectedFragment);
        }
        private IActionResult RedirectToPreviousPage(
            int delegateId,
            int customisationId,
            DelegateAccessRoute accessedVia,
            ReturnPageQuery?returnPageQuery
            )
        {
            if (accessedVia.Equals(DelegateAccessRoute.CourseDelegates))
            {
                var routeData = returnPageQuery !.Value.ToRouteDataDictionary();
                routeData.Add("customisationId", customisationId.ToString());
                return(RedirectToAction("Index", "CourseDelegates", routeData, returnPageQuery.Value.ItemIdToReturnTo));
            }

            return(RedirectToAction("Index", "ViewDelegate", new { delegateId }));
        }