Ejemplo n.º 1
0
        private Aspect DefineDateTimeAspects(PropertyInfo property, AspectModel aspectModel, Aspect currentAspect)
        {
            if (property.GetCustomAttribute <EarliestDateAttribute>() != null)
            {
                currentAspect.EarliestDateTime = property.GetCustomAttribute <EarliestDateAttribute>().EarliestDate;
            }
            else if (aspectModel != null)
            {
                currentAspect.EarliestDateTime = aspectModel.EarliestDateTime;
            }
            else
            {
                currentAspect.EarliestDateTime = DefaultValues.DEFAULTEARLIESTDATETIME;
            }

            if (property.GetCustomAttribute <LatestDateAttribute>() != null)
            {
                currentAspect.LatestDateTime = property.GetCustomAttribute <LatestDateAttribute>().LatestDateTime;
            }
            else if (aspectModel != null)
            {
                currentAspect.LatestDateTime = aspectModel.LatestDateTime;
            }
            else
            {
                currentAspect.LatestDateTime = DefaultValues.DEFAULTLATESTDATETIME;
            }
            return(currentAspect);
        }
Ejemplo n.º 2
0
        private Aspect DefineAspect(PropertyInfo property, AspectModel aspectModel)
        {
            Aspect currentAspect = new Aspect();

            currentAspect = DefineBaseAspects(property, aspectModel, currentAspect);

            bool isCollection = (property.PropertyType.GetInterfaces()
                                 .Where(type => type.Namespace.Contains("Collection")).Count() > 0 ||
                                 property.PropertyType.IsArray);

            if (property.PropertyType == typeof(string))
            {
                currentAspect = DefineStringAspects(property, aspectModel, currentAspect);
            }
            else if (isCollection)
            {
                currentAspect = DefineCollectionAspects(property, aspectModel, currentAspect);
                if (currentAspect.ConcreteCollectionItemType == typeof(DateTime))
                {
                    currentAspect = DefineDateTimeAspects(property, aspectModel, currentAspect);
                }
            }
            else
            {
                if (property.PropertyType == typeof(DateTime))
                {
                    currentAspect = DefineDateTimeAspects(property, aspectModel, currentAspect);
                }
            }

            return(currentAspect);
        }
Ejemplo n.º 3
0
        private Aspect DefineCollectionAspects(PropertyInfo property, AspectModel aspectModel, Aspect currentAspect)
        {
            Aspect newCurrentAspect = currentAspect;

            if (property.GetCustomAttribute <MinimumLengthAttribute>() != null)
            {
                currentAspect.MinimumLength = property.GetCustomAttribute <MinimumLengthAttribute>().MinimumLength;
            }
            else if (aspectModel != null)
            {
                currentAspect.MinimumLength = aspectModel.MinimumLength;
            }
            else
            {
                currentAspect.MinimumLength = DefaultValues.DEFAULTMINIMUMLENGTH;
            }

            if (property.GetCustomAttribute <MaximumLengthAttribute>() != null)
            {
                currentAspect.MaximumLength = property.GetCustomAttribute <MaximumLengthAttribute>().MaximumLength;
            }
            else if (aspectModel != null)
            {
                currentAspect.MaximumLength = aspectModel.MaximumLength;
            }
            else
            {
                currentAspect.MaximumLength = DefaultValues.DEFAULTMAXIMUMLENGTH;
            }

            if (property.GetCustomAttribute <CollectionItemConcreteTypeAttribute>() != null)
            {
                currentAspect.ConcreteCollectionItemType = property.GetCustomAttribute <CollectionItemConcreteTypeAttribute>().ConcreteType;
            }
            else
            {
                if (property.PropertyType.BaseType == typeof(Array))
                {
                    throw new ArgumentException($"The specified type in property {property.DeclaringType.Name}.{property.Name} is an array. Please switch to a List<T> instead.");
                }
                else
                {
                    currentAspect.ConcreteCollectionItemType = property.PropertyType.GenericTypeArguments.First();
                    if (!currentAspect.ConcreteCollectionItemType.HasDefaultConstructor())
                    {
                        throw new ArgumentException($"The specified Concrete type of the items in the collection specified in property {property.DeclaringType.Name}.{property.Name} needs to be concrete and have a parameterless constructor.");
                    }
                }
            }

            List <MethodInfo> validator = property.DeclaringType.GetMethods()
                                          .Where(method => IsCollectionItemValidator(property, method)).ToList();

            if (validator.Count == 1)
            {
                currentAspect.CollectionItemValidator = validator.First();
            }
            return(newCurrentAspect);
        }
Ejemplo n.º 4
0
 private Aspect DefineStringAspects(PropertyInfo property, AspectModel aspectModel, Aspect currentAspect)
 {
     if (property.GetCustomAttribute <StringTypeAttribute>() != null)
     {
         currentAspect.StringType = property.GetCustomAttribute <StringTypeAttribute>().StringType;
         if (currentAspect.StringType == StringType.Regex)
         {
             currentAspect.RegexPattern = property.GetCustomAttribute <StringTypeAttribute>().RegexPattern;
         }
     }
     else if (aspectModel != null)
     {
         currentAspect.StringType = aspectModel.StringType;
         if (currentAspect.StringType == StringType.Regex)
         {
             currentAspect.RegexPattern = aspectModel.RegexPattern;
         }
     }
     else
     {
         currentAspect.StringType = DefaultValues.DEFAULTSTRINGTYPE;
     }
     return(currentAspect);
 }
