private static void Transform <T>(T objectToTransform, string key, TransformValueManager valueManager)
        {
            var typeOfTClass = typeof(T);

            if (key == null)
            {
                key = typeOfTClass.Name;
            }

            var properties = typeOfTClass.GetProperties();

            foreach (var propertyInfo in properties)
            {
                var transformationAttribute = propertyInfo.GetCustomAttributes(true).OfType <TransformValueAttribute>().FirstOrDefault();
                if (transformationAttribute == null)
                {
                    continue;
                }

                var fieldType = ResolveFieldType(transformationAttribute.FieldType, propertyInfo.PropertyType);
                var newValue  = RandomValueGenerator.Generate(fieldType);

                var propertyKey = GeneratePropertyKey(key, propertyInfo.Name);
                var property    = new TransformedProperty(propertyKey, propertyInfo.GetValue(objectToTransform), newValue);
                valueManager.Add(property);
                propertyInfo.SetValue(objectToTransform, newValue);
            }
        }
Exemple #2
0
 private void GuardAgainstDuplicatedEntity(TransformedProperty property)
 {
     if (EntityWithKeyHasBeenAddedBefore(property))
     {
         throw new Exception($"Duplicate key detected : {property.Key}");
     }
 }
Exemple #3
0
 public void Add(TransformedProperty property)
 {
     GuardAgainstDuplicatedEntity(property);
     _entities.Add(property);
 }
Exemple #4
0
 private bool EntityWithKeyHasBeenAddedBefore(TransformedProperty property)
 {
     return(_entities.Any(a => a.SameKeyAs(property)));
 }
Exemple #5
0
 public bool SameKeyAs(TransformedProperty property)
 {
     return(this.Key == property.Key);
 }