コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime. 
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        /// <param name="ipAddressParser">
        /// The IpAddressParser
        /// </param>
        public ThrottlingMiddleware(OwinMiddleware next, 
            ThrottlePolicy policy, 
            IPolicyRepository policyRepository, 
            IThrottleRepository repository, 
            IThrottleLogger logger,
            IIpAddressParser ipAddressParser)
            : base(next)
        {
            core = new ThrottlingCore();
            core.Repository = repository;
            Repository = repository;
            Logger = logger;

            if (ipAddressParser != null)
            {
                core.IpAddressParser = ipAddressParser;
            }

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
コード例 #2
0
 public MultiMemberInsurancePremium(IPolicyRepository policyRepository, IMemberRepository memberRepository,
     IMultiMemberPremiumCalculator calculator)
 {
     this.policyRepository = policyRepository;
     this.memberRepository = memberRepository;
     this.calculator = calculator;
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottlingFilter"/> class.
        /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation.
        /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime. 
        /// </summary>
        /// <param name="policy">
        /// The policy.
        /// </param>
        /// <param name="policyRepository">
        /// The policy repository.
        /// </param>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="logger">
        /// The logger.
        /// </param>
        public ThrottlingFilter(ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger)
        {
            core = new ThrottlingCore();
            core.Repository = repository;
            Repository = repository;
            Logger = logger;

            QuotaExceededResponseCode = (HttpStatusCode)429;

            this.policy = policy;
            this.policyRepository = policyRepository;

            if (policyRepository != null)
            {
                policyRepository.Save(ThrottleManager.GetPolicyKey(), policy);
            }
        }
コード例 #4
0
 public PolicyController(IPolicyRepository repository)
 {
     _repository = repository;
 }
コード例 #5
0
        public SaveFundingConfigurationValidator(IPolicyRepository policyRepository,
                                                 IPolicyResiliencePolicies policyResiliencePolicies,
                                                 IFundingTemplateService fundingTemplateService)
        {
            Guard.ArgumentNotNull(policyRepository, nameof(policyRepository));
            Guard.ArgumentNotNull(fundingTemplateService, nameof(fundingTemplateService));
            Guard.ArgumentNotNull(policyResiliencePolicies?.PolicyRepository, nameof(policyResiliencePolicies.PolicyRepository));

            ResiliencePolicy policyRepositoryPolicy = policyResiliencePolicies.PolicyRepository;

            RuleFor(_ => _.ApprovalMode)
            .Must(_ => _ != ApprovalMode.Undefined)
            .WithMessage("No valid approval mode was selected");

            RuleFor(model => model.FundingStreamId)
            .NotEmpty()
            .WithMessage("No funding stream id was provided to SaveFundingConfiguration")
            .CustomAsync(async(name, context, cancellationToken) =>
            {
                FundingConfiguration model = context.ParentContext.InstanceToValidate as FundingConfiguration;
                if (!string.IsNullOrWhiteSpace(model.FundingStreamId))
                {
                    FundingStream fundingStream = await policyRepositoryPolicy.ExecuteAsync(() => policyRepository.GetFundingStreamById(model.FundingStreamId));
                    if (fundingStream == null)
                    {
                        context.AddFailure("Funding stream not found");
                    }
                }
            });

            RuleFor(model => model.FundingPeriodId)
            .NotEmpty()
            .WithMessage("No funding period id was provided to SaveFundingConfiguration")
            .CustomAsync(async(name, context, cancellationToken) =>
            {
                FundingConfiguration model = context.ParentContext.InstanceToValidate as FundingConfiguration;
                if (!string.IsNullOrWhiteSpace(model.FundingPeriodId))
                {
                    FundingPeriod fundingPeriod = await policyRepositoryPolicy.ExecuteAsync(() => policyRepository.GetFundingPeriodById(model.FundingPeriodId));
                    if (fundingPeriod == null)
                    {
                        context.AddFailure("Funding period not found");
                    }
                }
            });

            RuleFor(model => model.DefaultTemplateVersion)
            .CustomAsync(async(name, context, cancellationToken) =>
            {
                FundingConfiguration model = context.ParentContext.InstanceToValidate as FundingConfiguration;

                string fundingStreamId        = model.FundingStreamId;
                string defaultTemplateVersion = model.DefaultTemplateVersion;
                string fundingPeriodId        = model.FundingPeriodId;

                if (!string.IsNullOrWhiteSpace(fundingStreamId) && !string.IsNullOrWhiteSpace(fundingPeriodId) && !string.IsNullOrWhiteSpace(defaultTemplateVersion))
                {
                    if (!await fundingTemplateService.TemplateExists(fundingStreamId, fundingPeriodId, defaultTemplateVersion))
                    {
                        context.AddFailure("Default template not found");
                    }
                }
            });

            RuleFor(_ => _.UpdateCoreProviderVersion)
            .Must(v => v == UpdateCoreProviderVersion.Manual)
            .When(_ => _.ProviderSource != CalculateFunding.Models.Providers.ProviderSource.FDZ, ApplyConditionTo.CurrentValidator)
            .WithMessage(x => $"UpdateCoreProviderVersion - {x.UpdateCoreProviderVersion.ToString()} is not valid for provider source - {x.ProviderSource}");
        }
コード例 #6
0
 public PolicyManager(IPolicyRepository repo)
 {
     _repo = repo;
 }
コード例 #7
0
 public PolicyCreatedHandler(IPolicyRepository policis)
 {
     this.policis = policis;
 }
コード例 #8
0
 public CustomThrottlingFilter(ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger)
     : base(policy, policyRepository, repository, logger)
 {
     this.QuotaExceededMessage = "API calls quota exceeded! maximum admitted {0} per {1}.";
 }
コード例 #9
0
 public InsuranceAPIController()
 {
     repository        = new PolicyRepository();
     userRepository    = new UserRepository();
     enquiryRepository = new EnquiryRepository();
 }
コード例 #10
0
 public PolicyAuthorizationHandler(IPolicyRepository policyRepository, IGroupPermissionService groupPermission)
 {
     _policyRepository = policyRepository;
     _grouPermission   = groupPermission;
 }
コード例 #11
0
 public SearchAuthPoliciesAction(IPolicyRepository policyRepository)
 {
     _policyRepository = policyRepository;
 }
コード例 #12
0
 public PolicyService(IPolicyExpressionFactory policyExpressionFactory, IPolicyRepository policyRepository)
 {
     _expressionFactory = policyExpressionFactory;
     _policyRepositor   = policyRepository;
 }
コード例 #13
0
        /// <summary>
        ///
        /// </summary>

        /// <param name="policyRepository"></param>
        /// <param name="logger"></param>
        /// <param name="cacheProvider"></param>
        public PolicyService(IPolicyRepository policyRepository, ILogger logger, IEasyCachingProvider cacheProvider)
        {
            _logger           = logger;
            _cacheProvider    = cacheProvider;
            _policyRepository = policyRepository;
        }
コード例 #14
0
 public PolicyRulesController(IDeviceRepository deviceRepository, IEventsRepository eventRepository, IPolicyRepository policyRepository)
 {
     deviceRepo = deviceRepository;
     eventRepo  = eventRepository;
     policyRepo = policyRepository;
 }
コード例 #15
0
 public GetPolicyInteractor(IPolicyRepository policyRepo)
 {
     _repo = policyRepo;
 }
コード例 #16
0
 public ConfirmTerminationHandler(IPolicyRepository policyRepository)
 {
     this.policyRepository = policyRepository;
 }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PolicyRetrievalPoint"/> class.
 /// </summary>
 /// <param name="policyRepository">The policy Repository..</param>
 public PolicyRetrievalPoint(IPolicyRepository policyRepository)
 {
     _repository = policyRepository;
 }
コード例 #18
0
 public PolicyCreatedHandler(IPolicyRepository policyRepository)
 {
     this.policyRepository = policyRepository;
 }
コード例 #19
0
 /// <summary>
 /// Reads the policy object from store and updates the cache
 /// </summary>
 /// <param name="storeProvider">
 /// The store provider.
 /// </param>
 /// <param name="cacheRepository">
 /// The cache repository.
 /// </param>
 public static void UpdatePolicy(IThrottlePolicyProvider storeProvider, IPolicyRepository cacheRepository)
 {
     var policy = ThrottlePolicy.FromStore(storeProvider);
     cacheRepository.Save(GetPolicyKey(), policy);
 }
コード例 #20
0
 public PolicyService(IUnitOfWorkAsync unitOfWork, IPolicyRepository PolicyRepo)
 {
     this._unitOfWork = unitOfWork;
     this._PolicyRepo = PolicyRepo;
 }
コード例 #21
0
 public UpdateResourcePermissionsAction(IResourceSetRepository resourceSetRepository, IPolicyRepository policyRepository)
 {
     _resourceSetRepository = resourceSetRepository;
     _policyRepository      = policyRepository;
 }
コード例 #22
0
 public PoliciesController(IPolicyRepository repo, IMapper mapper)
 {
     _mapper = mapper;
     _repo   = repo;
 }
コード例 #23
0
 public PolicyLogic(IPolicyRepository policyRepository)
 {
     this.policyRepository = policyRepository;
 }
コード例 #24
0
 /// <summary>
 /// Конструктор класса.
 /// </summary>
 /// <param name="policyRepository">Репозиторий, реализующий интерфейс IPolicyRepository.</param>
 public PolicyManager(IPolicyRepository policyRepository)
 {
     _policyRepository = policyRepository;
 }
コード例 #25
0
 public UserService(
     IUserRepository userRepository,
     ICipherRepository cipherRepository,
     IOrganizationUserRepository organizationUserRepository,
     IOrganizationRepository organizationRepository,
     IU2fRepository u2fRepository,
     IMailService mailService,
     IPushNotificationService pushService,
     IUserStore <User> store,
     IOptions <IdentityOptions> optionsAccessor,
     IPasswordHasher <User> passwordHasher,
     IEnumerable <IUserValidator <User> > userValidators,
     IEnumerable <IPasswordValidator <User> > passwordValidators,
     ILookupNormalizer keyNormalizer,
     IdentityErrorDescriber errors,
     IServiceProvider services,
     ILogger <UserManager <User> > logger,
     ILicensingService licenseService,
     IEventService eventService,
     IApplicationCacheService applicationCacheService,
     IDataProtectionProvider dataProtectionProvider,
     IPaymentService paymentService,
     IPolicyRepository policyRepository,
     IReferenceEventService referenceEventService,
     ICurrentContext currentContext,
     GlobalSettings globalSettings,
     IOrganizationService organizationService)
     : base(
         store,
         optionsAccessor,
         passwordHasher,
         userValidators,
         passwordValidators,
         keyNormalizer,
         errors,
         services,
         logger)
 {
     _userRepository             = userRepository;
     _cipherRepository           = cipherRepository;
     _organizationUserRepository = organizationUserRepository;
     _organizationRepository     = organizationRepository;
     _u2fRepository                    = u2fRepository;
     _mailService                      = mailService;
     _pushService                      = pushService;
     _identityOptions                  = optionsAccessor?.Value ?? new IdentityOptions();
     _identityErrorDescriber           = errors;
     _passwordHasher                   = passwordHasher;
     _passwordValidators               = passwordValidators;
     _licenseService                   = licenseService;
     _eventService                     = eventService;
     _applicationCacheService          = applicationCacheService;
     _paymentService                   = paymentService;
     _policyRepository                 = policyRepository;
     _organizationServiceDataProtector = dataProtectionProvider.CreateProtector(
         "OrganizationServiceDataProtector");
     _referenceEventService = referenceEventService;
     _currentContext        = currentContext;
     _globalSettings        = globalSettings;
     _organizationService   = organizationService;
 }
コード例 #26
0
 public FindPolicyHandler(IPolicyRepository policis)
 {
     this.policis = policis;
 }
コード例 #27
0
 public PolicyService(IUnitOfWork uow, IPolicyRepository policyRepository, IMapper iMapper)
 {
     _repo   = policyRepository;
     _uow    = uow;
     _mapper = iMapper;
 }
コード例 #28
0
 public PoliciesController()
 {
     policyRepository           = IocConfig.GetInstance <PolicyRepository>();
     coverageByPolicyRepository = IocConfig.GetInstance <CoverageByPolicyRepository>();
 }
コード例 #29
0
 public ClientService(IClientRepository clientRepository, IPolicyRepository policyRepository)
 {
     this.ClientRepository = clientRepository;
     this.PolicyRepository = policyRepository;
 }
コード例 #30
0
        async public Task SaveFundingConfiguration_GivenValidConfiguration_ReturnsStatusCode(
            string fundingStreamId, string fundingPeriodId)
        {
            FundingStream fundingStream = NewFundingStream(_ => _.WithId(fundingStreamId));
            FundingPeriod fundingPeriod = NewFundingPeriod(_ => _.WithId(fundingPeriodId));

            ILogger logger = CreateLogger();

            HttpStatusCode statusCode = HttpStatusCode.OK;

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .RemoveAsync <List <FundingConfiguration> >($"{CacheKeys.FundingConfig}{fundingStreamId}")
            .Returns(Task.CompletedTask);

            cacheProvider
            .SetAsync(
                $"{CacheKeys.FundingConfig}{fundingStreamId}-{fundingPeriodId}",
                Arg.Is <FundingConfiguration>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId))
            .Returns(Task.CompletedTask);

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(fundingStream);

            policyRepository
            .GetFundingPeriodById(Arg.Is(fundingPeriodId))
            .Returns(fundingPeriod);

            policyRepository
            .SaveFundingConfiguration(Arg.Is <FundingConfiguration>(x => x.FundingStreamId == fundingStreamId && x.FundingPeriodId == fundingPeriodId))
            .Returns(statusCode);

            FundingConfigurationService fundingConfigurationsService = CreateFundingConfigurationService(
                logger: logger,
                policyRepository: policyRepository,
                cacheProvider: cacheProvider);

            FundingConfigurationViewModel fundingConfigurationViewModel = CreateConfigurationModel();

            //Act
            IActionResult result = await fundingConfigurationsService.SaveFundingConfiguration("Action", "Controller", fundingConfigurationViewModel, fundingStreamId, fundingPeriodId);

            //Assert
            result
            .Should()
            .BeOfType <CreatedAtActionResult>();

            await cacheProvider
            .Received(1)
            .SetAsync(
                $"{CacheKeys.FundingConfig}{fundingStreamId}-{fundingPeriodId}",
                Arg.Is <FundingConfiguration>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId));

            await cacheProvider
            .Received(1)
            .RemoveAsync <List <FundingConfiguration> >($"{CacheKeys.FundingConfig}{fundingStreamId}");
        }
