Ejemplo n.º 1
0
 public static IEnumerable<ValidationResult> Persist(IDataContext context,
     TakeRateFilter filter,
     FluentValidation.Results.ValidationResult results,
     bool global)
 {
     return context.TakeRate.PersistValidationErrors(filter, results, global);
 }
            public void WhenIdBlank_ThenThrows()
            {
                dto.Id = string.Empty;

                Assert.Throws <ValidationException>(FluentValidation <UpdateUserAccount> .NotEmptyErrorMessage(x => x.Id),
                                                    () => validator.ValidateAndThrow(dto));
            }
            public void WhenGrantTypeIsNull_ThenThrows()
            {
                dto.GrantType = null;

                Assert.Throws <ValidationException>(
                    FluentValidation <CreateAccessToken> .NotNullErrorMessage(x => x.GrantType),
                    () => validator.ValidateAndThrow(dto));
            }
Ejemplo n.º 4
0
            public void WhenIdIsNull_ThenThrows()
            {
                var dto = new GetUserAccount
                {
                    Id = null,
                };

                Assert.Throws <ValidationException>(FluentValidation <GetUserAccount> .NotEmptyErrorMessage(x => x.Id),
                                                    () => validator.ValidateAndThrow(dto));
            }
            public void WhenNameIsNull_ThenThrows()
            {
                var dto = new CreateClientApplication
                {
                    Name = null,
                };

                Assert.Throws <ValidationException>(
                    FluentValidation <CreateClientApplication> .NotNullErrorMessage(x => x.Name),
                    () => validator.ValidateAndThrow(dto));
            }
            public void WhenIdIsNull_ThenThrows()
            {
                var dto = new DeleteClientApplication
                {
                    Id = null,
                };

                Assert.Throws <ValidationException>(
                    FluentValidation <DeleteClientApplication> .NotEmptyErrorMessage(x => x.Id),
                    () => validator.ValidateAndThrow(dto));
            }
Ejemplo n.º 7
0
 public GenreService(
     IEntityRepository<Genre> genreRepository
     ,
     FluentValidation.IValidatorFactory validatorFactory
     ,
     IMappingEngine mapper
     )
 {
     _genreRepository = genreRepository;
     _hasPermission = validatorFactory.GetValidator<Genre>();
     _mapper = mapper;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Run the specified validator, tag and formattedMessage.
 /// </summary>
 /// <param name="validator">A validator.</param>
 /// <param name="tag">A tag.</param>
 /// <param name="formattedMessage">Formatted message.</param>
 public void Run(FluentValidation.Validators.IPropertyValidator validator, HtmlTag tag, string formattedMessage)
 {
     if (validator is CpfValidator)
     {
         tag.Data("val-cpf", formattedMessage);
     }
     else if (validator is ValidDate)
     {
         tag.Data("val-dateBR", formattedMessage);
     }
     else if (validator is ValidNomeConjuge)
     {
         tag.Data("val-nomeConjuge", formattedMessage);
     }
 }
Ejemplo n.º 9
0
        public ServiceBase(
            IRepositoryBase <TEntity> _repository,
            INotificationManager _notificationManager,
            IMapper _mapper,
            IFluentValidation <TEntity> _fluentValidation,
            IAuthService _authService
            ) : base(_notificationManager)
        {
            repository       = _repository;
            mapper           = _mapper;
            fluentValidation = _fluentValidation;
            authService      = _authService;

            // configure Validation Base
            validationBase = new FluentValidation <TEntity>();
            validationBase.SetValidation(fluentValidation.GetValidations());
        }
        public IEnumerable<ValidationResult> PersistValidationErrors(TakeRateFilter filter, FluentValidation.Results.ValidationResult validationResult, bool global = false)
        {
            var results = new List<ValidationResult>();
            
            _takeRateDataStore.FdpValidationClear(filter);

            foreach (var validationError in validationResult.Errors)
            {
                var state = (ValidationState)validationError.CustomState;
                var validationData = new ValidationResult
                {
                    TakeRateId = state.TakeRateId,

                    ValidationRule = state.ValidationRule,

                    FdpVolumeDataItemId = state.FdpVolumeDataItemId,
                    FdpTakeRateSummaryId = state.FdpTakeRateSummaryId,
                    FdpTakeRateFeatureMixId = state.FdpTakeRateFeatureMixId,
                    FdpChangesetDataItemId = state.FdpChangesetDataItemId,

                    MarketId = state.MarketId,
                    ModelId = state.ModelId,
                    FdpModelId = state.FdpModelId,
                    FeatureId = state.FeatureId,
                    FdpFeatureId = state.FdpFeatureId,
                    FeaturePackId = state.FeaturePackId,
                    ExclusiveFeatureGroup = state.ExclusiveFeatureGroup,

                    Message = validationError.ErrorMessage
                };

                validationData = _takeRateDataStore.FdpValidationPersist(validationData, global);
                results.Add(validationData);

                foreach (var childState in state.ChildStates)
                {
                    validationData = new ValidationResult
                    {
                        TakeRateId = childState.TakeRateId,

                        FdpVolumeDataItemId = childState.FdpVolumeDataItemId,
                        FdpTakeRateSummaryId = childState.FdpTakeRateSummaryId,
                        FdpTakeRateFeatureMixId = childState.FdpTakeRateFeatureMixId,
                        FdpChangesetDataItemId = childState.FdpChangesetDataItemId,

                        ValidationRule = state.ValidationRule,

                        MarketId = childState.MarketId,
                        ModelId = childState.ModelId,
                        FdpModelId = childState.FdpModelId,
                        FeatureId = childState.FdpFeatureId,
                        FdpFeatureId = childState.FdpFeatureId,
                        FeaturePackId = childState.FeaturePackId,

                        Message = validationError.ErrorMessage
                    };
                    validationData = _takeRateDataStore.FdpValidationPersist(validationData, global);
                    results.Add(validationData);
                }
            }
            
            return results;
        }
Ejemplo n.º 11
0
 public FVValidationFailureAdapter(FluentValidation.Results.ValidationFailure failure)
 {
     this._failure = failure;
 }
 public static void AddModelErrors(this ModelStateDictionary state,
     FluentValidation.ValidationException exception)
 {
     foreach (var error in exception.Errors)
         state.AddModelError(error.PropertyName, error.ErrorMessage);
 }
Ejemplo n.º 13
0
 public FVValidationResultAdapter(FluentValidation.Results.ValidationResult result)
 {
     _result = result;
 }
 public FluentValidationValidator(FluentValidation.IValidator validator)
 {
     _validator = validator;
 }