Esempio n. 1
0
        public async Task ThenWillSendCommandToMarkRuleAsRead(MarkRuleAsReadCommand command)
        {
            //Act
            await _handler.Handle(command, CancellationToken.None);

            //Assert
            _service.Verify(s => s.MarkRuleAsRead(command.Id, command.RuleId, command.TypeOfRule), Times.Once);
        }
Esempio n. 2
0
        public void ThenWillThrowExceptionIfValidationFails(MarkRuleAsReadCommand command)
        {
            //Arrange
            _validator.Setup(v => v.ValidateAsync(It.IsAny <MarkRuleAsReadCommand>()))
            .ReturnsAsync(() => new ValidationResult {
                ValidationDictionary = new Dictionary <string, string> {
                    { "Test", "Error" }
                }
            });

            //Act
            Assert.ThrowsAsync <ValidationException>(() => _handler.Handle(command, CancellationToken.None));

            //Assert
            _service.Verify(s => s.MarkRuleAsRead(command.Id, command.RuleId, command.TypeOfRule), Times.Never);
        }
Esempio n. 3
0
        public async Task And_All_Fields_Not_Set_Then_Returns_All_Errors()
        {
            //Arrange
            var validator = new MarkRuleAsReadCommandValidator();

            var command = new  MarkRuleAsReadCommand();

            //Act
            var result = await validator.ValidateAsync(command);

            //Assert
            result.IsValid().Should().BeFalse();
            result.ValidationDictionary.Count.Should().Be(3);
            result.ValidationDictionary
            .Should().ContainKey(nameof(MarkRuleAsReadCommand.Id))
            .And.ContainKey(nameof(MarkRuleAsReadCommand.RuleId))
            .And.ContainKey(nameof(MarkRuleAsReadCommand.TypeOfRule));
        }
Esempio n. 4
0
        public async Task And_All_Fields_For_Employer_Then_Command_Is_Valid()
        {
            //Arrange
            var validator = new MarkRuleAsReadCommandValidator();

            var command = new  MarkRuleAsReadCommand
            {
                Id         = Guid.NewGuid().ToString(),
                RuleId     = 1,
                TypeOfRule = RuleType.GlobalRule
            };

            //Act
            var result = await validator.ValidateAsync(command);

            //Assert
            result.IsValid().Should().BeTrue();
            result.ValidationDictionary.Count.Should().Be(0);
        }
        public async Task <IActionResult> SaveRuleNotificationChoice(long ruleId, RuleType typeOfRule, bool markRuleAsRead)
        {
            if (!markRuleAsRead)
            {
                return(RedirectToRoute(RouteNames.EmployerStart));
            }

            var userAccountIdClaim = HttpContext.User.Claims.First(c => c.Type.Equals(EmployerClaims.IdamsUserIdClaimTypeIdentifier));

            var userId = userAccountIdClaim.Value;

            var command = new MarkRuleAsReadCommand
            {
                Id         = userId,
                RuleId     = ruleId,
                TypeOfRule = typeOfRule
            };

            await _mediator.Send(command);

            return(RedirectToRoute(RouteNames.EmployerStart));
        }
        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));
        }