public async Task Then_If_Employer_Reads_UserId_Claim_And_Sends_Command_To_Mark_Rule_As_Read_And_Redirects_To_Route_In_Model(
            FundingRestrictionNotificationViewModel viewModel,
            ReservationsRouteModel routeModel,
            string expectedUserId,
            [Frozen] Mock <IMediator> mockMediator,
            ReservationsController controller)
        {
            //arrange
            viewModel.RouteName      = RouteNames.ProviderApprenticeshipTraining;
            routeModel.UkPrn         = null;
            viewModel.MarkRuleAsRead = true;

            var claim = new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId);

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { claim }));

            //act
            var actual = await controller.SaveRuleNotificationChoice(routeModel, viewModel) as RedirectToRouteResult;

            //assert
            mockMediator.Verify(m => m.Send(It.Is <MarkRuleAsReadCommand>(c =>
                                                                          c.Id.Equals(expectedUserId) &&
                                                                          c.RuleId.Equals(viewModel.RuleId) &&
                                                                          c.TypeOfRule.Equals(viewModel.TypeOfRule)), It.IsAny <CancellationToken>()));
            Assert.IsNotNull(actual);
            Assert.AreEqual(viewModel.RouteName, actual.RouteName);
        }
        protected async Task <ViewResult> CheckNextGlobalRule(string redirectRouteName, string claimName, string backLink, string postRouteName)
        {
            var isProvider = claimName == ProviderClaims.ProviderUkprn;

            var userAccountIdClaim = User.Claims.First(c => c.Type.Equals(claimName));
            var response           = await _mediator.Send(new GetNextUnreadGlobalFundingRuleQuery { Id = userAccountIdClaim.Value });

            var nextGlobalRuleId        = response?.Rule?.Id;
            var nextGlobalRuleStartDate = response?.Rule?.ActiveFrom;

            if (!nextGlobalRuleId.HasValue || nextGlobalRuleId.Value == 0 || !nextGlobalRuleStartDate.HasValue)
            {
                return(null);
            }

            var viewModel = new FundingRestrictionNotificationViewModel
            {
                RuleId               = nextGlobalRuleId.Value,
                TypeOfRule           = RuleType.GlobalRule,
                RestrictionStartDate = nextGlobalRuleStartDate.Value,
                BackLink             = backLink,
                RouteName            = redirectRouteName,
                IsProvider           = isProvider,
                PostRouteName        = postRouteName
            };

            return(View("FundingRestrictionNotification", viewModel));
        }
コード例 #3
0
        public async Task <IActionResult> Index(bool isFromManage)
        {
            var providerUkPrnClaim = ControllerContext.HttpContext.User.Claims.First(c => c.Type.Equals(ProviderClaims.ProviderUkprn));

            var response = await _mediator.Send(new GetNextUnreadGlobalFundingRuleQuery { Id = providerUkPrnClaim.Value });

            var nextGlobalRuleId        = response?.Rule?.Id;
            var nextGlobalRuleStartDate = response?.Rule?.ActiveFrom;

            if (!nextGlobalRuleId.HasValue || nextGlobalRuleId.Value == 0 || !nextGlobalRuleStartDate.HasValue)
            {
                RouteData.Values.Add(nameof(isFromManage), isFromManage);
                return(RedirectToAction("Start", RouteData?.Values));
            }

            var viewModel = new FundingRestrictionNotificationViewModel
            {
                RuleId               = nextGlobalRuleId.Value,
                TypeOfRule           = RuleType.GlobalRule,
                RestrictionStartDate = nextGlobalRuleStartDate.Value,
                BackLink             = _externalUrlHelper.GenerateDashboardUrl()
            };

            return(View("FundingRestrictionNotification", viewModel));
        }
        public void ThenIAmAbleToDismissThem()
        {
            var controller = Services.GetService <ReservationsController>();

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { _claim }));
            var fundingRestrictionViewModel = new FundingRestrictionNotificationViewModel
            {
                RuleId         = _globalRule.Id,
                TypeOfRule     = RuleType.GlobalRule,
                MarkRuleAsRead = true,
                IsProvider     = false,
                RouteName      = RouteNames.EmployerStart
            };

            TestData.ActionResult = controller.SaveRuleNotificationChoice(TestData.ReservationRouteModel, fundingRestrictionViewModel).Result;
            Assert.NotNull(TestData.ActionResult);
            Assert.AreEqual(RouteNames.EmployerStart, (TestData.ActionResult as RedirectToRouteResult)?.RouteName);
        }
        public async Task ThenDoesNotSendsCommandIfNotMarkedAsReadAnd_Redirects_To_Route_In_Model(
            FundingRestrictionNotificationViewModel viewModel,
            ReservationsRouteModel routeModel,
            string expectedUserId,
            [Frozen] Mock <IMediator> mockMediator,
            ReservationsController controller)
        {
            //Arrange
            viewModel.MarkRuleAsRead = false;

            //act
            var actual = await controller.SaveRuleNotificationChoice(routeModel, viewModel) as RedirectToRouteResult;

            //assert
            mockMediator.Verify(m => m.Send(It.Is <MarkRuleAsReadCommand>(c =>
                                                                          c.Id.Equals(expectedUserId) &&
                                                                          c.RuleId.Equals(viewModel.RuleId) &&
                                                                          c.TypeOfRule.Equals(viewModel.TypeOfRule)), It.IsAny <CancellationToken>()), Times.Never);
            Assert.IsNotNull(actual);
            Assert.AreEqual(viewModel.RouteName, actual.RouteName);
        }
        public async Task <IActionResult> Index()
        {
            var userAccountIdClaim = User.Claims.First(c => c.Type.Equals(EmployerClaims.IdamsUserIdClaimTypeIdentifier));
            var response           = await _mediator.Send(new GetNextUnreadGlobalFundingRuleQuery { Id = userAccountIdClaim.Value });

            var nextGlobalRuleId        = response?.Rule?.Id;
            var nextGlobalRuleStartDate = response?.Rule?.ActiveFrom;

            if (!nextGlobalRuleId.HasValue || nextGlobalRuleId.Value == 0 || !nextGlobalRuleStartDate.HasValue)
            {
                return(RedirectToAction("Start", RouteData?.Values));
            }

            var viewModel = new FundingRestrictionNotificationViewModel
            {
                RuleId               = nextGlobalRuleId.Value,
                TypeOfRule           = RuleType.GlobalRule,
                RestrictionStartDate = nextGlobalRuleStartDate.Value,
                BackLink             = _config.EmployerDashboardUrl
            };

            return(View("FundingRestrictionNotification", viewModel));
        }
        public async Task <IActionResult> SaveRuleNotificationChoice(ReservationsRouteModel routeModel, FundingRestrictionNotificationViewModel viewModel)
        {
            if (!viewModel.MarkRuleAsRead)
            {
                return(RedirectToRoute(viewModel.RouteName));
            }

            var claim = routeModel.UkPrn != null?
                        HttpContext.User.Claims.First(c => c.Type.Equals(ProviderClaims.ProviderUkprn)) :
                            HttpContext.User.Claims.First(c => c.Type.Equals(EmployerClaims.IdamsUserIdClaimTypeIdentifier));

            var claimValue = claim.Value;

            var command = new MarkRuleAsReadCommand
            {
                Id         = claimValue,
                RuleId     = viewModel.RuleId,
                TypeOfRule = viewModel.TypeOfRule
            };

            await _mediator.Send(command);

            return(RedirectToRoute(viewModel.RouteName));
        }