コード例 #1
0
        public async Task WhenFundingIsPaused_AndFromManage_ThenBackLinkSetToManage(
            string expectedBackLink,
            uint ukprn,
            [Frozen] Mock <IMediator> mockMediator,
            GetFundingRulesResult result,
            [Frozen] Mock <IUrlHelper> mockUrlHelper,
            [Frozen] Mock <IExternalUrlHelper> mockExternalUrlHelper,
            GlobalRule rule,
            ProviderReservationsController controller)
        {
            //Arrange
            rule.ActiveFrom = DateTime.UtcNow.AddDays(-5);
            result.GlobalRules.Add(rule);

            mockMediator
            .Setup(x => x.Send(It.IsAny <GetFundingRulesQuery>(), CancellationToken.None))
            .ReturnsAsync(result);
            mockUrlHelper
            .Setup(x => x.RouteUrl(It.IsAny <UrlRouteContext>()))
            .Returns(expectedBackLink);
            mockExternalUrlHelper
            .Setup(x => x.GenerateDashboardUrl(It.IsAny <string>()))
            .Returns("unexpectedUrl");
            controller.Url = mockUrlHelper.Object;
            //Act
            var viewResult = await controller.Start(ukprn, true) as ViewResult;

            //Assert
            Assert.NotNull(viewResult);
            Assert.NotNull(viewResult.Model as string);
            Assert.AreEqual(expectedBackLink, viewResult.Model as string);
            mockUrlHelper.Verify(x => x.RouteUrl(It.Is <UrlRouteContext>(y => y.RouteName == RouteNames.ProviderManage)), Times.Once);
            mockExternalUrlHelper.Verify(x => x.GenerateDashboardUrl(It.IsAny <string>()), Times.Never);
        }
コード例 #2
0
        public void Arrange()
        {
            _fromDate = new DateTime(2019, 01, 01);

            _activeRule = new GlobalRule
            {
                ActiveFrom  = _fromDate.AddDays(-2),
                ActiveTo    = _fromDate.AddDays(10),
                Restriction = 1,
                RuleType    = 1
            };

            _futureRule = new GlobalRule
            {
                ActiveFrom  = _fromDate.AddDays(2),
                ActiveTo    = _fromDate.AddDays(20),
                Restriction = 1,
                RuleType    = 1
            };

            var globalRules = new List <GlobalRule>
            {
                _activeRule,
                _futureRule
            };

            _context = new Mock <IReservationsDataContext>();
            _context.Setup(x => x.GlobalRules).ReturnsDbSet(globalRules);
            _globalRulesRepository = new GlobalRuleRepository(_context.Object);
        }
        public void Arrange()
        {
            _expectedGlobalRule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(2)
            };

            var fundingRules = new GetFundingRulesApiResponse
            {
                Rules       = new List <ReservationRule>(),
                GlobalRules = new List <GlobalRule>
                {
                    new GlobalRule {
                        ActiveFrom = DateTime.Now.AddDays(-2)
                    },
                    new GlobalRule {
                        ActiveFrom = DateTime.Now.AddDays(4)
                    },
                    _expectedGlobalRule
                }
            };

            _service = new Mock <IFundingRulesService>();
            _service.Setup(s => s.GetFundingRules()).ReturnsAsync(fundingRules);

            _handler = new GetNextUnreadGlobalFundingRuleQueryHandler(_service.Object);
        }
        public async Task Then_No_Employer_Acknowledged_Rules_Are_Returned()
        {
            //Arrange
            var userId = Guid.NewGuid();

            var acknowledgement = new UserRuleAcknowledgement
            {
                TypeOfRule = RuleType.GlobalRule,
                UserId     = userId
            };

            var rule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(2),
                UserRuleAcknowledgements = new List <UserRuleAcknowledgement> {
                    acknowledgement
                }
            };

            var fundingRules = new GetFundingRulesApiResponse
            {
                Rules       = new List <ReservationRule>(),
                GlobalRules = new List <GlobalRule> {
                    rule
                }
            };

            _service.Setup(s => s.GetFundingRules()).ReturnsAsync(fundingRules);

            //Act
            var actual = await _handler.Handle(new GetNextUnreadGlobalFundingRuleQuery { Id = userId.ToString() }, new CancellationToken());

            //Assert
            Assert.IsNull(actual.Rule);
        }
コード例 #5
0
        public LoanValidationResponse ValidateLoan(ILoan loan)
        {
            var response = new LoanValidationResponse();

            var globalRuleResult = CreateRuleTestResult(GlobalRule.Type, GlobalRule.Pass(loan));

            response.Results.Add(globalRuleResult);

            if (globalRuleResult.Pass)
            {
                RunRuleTests(loan, response);
            }

            return(response);
        }
        public async Task Then_Will_Return_Nearest_Rules_That_Has_Not_Been_Acknowledged_By_User()
        {
            //Arrange
            const int ukPrn = 12345;

            var acknowledgement = new UserRuleAcknowledgement
            {
                TypeOfRule = RuleType.GlobalRule,
                UkPrn      = ukPrn
            };

            var acknowledgeRule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(2),
                UserRuleAcknowledgements = new List <UserRuleAcknowledgement> {
                    acknowledgement
                }
            };

            var expectedRule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(3),
                UserRuleAcknowledgements = new List <UserRuleAcknowledgement>()
            };

            var futureRule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(4),
                UserRuleAcknowledgements = new List <UserRuleAcknowledgement>()
            };

            var fundingRules = new GetFundingRulesApiResponse
            {
                Rules       = new List <ReservationRule>(),
                GlobalRules = new List <GlobalRule> {
                    acknowledgeRule, expectedRule, futureRule
                }
            };

            _service.Setup(s => s.GetFundingRules()).ReturnsAsync(fundingRules);

            //Act
            var actual = await _handler.Handle(new GetNextUnreadGlobalFundingRuleQuery { Id = ukPrn.ToString() }, new CancellationToken());

            //Assert
            Assert.IsNotNull(actual.Rule);
            Assert.AreEqual(expectedRule, actual.Rule);
        }
        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);
        }