Ejemplo n.º 5
0
        public static void CreateMockObjects(TestContext context)
        {
            AspectModel aspect1 = new AspectModel()
            {
                PropertyName = "testString1",
                ClassName    = "TestObjectAlpha",
                Required     = true,
                Minimum      = 1,
                Maximum      = 5,
                StringType   = StringType.AlphaNumeric
            };

            AspectModel aspect2 = new AspectModel()
            {
                PropertyName = "testInt1",
                Required     = true,
                Maximum      = 10
            };

            AspectModel aspect3 = new AspectModel()
            {
                PropertyName = "testString2",
                Required     = false,
                Minimum      = 3,
                Maximum      = 25,
                StringType   = StringType.All
            };

            AspectModel aspect4 = new AspectModel()
            {
                PropertyName = "testBeta1",
                Required     = true
            };

            AspectModel aspect5 = new AspectModel()
            {
                PropertyName = "testBool1",
                Required     = true
            };

            AspectModel aspect6 = new AspectModel()
            {
                PropertyName = "testString1",
                ClassName    = "TestObjectBeta",
                Required     = false,
                Minimum      = 6,
                Maximum      = 40,
                StringType   = StringType.Regex,
                RegexPattern = "Gr8 [A-Za-z]{2,36}"
            };

            AspectModel aspect7 = new AspectModel()
            {
                PropertyName     = "testDateTime1",
                Minimum          = DefaultValues.DEFAULTMINIMUM,
                MinimumLength    = DefaultValues.DEFAULTMINIMUMLENGTH,
                Maximum          = DefaultValues.DEFAULTMAXIMUM,
                MaximumLength    = DefaultValues.DEFAULTMAXIMUMLENGTH,
                EarliestDateTime = new DateTime(2015, 1, 1, 0, 0, 0),
                LatestDateTime   = new DateTime(2016, 1, 1, 0, 0, 0),
                Required         = true
            };

            AspectModel aspect8 = new AspectModel()
            {
                PropertyName  = "testIList1",
                Minimum       = DefaultValues.DEFAULTMINIMUM,
                MinimumLength = DefaultValues.DEFAULTMINIMUMLENGTH,
                Maximum       = DefaultValues.DEFAULTMAXIMUM,
                MaximumLength = DefaultValues.DEFAULTMAXIMUMLENGTH,
                Required      = false
            };

            AspectModel aspect9 = new AspectModel()
            {
                PropertyName  = "deltas",
                Minimum       = DefaultValues.DEFAULTMINIMUM,
                MinimumLength = 1,
                Maximum       = DefaultValues.DEFAULTMAXIMUM,
                MaximumLength = 5,
                Required      = true
            };

            AspectModel aspect10 = new AspectModel()
            {
                PropertyName = "testString1",
                ClassName    = "TestObjectDelta",
                Minimum      = 0,
                Maximum      = 25,
                Required     = false
            };

            AspectModel aspect11 = new AspectModel()
            {
                PropertyName  = "testStringArray1",
                Minimum       = 0,
                Maximum       = 25,
                MinimumLength = 1,
                MaximumLength = 10,
                Required      = false,
                StringType    = StringType.Alphabetic
            };

            MockAspectCollection = new AspectModelCollection();
            MockAspectCollection.Models.Add(aspect1);
            MockAspectCollection.Models.Add(aspect2);
            MockAspectCollection.Models.Add(aspect3);
            MockAspectCollection.Models.Add(aspect4);
            MockAspectCollection.Models.Add(aspect5);
            MockAspectCollection.Models.Add(aspect6);
            MockAspectCollection.Models.Add(aspect7);
            MockAspectCollection.Models.Add(aspect8);
            MockAspectCollection.Models.Add(aspect9);
            MockAspectCollection.Models.Add(aspect10);
            MockAspectCollection.Models.Add(aspect11);
        }
Ejemplo n.º 6
0
        private Aspect DefineBaseAspects(PropertyInfo property, AspectModel aspectModel, Aspect currentAspect)
        {
            currentAspect.Property = property;
            if (property.GetCustomAttribute <RequiredAttribute>() != null)
            {
                currentAspect.Required = property.GetCustomAttribute <RequiredAttribute>().IsRequired;
            }
            else if (aspectModel != null)
            {
                currentAspect.Required = aspectModel.Required;
            }
            else
            {
                currentAspect.Required = false;
            }

            if (property.GetCustomAttribute <MinimumAttribute>() != null)
            {
                currentAspect.Minimum = property.GetCustomAttribute <MinimumAttribute>().MinimumSize;
            }
            else if (aspectModel != null)
            {
                currentAspect.Minimum = aspectModel.Minimum;
            }
            else
            {
                currentAspect.Minimum = DefaultValues.DEFAULTMINIMUM;
            }

            if (property.GetCustomAttribute <MaximumAttribute>() != null)
            {
                currentAspect.Maximum = property.GetCustomAttribute <MaximumAttribute>().MaximumSize;
            }
            else if (aspectModel != null)
            {
                currentAspect.Maximum = aspectModel.Maximum;
            }
            else
            {
                currentAspect.Maximum = DefaultValues.DEFAULTMAXIMUM;
            }

            if (property.GetCustomAttribute <ConcreteTypeAttribute>() != null)
            {
                currentAspect.ConcreteType = property.GetCustomAttribute <ConcreteTypeAttribute>().ConcreteType;
            }
            else
            {
                currentAspect.ConcreteType = property.PropertyType;
            }

            if (property.GetCustomAttribute <ValueAttribute>() != null)
            {
                currentAspect.ValueType = property.GetCustomAttribute <ValueAttribute>().ValueType;
            }
            else
            {
                currentAspect.ValueType = Enums.ValueType.DefaultValue;
            }

            List <MethodInfo> validator = property.DeclaringType.GetMethods()
                                          .Where(method => IsPropertyValidator(property, method)).ToList();

            if (validator.Count == 1)
            {
                currentAspect.Validator = validator.First();
            }
            return(currentAspect);
        }