コード例 #31
0
 public PolicyController(IPolicyRepository repository)
 {
     _repository = repository;
 }
コード例 #32
0
            private void SetupMocks()
            {
                _templateRepository = Substitute.For <ITemplateRepository>();
                _existingTemplate   = new Template
                {
                    Name          = "Test",
                    TemplateId    = Guid.NewGuid().ToString(),
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XXX",
                        ShortName = "XXX",
                        Name      = "FundingSteam"
                    }
                };

                var version = new TemplateVersion
                {
                    Name            = "Old Test Name",
                    TemplateId      = _existingTemplate.TemplateId,
                    TemplateJson    = @"{""$schema"":""https://fundingschemas.blob.core.windows.net/schemas/funding-template-schema-1.1.json"",""schemaVersion"":""1.1"",""fundingTemplate"":{""fundingLines"":[{""templateLineId"":1,""type"":""Payment"",""name"":""Funding Line 1"",""fundingLineCode"":""DSG-001"",""fundingLines"":[],""calculations"":[]}],""fundingPeriod"":{""id"":""XX-2021"",""period"":""2021"",""name"":""XX-2021"",""type"":""FY"",""startDate"":""2020-04-01T00:00:00+00:00"",""endDate"":""2021-03-31T00:00:00+00:00""},""fundingStream"":{""code"":""DSG"",""name"":""DSG""},""fundingTemplateVersion"":""0.1""}}",
                    Version         = 1,
                    MinorVersion    = 1,
                    MajorVersion    = 0,
                    FundingPeriodId = _existingTemplate.FundingPeriod.Id,
                    FundingStreamId = _existingTemplate.FundingStream.Id,
                    SchemaVersion   = "1.1",
                    Status          = TemplateStatus.Published,
                    Author          = new Reference("111", "FirstTestUser")
                };

                _existingTemplate.Current = version;

                _templateRepository.GetAllTemplates().Returns(new List <Template> {
                    _existingTemplate
                });

                _policyRepository = Substitute.For <IPolicyRepository>();
                var fundingConfigurations = new List <FundingConfiguration>
                {
                    new FundingConfiguration
                    {
                        FundingStreamId = "XX",
                        FundingPeriodId = "2021"
                    },
                    new FundingConfiguration
                    {
                        FundingStreamId = "XX",
                        FundingPeriodId = "2122"
                    },
                    new FundingConfiguration
                    {
                        FundingStreamId = "XXX",
                        FundingPeriodId = "2021"
                    },
                    new FundingConfiguration
                    {
                        FundingStreamId = "XXX",
                        FundingPeriodId = "2122"
                    }
                };

                _policyRepository.GetFundingConfigurations().Returns(fundingConfigurations);

                _policyRepository.GetFundingStreams().Returns(new List <FundingStream>
                {
                    new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam XX"
                    },
                    new FundingStream
                    {
                        Id        = "XXX",
                        ShortName = "XXX",
                        Name      = "FundingSteam XXX"
                    }
                });
                _policyRepository.GetFundingPeriods().Returns(new List <FundingPeriod>
                {
                    new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period 20-21",
                        Type = FundingPeriodType.FY
                    },
                    new FundingPeriod
                    {
                        Id   = "2122",
                        Name = "Test Period 21-22",
                        Type = FundingPeriodType.FY
                    }
                });
            }
