public async Task Then_The_GlobalRules_Are_Returned_For_That_Account() { //Act var result = await _service.GetAccountFundingRules(ExpectedAccountId); //Assert Assert.IsNotNull(result); Assert.AreEqual(_expectedGlobalRules, result.GlobalRules); }
public async Task <GetAccountFundingRulesResult> Handle(GetAccountFundingRulesQuery request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request); if (!validationResult.IsValid()) { throw new ValidationException(validationResult.ConvertToDataAnnotationsValidationResult(), null, null); } var result = new GetAccountFundingRulesResult(); var rules = await _fundingRulesService.GetAccountFundingRules(request.AccountId); result.AccountFundingRules = rules; result.ActiveRule = rules?.GlobalRules?.FirstOrDefault(x => x != null)?.RuleType; return(result); }
public async Task <ValidationResult> ValidateAsync(CacheReservationEmployerCommand command) { var result = new ValidationResult(); if (command.Id == Guid.Empty) { result.AddError(nameof(command.Id)); } if (command.AccountId == default(long)) { result.AddError(nameof(command.AccountId)); } else { var accountFundingRulesApiResponse = await _rulesService.GetAccountFundingRules(command.AccountId); if (accountFundingRulesApiResponse.GlobalRules.Any(c => c != null && c.RuleType == GlobalRuleType.ReservationLimit) && accountFundingRulesApiResponse.GlobalRules.Count(c => c.RuleType == GlobalRuleType.ReservationLimit) > 0) { result.FailedRuleValidation = true; } var globalRulesApiResponse = await _rulesService.GetFundingRules(); if (globalRulesApiResponse.GlobalRules != null && globalRulesApiResponse.GlobalRules.Any(c => c != null && c.RuleType == GlobalRuleType.FundingPaused) && globalRulesApiResponse.GlobalRules.Count(c => c.RuleType == GlobalRuleType.FundingPaused) > 0) { result.FailedGlobalRuleValidation = true; } // eoi var queryResult = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = command.AccountId }); if (queryResult.AccountLegalEntities.Any(entity => !entity.IsLevy && entity.AgreementType != AgreementType.NonLevyExpressionOfInterest)) { result.FailedEoiCheck = true; return(result); } } if (command.AccountLegalEntityId == default(long)) { result.AddError(nameof(command.AccountLegalEntityId)); } if (string.IsNullOrWhiteSpace(command.AccountLegalEntityName)) { result.AddError(nameof(command.AccountLegalEntityName)); } if (string.IsNullOrWhiteSpace(command.AccountLegalEntityPublicHashedId)) { result.AddError(nameof(command.AccountLegalEntityPublicHashedId)); } if (command.UkPrn.HasValue && !command.IsEmptyCohortFromSelect) { var accounts = await _mediator.Send( new GetTrustedEmployersQuery { UkPrn = command.UkPrn.Value }); var matchedAccount = accounts?.Employers?.SingleOrDefault(employer => employer.AccountLegalEntityPublicHashedId == command.AccountLegalEntityPublicHashedId); result.FailedAuthorisationValidation = matchedAccount == null; } return(result); }