Ejemplo n.º 1
0
        public void TestEnumCustomFieldWithWhereAndStringConverter()
        {
            var configuratorCollection = new TestDataConfiguratorCollection <SourceTestData>(null, null, pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each());
                subConfigurator.Target(x => x.EnumCustomField).Required(x => new TestText
                {
                    Text = x.Info
                });
            });
            IStringConverter enumStringConverter = new EnumStringConverter();
            var converterCollection = new TestConverterCollection <TargetTestData, SourceTestData>(pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each(), x => x.As.Where(y => y.IsRemoved != true).Current());
                subConfigurator.Target(x => x.Info).Set(x => x.Info);
            }, enumStringConverter);
            var mutatorsTree    = configuratorCollection.GetMutatorsTree(MutatorsContext.Empty);
            var migratedTree    = converterCollection.Migrate(mutatorsTree, MutatorsContext.Empty);
            var mutatorWithPath = migratedTree.GetAllMutatorsWithPathsForWeb(x => x).Single();

            // Should be: Expression<Func<TargetTestData, AEnum>> expectedPathToMutator = x => (AEnum)(x.As.Each().CustomFields["EnumCustomField"].Value ?? AEnum.Unknown);
            Expression <Func <TargetTestData, AEnum> > expectedPathToMutator = x => (AEnum)(enumStringConverter.ConvertFromString <AEnum>((string)x.As.Where(y => y.IsRemoved != true).Each().CustomFields["EnumCustomField"].Value) ?? (object)AEnum.Unknown);

            mutatorWithPath.PathToMutator.AssertEquivalentExpressions(expectedPathToMutator.Body.Simplify());
            Expression <Func <TargetTestData, object> > expectedPathToNode = x => x.As.Each().CustomFields["EnumCustomField"].Value;

            mutatorWithPath.PathToNode.AssertEquivalentExpressions(expectedPathToNode.Body);

            var requiredIfConfiguration = (RequiredIfConfiguration)mutatorWithPath.Mutator;
            // Should be: Expression<Func<TargetTestData, AEnum>> expectedMutatorPath = x => (AEnum)(x.As.Current().CustomFields["EnumCustomField"].Value ?? AEnum.Unknown);
            Expression <Func <TargetTestData, AEnum> > expectedMutatorPath = x => (AEnum)(enumStringConverter.ConvertFromString <AEnum>((string)x.As.Where(y => y.IsRemoved != true).Current().CustomFields["EnumCustomField"].Value) ?? AEnum.Unknown);

            requiredIfConfiguration.Path.AssertEquivalentExpressions(expectedMutatorPath.Simplify());

            // Should be: Expression<Func<TargetTestData, bool>> expectedMutatorCondition = x => x.As.Each().IsRemoved != true;
            Expression <Func <TargetTestData, bool> > expectedMutatorCondition = null;

            requiredIfConfiguration.Condition.AssertEquivalentExpressions(expectedMutatorCondition);

            // Should be: Expression<Func<TargetTestData, TestText>> expectedMutatorMessage = x => new TestText {Text = x.As.Each().Info};
            Expression <Func <TargetTestData, TestText> > expectedMutatorMessage = x => new TestText {
                Text = x.As.Where(y => y.IsRemoved != true).Current().Info
            };

            requiredIfConfiguration.Message.AssertEquivalentExpressions(expectedMutatorMessage);
        }
Ejemplo n.º 2
0
        public void TestNormalFieldsWithWhere()
        {
            var configuratorCollection = new TestDataConfiguratorCollection <SourceTestData>(null, null, pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each());
                subConfigurator.Target(x => x.SomethingNormal).Required(x => new TestText
                {
                    Text = x.Info
                });
            });
            var converterCollection = new TestConverterCollection <TargetTestData, SourceTestData>(pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each(), x => x.As.Where(y => y.IsRemoved != true).Current());
                subConfigurator.Target(x => x.Info).Set(x => x.Info);
                subConfigurator.Target(x => x.SomethingNormal).Set(x => x.SomethingNormal);
            });
            var mutatorsTree = configuratorCollection.GetMutatorsTree(MutatorsContext.Empty);
            var migratedTree = converterCollection.Migrate(mutatorsTree, MutatorsContext.Empty);

            var mutatorWithPath = migratedTree.GetAllMutatorsWithPathsForWeb(x => x).Single();

            Expression <Func <TargetTestData, string> > expectedPathToMutator = x => x.As.Current().SomethingNormal;

            mutatorWithPath.PathToMutator.AssertEquivalentExpressions(expectedPathToMutator.Body);
            Expression <Func <TargetTestData, object> > expectedPathToNode = x => x.As.Each().SomethingNormal;

            mutatorWithPath.PathToNode.AssertEquivalentExpressions(expectedPathToNode.Body);

            var requiredIfConfiguration = (RequiredIfConfiguration)mutatorWithPath.Mutator;
            Expression <Func <TargetTestData, string> > expectedMutatorPath = x => x.As.Current().SomethingNormal;

            requiredIfConfiguration.Path.AssertEquivalentExpressions(expectedMutatorPath);
            Expression <Func <TargetTestData, bool> > expectedMutatorCondition = x => x.As.Current().IsRemoved != true;

            requiredIfConfiguration.Condition.AssertEquivalentExpressions(expectedMutatorCondition);
            Expression <Func <TargetTestData, TestText> > expectedMutatorMessage = x => new TestText {
                Text = x.As.Current().Info
            };

            requiredIfConfiguration.Message.AssertEquivalentExpressions(expectedMutatorMessage);
        }
Ejemplo n.º 3
0
        public void TestProperty()
        {
            var configuratorCollection = new TestDataConfiguratorCollection <SourceTestData>(null, null, pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each());
                subConfigurator.Target(x => x.Bs).Required(x => new TestText
                {
                    Text = x.Info
                });
            });
            var converterCollection = new TestConverterCollection <TargetTestData, SourceTestData>(pathFormatterCollection, configurator =>
            {
                var subConfigurator = configurator.GoTo(x => x.As.Each(), x => x.As.Where(y => y.IsRemoved != true).Current());
                subConfigurator.Target(x => x.Bs.Each().Value).Set(x => x.Bs.Current());
                subConfigurator.Target(x => x.Info).Set(x => x.Info);
            });
            var mutatorsTree = configuratorCollection.GetMutatorsTree(MutatorsContext.Empty);
            var migratedTree = converterCollection.Migrate(mutatorsTree, MutatorsContext.Empty);

            var mutatorWithPath = migratedTree.GetAllMutatorsWithPaths().Single();

            ((RequiredIfConfiguration)mutatorWithPath.Mutator).Condition.Compile();
            ((RequiredIfConfiguration)mutatorWithPath.Mutator).Message.Compile();
        }