public async Task Then_If_Employer_Redirect_To_Employer_Select_Course_If_No_Funding_Rules_Exist(
            ReservationsRouteModel routeModel,
            string expectedUserId,
            [Frozen] Mock <IMediator> mockMediator,
            ReservationsController controller)
        {
            routeModel.UkPrn            = null;
            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId)
            }));
            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = null
            };

            mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);

            //act
            var actual = await controller.SelectCourseRuleCheck(routeModel) as RedirectToRouteResult;

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.RouteName, RouteNames.EmployerSelectCourse);
        }
        public async Task Then_If_Employer_Redirect_To_Funding_Notification_If_Funding_Rules_Exist(
            ReservationsRouteModel routeModel,
            string expectedUserId,
            string expectedBackUrl,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IExternalUrlHelper> externalUrlHelper,
            ReservationsController controller)
        {
            //Arrange
            routeModel.UkPrn = null;
            var expectedRule = new GlobalRule
            {
                Id         = 2,
                ActiveFrom = DateTime.Now.AddDays(2)
            };

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId)
            }));
            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = expectedRule
            };

            mockMediator.Setup(x => x.Send(It.Is <GetNextUnreadGlobalFundingRuleQuery>(c => c.Id.Equals(expectedUserId)), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);
            externalUrlHelper.Setup(x => x.GenerateCohortDetailsUrl(null, routeModel.EmployerAccountId,
                                                                    routeModel.CohortReference, routeModel.CohortReference == string.Empty,
                                                                    It.IsAny <string>())).Returns(expectedBackUrl);

            //act
            var view = await controller.SelectCourseRuleCheck(routeModel) as ViewResult;

            //assert
            Assert.IsNotNull(view);
            var viewModel = view?.Model as FundingRestrictionNotificationViewModel;

            Assert.IsNotNull(viewModel);
            Assert.AreEqual(view.ViewName, "FundingRestrictionNotification");
            Assert.AreEqual(expectedRule.Id, viewModel.RuleId);
            Assert.AreEqual(RuleType.GlobalRule, viewModel.TypeOfRule);
            Assert.AreEqual(expectedRule.ActiveFrom, viewModel.RestrictionStartDate);
            Assert.AreEqual(expectedBackUrl, viewModel.BackLink);
            Assert.AreEqual(false, viewModel.IsProvider);
            Assert.AreEqual(RouteNames.EmployerSelectCourse, viewModel.RouteName);
            Assert.AreEqual(RouteNames.EmployerSaveRuleNotificationChoice, viewModel.PostRouteName);
        }
        public async Task ThenRedirectToFundingNotificationIfFundingRulesExist(
            string expectedUserId,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IUrlHelper> urlHelper,
            string expectedBackUrl,
            ReservationsRouteModel routeModel,
            EmployerReservationsController controller)
        {
            //Arrange
            urlHelper.Setup(h => h.RouteUrl(It.Is <UrlRouteContext>(c =>
                                                                    c.RouteName.Equals(RouteNames.EmployerManage))))
            .Returns(expectedBackUrl);
            var expectedRule = new GlobalRule
            {
                Id         = 2,
                ActiveFrom = DateTime.Now.AddDays(2)
            };

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId)
            }));
            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = expectedRule
            };

            mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);

            //act
            var view = await controller.Index(routeModel) as ViewResult;

            //assert
            Assert.IsNotNull(view);
            var viewModel = view?.Model as FundingRestrictionNotificationViewModel;

            Assert.IsNotNull(viewModel);
            Assert.AreEqual(view.ViewName, "FundingRestrictionNotification");
            Assert.AreEqual(expectedRule.Id, viewModel.RuleId);
            Assert.AreEqual(RuleType.GlobalRule, viewModel.TypeOfRule);
            Assert.AreEqual(expectedRule.ActiveFrom, viewModel.RestrictionStartDate);
            Assert.AreEqual(expectedBackUrl, viewModel.BackLink);
            Assert.AreEqual(false, viewModel.IsProvider);
            Assert.AreEqual(RouteNames.EmployerStart, viewModel.RouteName);
            Assert.AreEqual(RouteNames.EmployerSaveRuleNotificationChoiceNoReservation, viewModel.PostRouteName);
        }
        public void Arrange()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization {
                ConfigureMembers = true
            });

            _expectedRule = new GlobalRule {
                Id = 2, ActiveFrom = DateTime.Now.AddDays(2)
            };

            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = _expectedRule
            };

            _mockMediator = fixture.Freeze <Mock <IMediator> >();
            _config       = new ReservationsWebConfiguration
            {
                DashboardUrl = "test.com/test"
            };

            var options = fixture.Freeze <Mock <IOptions <ReservationsWebConfiguration> > >();

            options.Setup(o => o.Value).Returns(_config);

            _mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);

            _externalUrlHelper = fixture.Freeze <Mock <IExternalUrlHelper> >();
            _externalUrlHelper.Setup(x => x.GenerateDashboardUrl(null)).Returns(ExpectedDashboardUrl);

            _urlHelper = fixture.Freeze <Mock <IUrlHelper> >();
            _urlHelper.Setup(h => h.RouteUrl(It.Is <UrlRouteContext>(c =>
                                                                     c.RouteName.Equals(RouteNames.ProviderManage))))
            .Returns(ExpectedManageUrl);

            _controller = fixture.Create <ProviderReservationsController>();
            var claim = new Claim(ProviderClaims.ProviderUkprn, ExpectedUkPrn);

            _controller.ControllerContext.HttpContext = new DefaultHttpContext
            {
                User = new ClaimsPrincipal(new ClaimsIdentity(new[] { claim }))
            };
        }
        public async Task ThenRedirectToFundingPausedIfFundingRulesExist(
            string expectedUserId,
            [Frozen] Mock <IMediator> mockMediator,
            [Frozen] Mock <IOptions <ReservationsWebConfiguration> > config,
            EmployerReservationsController controller)
        {
            //Arrange
            var expectedRule = new GlobalRule
            {
                Id         = 2,
                ActiveFrom = DateTime.Now.AddDays(2)
            };

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId)
            }));
            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = expectedRule
            };

            mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);

            //act
            var view = await controller.Index() as ViewResult;

            //assert
            Assert.IsNotNull(view);
            var viewModel = view?.Model as FundingRestrictionNotificationViewModel;

            Assert.IsNotNull(viewModel);
            Assert.AreEqual(view.ViewName, "FundingRestrictionNotification");
            Assert.AreEqual(expectedRule.Id, viewModel.RuleId);
            Assert.AreEqual(RuleType.GlobalRule, viewModel.TypeOfRule);
            Assert.AreEqual(expectedRule.ActiveFrom, viewModel.RestrictionStartDate);
            Assert.AreEqual(config.Object.Value.EmployerDashboardUrl, viewModel.BackLink);
        }
        public async Task Then_If_Provider_Redirect_To_Provider_Select_Course_If_No_Funding_Rules_Exist(
            ReservationsRouteModel routeModel,
            string expectedUkprn,
            [Frozen] Mock <IMediator> mockMediator,
            ReservationsController controller)
        {
            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(ProviderClaims.ProviderUkprn, expectedUkprn)
            }));
            var result = new GetNextUnreadGlobalFundingRuleResult {
                Rule = null
            };

            mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(result);

            //act
            var actual = await controller.SelectCourseRuleCheck(routeModel) as RedirectToRouteResult;

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.RouteName, RouteNames.ProviderApprenticeshipTraining);
        }