public async Task Then_Calls_Cache_Service_To_Save_Reservation(CacheReservationEmployerCommand command)
        {
            GetAccountFundingRulesApiResponse response = new GetAccountFundingRulesApiResponse()
            {
                GlobalRules = new List <GlobalRule>()
            };

            command.UkPrn = null;
            command.EmployerHasSingleLegalEntity = true;

            _mockFundingRulesService.Setup(c => c.GetAccountFundingRules(It.IsAny <long>()))
            .ReturnsAsync(response);

            //Act
            await _commandHandler.Handle(command, CancellationToken.None);

            //Assert
            _mockCacheStorageService.Verify(service => service.SaveToCache(
                                                It.IsAny <string>(),
                                                It.Is <CachedReservation>(c => c.Id.Equals(command.Id) &&
                                                                          c.AccountId.Equals(command.AccountId) &&
                                                                          c.AccountLegalEntityId.Equals(command.AccountLegalEntityId) &&
                                                                          c.AccountLegalEntityName.Equals(command.AccountLegalEntityName) &&
                                                                          c.AccountLegalEntityPublicHashedId.Equals(command.AccountLegalEntityPublicHashedId) &&
                                                                          c.AccountName.Equals(command.AccountName) &&
                                                                          c.CohortRef.Equals(command.CohortRef) &&
                                                                          c.UkPrn.Equals(command.UkPrn) &&
                                                                          c.IsEmptyCohortFromSelect.Equals(command.IsEmptyCohortFromSelect) &&
                                                                          c.EmployerHasSingleLegalEntity.Equals(command.EmployerHasSingleLegalEntity)),
                                                1));
        }
示例#2
0
        public async Task WhenRulesAreValid_ThenTheRulesAreReturned(
            [Frozen] long accountId)
        {
            //Arrange
            var expectedRules = new GetAccountFundingRulesApiResponse()
            {
                GlobalRules = new List <GlobalRule>()
                {
                    new GlobalRule()
                    {
                        Id       = accountId,
                        RuleType = GlobalRuleType.ReservationLimit,
                    }
                }
            };

            _query = new GetAccountFundingRulesQuery()
            {
                AccountId = accountId
            };

            _validator.Setup(m => m.ValidateAsync(_query))
            .ReturnsAsync(new ValidationResult());

            _fundingRulesService.Setup(m => m.GetAccountFundingRules(accountId)).ReturnsAsync(expectedRules);
            _handler = new GetAccountFundingRulesQueryHandler(_fundingRulesService.Object, _validator.Object);

            //Act
            var result = await _handler.Handle(_query, CancellationToken.None);

            //Assert
            Assert.AreEqual(expectedRules, result.AccountFundingRules);
            Assert.AreEqual(expectedRules.GlobalRules.First(), result.AccountFundingRules.GlobalRules.First());
        }
示例#3
0
        public async Task IfNoGlobalRulesReturned_ThenSetsActiveRulePropertyToNull(
            [Frozen] long accountId)

        {
            //Arrange
            var expectedRules = new GetAccountFundingRulesApiResponse {
                GlobalRules = new List <GlobalRule>()
            };

            _query = new GetAccountFundingRulesQuery {
                AccountId = accountId
            };

            _validator.Setup(m => m.ValidateAsync(_query))
            .ReturnsAsync(new ValidationResult());

            _fundingRulesService.Setup(m => m.GetAccountFundingRules(accountId)).ReturnsAsync(expectedRules);
            _handler = new GetAccountFundingRulesQueryHandler(_fundingRulesService.Object, _validator.Object);

            //Act
            var result = await _handler.Handle(_query, CancellationToken.None);

            //Assert
            Assert.IsNull(result.ActiveRule);
        }
示例#4
0
        public async Task If_Multiple_GlobalRulesReturned_ThenSetsActiveRulePropertyInResult(
            [Frozen] long accountId)

        {
            //Arrange
            var expectedRules = new GetAccountFundingRulesApiResponse()
            {
                GlobalRules = new List <GlobalRule>()
                {
                    null,
                    new GlobalRule
                    {
                        Id       = accountId,
                        RuleType = GlobalRuleType.ReservationLimit,
                    }
                }
            };

            _query = new GetAccountFundingRulesQuery {
                AccountId = accountId
            };

            _validator.Setup(m => m.ValidateAsync(_query))
            .ReturnsAsync(new ValidationResult());

            _fundingRulesService.Setup(m => m.GetAccountFundingRules(accountId)).ReturnsAsync(expectedRules);
            _handler = new GetAccountFundingRulesQueryHandler(_fundingRulesService.Object, _validator.Object);

            //Act
            var result = await _handler.Handle(_query, CancellationToken.None);

            //Assert
            Assert.AreEqual(expectedRules.GlobalRules.First(x => x != null).RuleType, result.ActiveRule);
        }
        public async Task Then_It_Validates_The_Command(CacheReservationEmployerCommand command)
        {
            var response = new GetAccountFundingRulesApiResponse()
            {
                GlobalRules = new List <GlobalRule>()
            };

            _mockFundingRulesService.Setup(m => m.GetAccountFundingRules(It.IsAny <long>()))
            .ReturnsAsync(response);

            //Act
            await _commandHandler.Handle(command, CancellationToken.None);

            //Assert
            _mockValidator.Verify(validator => validator.ValidateAsync(command), Times.Once);
        }
示例#6
0
        public void WhenRulesAreNotValid_ThenValidationExcetionIsThrown(
            [Frozen] long accountId)
        {
            //Arrange
            var expectedRules = new GetAccountFundingRulesApiResponse()
            {
                GlobalRules = new List <GlobalRule>()
                {
                    new GlobalRule()
                    {
                        Id       = accountId,
                        RuleType = GlobalRuleType.ReservationLimit,
                    }
                }
            };

            _query = new GetAccountFundingRulesQuery()
            {
                AccountId = accountId
            };

            _validator.Setup(m => m.ValidateAsync(_query)).ReturnsAsync(new ValidationResult
            {
                ValidationDictionary = new Dictionary <string, string>()
                {
                    ["Error"] = "Error"
                }
            });

            _fundingRulesService.Setup(m => m.GetAccountFundingRules(accountId)).ReturnsAsync(expectedRules);
            _handler = new GetAccountFundingRulesQueryHandler(_fundingRulesService.Object, _validator.Object);

            //Assert + Act
            Assert.ThrowsAsync <ValidationException>(async() =>
                                                     await _handler.Handle(_query, new CancellationToken()));
        }