コード例 #33
0
 public CustomThrottlingMiddleware(OwinMiddleware next, ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger) :
     base(next, policy, policyRepository, repository, logger)
 { }
コード例 #34
0
 public PolicyManager()
 {
     _repo = new PolicyRepository();
 }
コード例 #35
0
 public InsuranceCompany(string name, IPolicyRepository policyRepository)
 {
     this.Name             = name;
     this.policyRepository = policyRepository;
 }
コード例 #36
0
 public GetPolicyInteractor(IPolicyRepository policyRepo)
 {
     _repo = policyRepo;
 }
コード例 #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PolicyRetrievalPoint"/> class.
 /// </summary>
 /// <param name="policyRepository">The policy Repository..</param>
 /// <param name="memoryCache">The cache handler </param>
 /// <param name="settings">The app settings</param>
 public PolicyRetrievalPoint(IPolicyRepository policyRepository, IMemoryCache memoryCache, IOptions <GeneralSettings> settings)
 {
     _repository      = policyRepository;
     _memoryCache     = memoryCache;
     _generalSettings = settings.Value;
 }
コード例 #38
0
 public BuyAdditionalCoverHandler(IPolicyRepository policyRepository)
 {
     this.policyRepository = policyRepository;
 }
コード例 #39
0
 public CustomThrottlingFilter(ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger)
     : base(policy, policyRepository, repository, logger)
 {
     this.QuotaExceededMessage = "API calls quota exceeded! maximum admitted {0} per {1}.";
 }
コード例 #40
0
 public PolicyController(IPolicyRepository repo)
 {
     _repo = repo;
 }
コード例 #41
-3
 /// <summary>
 /// Updates the policy object cached value
 /// </summary>
 /// <param name="policy">
 /// The policy.
 /// </param>
 /// <param name="cacheRepository">
 /// The policy repository.
 /// </param>
 public static void UpdatePolicy(ThrottlePolicy policy, IPolicyRepository cacheRepository)
 {
     cacheRepository.Save(GetPolicyKey(), policy);
 }