コード例 #9
0
        public async Task <GlobalRule> CheckReservationAgainstRules(IReservationRequest request)
        {
            var resultsList = await _repository.FindActive(request.CreatedDate);

            resultsList = resultsList
                          .Where(r => r.RuleType != (byte)GlobalRuleType.DynamicPause || r.ActiveTo > request.StartDate)
                          .Where(r => !r.GlobalRuleAccountExemptions?.Any(e => e.AccountId == request.AccountId) ?? true)
                          .ToList();

            if (resultsList == null || !resultsList.Any())
            {
                return(await CheckAccountReservationLimit(request.AccountId, request.IsLevyAccount));
            }

            foreach (var result in resultsList)
            {
                var globalRule  = new GlobalRule(result);
                var reservation = new Reservation(
                    request.Id,
                    request.AccountId,
                    request.StartDate,
                    _options.ExpiryPeriodInMonths,
                    request.AccountLegalEntityName,
                    request.CourseId,
                    request.ProviderId,
                    request.AccountLegalEntityId,
                    request.IsLevyAccount,
                    request.TransferSenderAccountId);

                switch (globalRule.Restriction)
                {
                case AccountRestriction.All:
                    return(globalRule);

                case AccountRestriction.NonLevy when !reservation.IsLevyAccount:
                    return(globalRule);

                case AccountRestriction.Levy when reservation.IsLevyAccount:
                    return(globalRule);
                }
            }

            return(null);
        }
        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 void ThenWillHaveNoActiveGlobalRules()
        {
            //Arrange
            var result = new GetFundingRulesResult
            {
                GlobalRules  = new List <GlobalRule>(),
                AccountRules = new List <ReservationRule>()
            };

            var expectedGlobalRule = new GlobalRule
            {
                ActiveFrom = DateTime.Now.AddDays(2)
            };

            result.GlobalRules.Add(expectedGlobalRule);

            //Assert
            Assert.AreEqual(1, result.GlobalRules.Count);
            Assert.IsEmpty(result.ActiveGlobalRules);
        }
        public void GivenThereAreUpcomingFundingRestrictionsInPlace()
        {
            var apiClient  = Services.GetService <IApiClient>();
            var mockClient = Mock.Get(apiClient);

            _globalRule = new GlobalRule
            {
                Id          = 1,
                RuleType    = GlobalRuleType.FundingPaused,
                ActiveFrom  = DateTime.UtcNow.AddDays(5),
                Restriction = AccountRestriction.NonLevy
            };
            _globalRules = new List <GlobalRule> {
                _globalRule
            };
            mockClient
            .Setup(x => x.Get <GetFundingRulesApiResponse>(It.IsAny <GetFundingRulesApiRequest>()))
            .ReturnsAsync(new GetFundingRulesApiResponse {
                GlobalRules = _globalRules
            });
        }
コード例 #13
0
        public void doGlobalRules(SQLRepository repository)
        {
            //end validation and write output

            foreach (Rule rule in listOfRules)
            {
                if (rule.getRuleExecutionPoint() == ruleExecutionPoint || ruleExecutionPoint == RuleExecutionPoint.OnRequest)
                {
                    if (rule is GlobalRule <SQLConnector> )
                    {
                        GlobalRule <SQLConnector>         connectorRule = rule as GlobalRule <SQLConnector>;
                        Dictionary <SQLConnector, String> results       = (rule as GlobalRule <SQLConnector>).doGlobalRule(repository);
                        foreach (SQLConnector con in results.Keys)
                        {
                            RuleResult ruleResult = ConsistencyUtil.computeRuleResult(rule, con, results[con]);
                            if (connectorRule.getCustomName(con, repository) != "")
                            {
                                ruleResult.NameOfObject = connectorRule.getCustomName(con, repository);
                            }
                            handleRuleResult(ruleResult, repository);
                        }
                    }
                    else if (rule is GlobalRule <SQLElement> )
                    {
                        GlobalRule <SQLElement>         elementRule = rule as GlobalRule <SQLElement>;
                        Dictionary <SQLElement, String> results     = (rule as GlobalRule <SQLElement>).doGlobalRule(repository);

                        foreach (SQLElement con in results.Keys)
                        {
                            RuleResult ruleResult = ConsistencyUtil.computeRuleResult(rule, con, results[con]);
                            if (elementRule.getCustomName(con, repository) != "")
                            {
                                ruleResult.NameOfObject = elementRule.getCustomName(con, repository);
                            }
                            handleRuleResult(ruleResult, repository);
                        }
                    }
                }
            }
        }
コード例 #14
0
        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);
        }