Exemple #1
0
 protected EqualsToConfiguration(Type converterType, Type type, LambdaExpression value, StaticValidatorConfiguration validator)
     : base(type)
 {
     ConverterType = converterType;
     Value         = value;
     Validator     = validator;
 }
        public void TestSetWithValidator()
        {
            configurator.Target(d => d.RootS).Set(s => s.RootS, x => x, x => ValidationResult.Ok);
            var sourceValidator = StaticValidatorConfiguration.Create <SourceRoot>(MutatorsCreator.Sharp, "SetWithValidator", 0, null,
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS),
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS),
                                                                                   (Expression <Func <string, ValidationResult> >)(x => ValidationResult.Ok));
            var equalsToConfiguration = EqualsToConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, string> >)(s => s.RootS), sourceValidator);

            AssertEquivalentConfigurations(equalsToConfiguration);
            AssertEquivalentPaths(d => d.RootS);
        }
        public void TestSetWithValueAndValidatorAndConverter()
        {
            var validationResult = ValidationResult.Warning(new TestText {
                Text = "test text"
            });

            configurator.Target(d => d.RootS).Set(s => s.RootS, x => x + "abc", x => x + "def", x => validationResult);
            var sourceValidator = StaticValidatorConfiguration.Create <SourceRoot>(MutatorsCreator.Sharp, "SetWithValidator", 0, null,
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS),
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS + "abc"),
                                                                                   (Expression <Func <string, ValidationResult> >)(x => validationResult));
            var equalsToConfiguration = EqualsToConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, string> >)(s => s.RootS + "abc" + "def"), sourceValidator);

            AssertEquivalentConfigurations(equalsToConfiguration);
            AssertEquivalentPaths(d => d.RootS);
        }
        public void TestSetWithMessage()
        {
            configurator.Target(d => d.RootS).Set(s => s.RootS, x => x + "def", x => x.Length == 5, s => new TestText {
                Text = "text!"
            }, 0, ValidationResultType.Warning);
            var sourceValidator = StaticValidatorConfiguration.Create <SourceRoot>(MutatorsCreator.Sharp, "SetWithValidator", 0, null,
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS),
                                                                                   (Expression <Func <SourceRoot, string> >)(x => x.RootS),
                                                                                   (Expression <Func <string, ValidationResult> >)(x => (bool?)(x.Length == 5) == true
                                                                                                                                        ? new ValidationResult(ValidationResultType.Warning, new TestText {
                Text = "text!"
            })
                                                                                                                                        : ValidationResult.Ok));
            var equalsToConfiguration = EqualsToConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, string> >)(s => s.RootS + "def"), sourceValidator);

            AssertEquivalentConfigurations(equalsToConfiguration);
            AssertEquivalentPaths(d => d.RootS);
        }
Exemple #5
0
        public static ConverterConfigurator <TSourceRoot, TSourceChild, TDestRoot, TDestChild, TDestValue> Set <TSourceRoot, TSourceChild, TSourceNode, TSourceValue, TDestRoot, TDestChild, TDestValue>(
            this ConverterConfigurator <TSourceRoot, TSourceChild, TDestRoot, TDestChild, TDestValue> configurator,
            Expression <Func <TSourceChild, TSourceNode> > node,
            Expression <Func <TSourceNode, TSourceValue> > value,
            Expression <Func <TSourceValue, TDestValue> > converter,
            Expression <Func <TSourceNode, ValidationResult> > validator,
            int priority = 0)
        {
            var pathToSourceChild      = (Expression <Func <TSourceRoot, TSourceChild> >)configurator.PathToSourceChild.ReplaceEachWithCurrent();
            var nodeFromRoot           = pathToSourceChild.Merge(node);
            var valueFromRoot          = nodeFromRoot.Merge(value);
            var convertedValue         = converter == null ? (LambdaExpression)valueFromRoot : valueFromRoot.Merge(converter);
            var validatorConfiguration = validator == null
                                             ? null
                                             : StaticValidatorConfiguration.Create(MutatorsCreator.Sharp, "SetWithValidator", priority,
                                                                                   null, nodeFromRoot, valueFromRoot, validator);

            configurator.SetMutator(EqualsToConfiguration.Create(configurator.Root.ConfiguratorType, typeof(TDestRoot), convertedValue, validatorConfiguration));
            return(configurator);
        }
 public static EqualsToIfConfiguration Create(Type type, LambdaExpression condition, LambdaExpression value, StaticValidatorConfiguration validator)
 {
     return(new EqualsToIfConfiguration(type, Prepare(condition), Prepare(value), validator));
 }
 public EqualsToIfConfiguration(Type type, LambdaExpression condition, LambdaExpression value, StaticValidatorConfiguration validator)
     : base(type, value, validator)
 {
     Condition = condition;
 }
 internal static EqualsToIfConfiguration Create <T>(LambdaExpression condition, LambdaExpression value, StaticValidatorConfiguration validator)
 {
     return(Create(null, typeof(T), condition, value, validator));
 }
 public static EqualsToConfiguration Create <TData>(LambdaExpression value, StaticValidatorConfiguration validator = null)
 {
     return(new EqualsToConfiguration(typeof(TData), Prepare(value), validator));
 }
Exemple #10
0
 public static EqualsToConfiguration Create(Type converterType, Type type, LambdaExpression value, StaticValidatorConfiguration validator)
 {
     return(new EqualsToConfiguration(converterType, type, Prepare(value), validator));
 }
Exemple #11
0
 internal static EqualsToConfiguration Create <TData>(LambdaExpression value, StaticValidatorConfiguration validator = null)
 {
     return(Create <TData>(null, value, validator));
 }