Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 81 additions & 59 deletions src/GenFu/FillerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ public class FillerManager
private IDictionary<Type, IPropertyFiller> _genericPropertyFillersByPropertyType;
private IList<IPropertyFiller> _propertyFillers;

static ReaderWriterLockSlim rwl = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

private ReaderWriterLockSlim rwl = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
public GenFuInstance GenFu { get; }

public FillerManager()
{
GenFu = A.GenFuInstance;
ResetFillers();
}

public FillerManager(GenFuInstance genFu)
{
GenFu = genFu;
ResetFillers();
}

Expand All @@ -31,68 +38,68 @@ public void ResetFillers()
{
_propertyFillers = new List<IPropertyFiller>();

_propertyFillers.Add(new CharFiller());
_propertyFillers.Add(new NullableCharFiller());
_propertyFillers.Add(new IntFiller());
_propertyFillers.Add(new NullableIntFiller());
_propertyFillers.Add(new NullableUIntFiller());
_propertyFillers.Add(new LongFiller());
_propertyFillers.Add(new NullableLongFiller());
_propertyFillers.Add(new NullableULongFiller());
_propertyFillers.Add(new DecimalFiller());
_propertyFillers.Add(new NullableDecimalFiller());
_propertyFillers.Add(new ShortFiller());
_propertyFillers.Add(new NullableShortFiller());
_propertyFillers.Add(new NullableUShortFiller());
_propertyFillers.Add(new BooleanFiller());
_propertyFillers.Add(new NullableBooleanFiller());

_propertyFillers.Add(new AgeFiller());
_propertyFillers.Add(new PriceFiller());

_propertyFillers.Add(new CompanyNameFiller());

_propertyFillers.Add(new CookingFiller.IngredientFiller());


DateTimeNullableFiller DateTimeNullableFiller = new DateTimeAdapterFiller<DateTime?>();
_propertyFillers.Add(new DateTimeFiller());
_propertyFillers.Add(new DateTimeOffsetFiller());
_propertyFillers.Add(new CharFiller(GenFu));
_propertyFillers.Add(new NullableCharFiller(GenFu));
_propertyFillers.Add(new IntFiller(GenFu));
_propertyFillers.Add(new NullableIntFiller(GenFu));
_propertyFillers.Add(new NullableUIntFiller(GenFu));
_propertyFillers.Add(new LongFiller(GenFu));
_propertyFillers.Add(new NullableLongFiller(GenFu));
_propertyFillers.Add(new NullableULongFiller(GenFu));
_propertyFillers.Add(new DecimalFiller(GenFu));
_propertyFillers.Add(new NullableDecimalFiller(GenFu));
_propertyFillers.Add(new ShortFiller(GenFu));
_propertyFillers.Add(new NullableShortFiller(GenFu));
_propertyFillers.Add(new NullableUShortFiller(GenFu));
_propertyFillers.Add(new BooleanFiller(GenFu));
_propertyFillers.Add(new NullableBooleanFiller(GenFu));

_propertyFillers.Add(new AgeFiller(GenFu));
_propertyFillers.Add(new PriceFiller(GenFu));

_propertyFillers.Add(new CompanyNameFiller(GenFu));

_propertyFillers.Add(new CookingFiller.IngredientFiller(GenFu));


DateTimeNullableFiller DateTimeNullableFiller = new DateTimeAdapterFiller<DateTime?>(GenFu);
_propertyFillers.Add(new DateTimeFiller(GenFu));
_propertyFillers.Add(new DateTimeOffsetFiller(GenFu));
_propertyFillers.Add(DateTimeNullableFiller);


_propertyFillers.Add(new BirthDateFiller());
_propertyFillers.Add(new GuidFiller());
_propertyFillers.Add(new ArticleTitleFiller());
_propertyFillers.Add(new BirthDateFiller(GenFu));
_propertyFillers.Add(new GuidFiller(GenFu));
_propertyFillers.Add(new ArticleTitleFiller(GenFu));

_propertyFillers.Add(new FirstNameFiller());
_propertyFillers.Add(new LastNameFiller());
_propertyFillers.Add(new EmailFiller());
_propertyFillers.Add(new PersonTitleFiller());
_propertyFillers.Add(new FirstNameFiller(GenFu));
_propertyFillers.Add(new LastNameFiller(GenFu));
_propertyFillers.Add(new EmailFiller(GenFu));
_propertyFillers.Add(new PersonTitleFiller(GenFu));

_propertyFillers.Add(new TwitterFiller());
_propertyFillers.Add(new TwitterFiller(GenFu));

_propertyFillers.Add(new AddressFiller());
_propertyFillers.Add(new AddressLine2Filler());
_propertyFillers.Add(new CityFiller());
_propertyFillers.Add(new StateFiller());
_propertyFillers.Add(new ProvinceFiller());
_propertyFillers.Add(new ZipCodeFiller());
_propertyFillers.Add(new PostalCodeFiller());
_propertyFillers.Add(new PhoneNumberFiller());
_propertyFillers.Add(new AddressFiller(GenFu));
_propertyFillers.Add(new AddressLine2Filler(GenFu));
_propertyFillers.Add(new CityFiller(GenFu));
_propertyFillers.Add(new StateFiller(GenFu));
_propertyFillers.Add(new ProvinceFiller(GenFu));
_propertyFillers.Add(new ZipCodeFiller(GenFu));
_propertyFillers.Add(new PostalCodeFiller(GenFu));
_propertyFillers.Add(new PhoneNumberFiller(GenFu));

_propertyFillers.Add(new MusicAlbumTitleFiller());
_propertyFillers.Add(new MusicArtistNameFiller());
_propertyFillers.Add(new MusicGenreDescriptionFiller());
_propertyFillers.Add(new MusicGenreNameFiller());
_propertyFillers.Add(new MusicAlbumTitleFiller(GenFu));
_propertyFillers.Add(new MusicArtistNameFiller(GenFu));
_propertyFillers.Add(new MusicGenreDescriptionFiller(GenFu));
_propertyFillers.Add(new MusicGenreNameFiller(GenFu));

_propertyFillers.Add(new CanadianSocialInsuranceNumberFiller());
_propertyFillers.Add(new USASocialSecurityNumberFiller());
_propertyFillers.Add(new CanadianSocialInsuranceNumberFiller(GenFu));
_propertyFillers.Add(new USASocialSecurityNumberFiller(GenFu));

_propertyFillers.Add(new DrugFiller());
_propertyFillers.Add(new MedicalProcedureFiller());
_propertyFillers.Add(new DrugFiller(GenFu));
_propertyFillers.Add(new MedicalProcedureFiller(GenFu));

_propertyFillers.Add(new StringFiller());
_propertyFillers.Add(new StringFiller(GenFu));

}

Expand Down Expand Up @@ -199,12 +206,12 @@ public IPropertyFiller GetFiller(PropertyInfo propertyInfo)
}
else if (propertyInfo.PropertyType.GetTypeInfo().BaseType == typeof(System.Enum))
{
result = new EnumFiller(propertyInfo.PropertyType);
result = new EnumFiller(this.GenFu, propertyInfo.PropertyType);
}
else
{
//TODO: Can we build a custom filler here for other value types that we have not explicitly implemented (eg. long, decimal, etc.)
result = new CustomFiller<object>("*", typeof(object), true, () => null);
result = new CustomFiller<object>(GenFu, "*", typeof(object), true, () => null);
newRegistrations[propertyInfo.PropertyType] = result;
}
}
Expand Down Expand Up @@ -328,12 +335,27 @@ private static IPropertyFiller GetMatchingMethodFiller(MethodInfo methodInfo, ID
public Result GetGenericFiller<Input, Result>()
{
var type = typeof(Input);
return (Result)_genericPropertyFillersByPropertyType[type];
try
{
rwl.EnterReadLock();
return (Result) _genericPropertyFillersByPropertyType[type];
}
finally
{
rwl.ExitReadLock();
}
}
public IPropertyFiller GetGenericFillerForType(Type t)
{
return _genericPropertyFillersByPropertyType[t];
try
{
rwl.EnterReadLock();
return _genericPropertyFillersByPropertyType[t];
}
finally
{
rwl.ExitReadLock();
}
}

}
}
12 changes: 8 additions & 4 deletions src/GenFu/Fillers/BooleanFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ namespace GenFu.Fillers
{
public class BooleanFiller : PropertyFiller<bool>
{
public BooleanFiller() : this(A.GenFuInstance) { }

public BooleanFiller() : base(new[] { "object" }, new[] { "*" }, true)
public BooleanFiller(Type objectType, string propertyName) : this(A.GenFuInstance, objectType, propertyName) { }

public BooleanFiller(GenFuInstance genfu) : base(genfu, new[] { "object" }, new[] { "*" }, true)
{

}

public BooleanFiller(Type objectType, string propertyName) : base(new[] { objectType.FullName }, new[] { propertyName })
public BooleanFiller(GenFuInstance genfu, Type objectType, string propertyName) : base(genfu, new[] { objectType.FullName }, new[] { propertyName })
{

}
Expand All @@ -25,13 +28,14 @@ public override object GetValue(object instance)

public class NullableBooleanFiller : PropertyFiller<bool?>
{
public NullableBooleanFiller() : this(A.GenFuInstance) { }

public NullableBooleanFiller() : base(new[] { "object" }, new[] { "*" }, true)
public NullableBooleanFiller(GenFuInstance genfu) : base(genfu, new[] { "object" }, new[] { "*" }, true)
{

}

public NullableBooleanFiller(Type objectType, string propertyName) : base(new[] { objectType.FullName }, new[] { propertyName })
public NullableBooleanFiller(GenFuInstance genfu,Type objectType, string propertyName) : base(genfu, new[] { objectType.FullName }, new[] { propertyName })
{

}
Expand Down
6 changes: 5 additions & 1 deletion src/GenFu/Fillers/CanadianSocialInsuranceNumberFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace GenFu.Fillers
class CanadianSocialInsuranceNumberFiller : PropertyFiller<String>
{
public CanadianSocialInsuranceNumberFiller()
: base(new[] { "object" }, new[] { "SIN", "SocialInsuranceNumber" })
: base(A.GenFuInstance, new[] { "object" }, new[] { "SIN", "SocialInsuranceNumber" })
{ }

public CanadianSocialInsuranceNumberFiller(GenFuInstance genfu)
: base(genfu, new[] { "object" }, new[] { "SIN", "SocialInsuranceNumber" })
{ }

public override object GetValue(object instance)
Expand Down
14 changes: 9 additions & 5 deletions src/GenFu/Fillers/CharFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,36 @@ namespace GenFu.Fillers
{
public class CharFiller : PropertyFiller<char>
{
public CharFiller() : this(A.GenFuInstance) { }

public CharFiller() : base(new[] { "object" }, new[] { "*" }, true)
public CharFiller(Type objectType, string propertyName) : this(A.GenFuInstance, objectType, propertyName) { }

public CharFiller(GenFuInstance genFu) : base(genFu, new[] { "object" }, new[] { "*" }, true)
{

}

public CharFiller(Type objectType, string propertyName) : base(new[] { objectType.FullName }, new[] { propertyName })
public CharFiller(GenFuInstance genFu, Type objectType, string propertyName) : base(genFu, new[] { objectType.FullName }, new[] { propertyName })
{

}

public override object GetValue(object instance)
{
return (char)GenFu.Random.Next(char.MinValue, char.MaxValue);
return (char)this.GenFu.Random.Next(char.MinValue, char.MaxValue);
}
}

public class NullableCharFiller : PropertyFiller<char?>
{
public NullableCharFiller() : this(A.GenFuInstance) { }

public NullableCharFiller() : base(new[] { "object" }, new[] { "*" }, true)
public NullableCharFiller(GenFuInstance genFu) : base(genFu, new[] { "object" }, new[] { "*" }, true)
{

}

public NullableCharFiller(Type objectType, string propertyName) : base(new[] { objectType.FullName }, new[] { propertyName })
public NullableCharFiller(GenFuInstance genFu, Type objectType, string propertyName) : base(genFu, new[] { objectType.FullName }, new[] { propertyName })
{

}
Expand Down
4 changes: 3 additions & 1 deletion src/GenFu/Fillers/CompanyNameFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace GenFu.Fillers
{
class CompanyNameFiller : PropertyFiller<string>, IPropertyFiller
{
public CompanyNameFiller(): base (new[] { "company" }, new[] { "name" }, false)
public CompanyNameFiller() : this(A.GenFuInstance) { }

public CompanyNameFiller(GenFuInstance genFu) : base (genFu, new[] { "company" }, new[] { "name" }, false)
{}

public override object GetValue(object instance)
Expand Down
8 changes: 5 additions & 3 deletions src/GenFu/Fillers/CookingFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class CookingFiller
{
public class IngredientFiller : PropertyFiller<string>
{
public IngredientFiller()
: base(new[] { "object" }, new[] { "ingredient", "ingredients" })
public IngredientFiller() : this(A.GenFuInstance) { }

public IngredientFiller(GenFuInstance genFu)
: base(genFu, new[] { "object" }, new[] { "ingredient", "ingredients" })
{
}

Expand All @@ -19,6 +21,6 @@ public override object GetValue(object instance)
return ValueGenerators.Cooking.Ingredients.Ingredient();
}
}

}
}
21 changes: 14 additions & 7 deletions src/GenFu/Fillers/CustomFillers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ public class CustomFiller<T> : PropertyFiller<T>
{
private Func<T> _filler;

public CustomFiller(string propertyName, Type objectType, Func<T> filler)
: this(propertyName, objectType, false, filler)
public CustomFiller(string propertyName, Type objectType, Func<T> filler) : this(A.GenFuInstance, propertyName, objectType, filler) { }

public CustomFiller(GenFuInstance genfu, string propertyName, Type objectType, Func<T> filler)
: this(genfu, propertyName, objectType, false, filler)
{
}

internal CustomFiller(string propertyName, Type objectType, bool isGeneric, Func<T> filler)
: base(new[] { objectType.FullName }, new[] { propertyName }, isGeneric)
internal CustomFiller(GenFuInstance genfu, string propertyName, Type objectType, bool isGeneric, Func<T> filler)
: base(genfu, new[] { objectType.FullName }, new[] { propertyName }, isGeneric)
{
if (objectType != typeof(Object))
AddAllBaseTypes(propertyName, objectType);
Expand Down Expand Up @@ -46,12 +48,17 @@ public class CustomFiller<T1, T2> : PropertyFiller<T2>
private Func<T1, T2> _filler;

public CustomFiller(string propertyName, Type objectType, Func<T1, T2> filler)
: this(propertyName, objectType, false, filler)
: this(A.GenFuInstance, propertyName, objectType, false, filler)
{
}

public CustomFiller(GenFuInstance genfu, string propertyName, Type objectType, Func<T1, T2> filler)
: this(genfu, propertyName, objectType, false, filler)
{
}

internal CustomFiller(string propertyName, Type objectType, bool isGeneric, Func<T1, T2> filler)
: base(new[] { objectType.FullName }, new[] { propertyName }, isGeneric)
internal CustomFiller(GenFuInstance genfu, string propertyName, Type objectType, bool isGeneric, Func<T1, T2> filler)
: base(genfu, new[] { objectType.FullName }, new[] { propertyName }, isGeneric)
{
_filler = filler;
}
Expand Down
19 changes: 16 additions & 3 deletions src/GenFu/Fillers/DateTimeAdapterFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ namespace GenFu.Fillers
{
public class DateTimeAdapterFiller<T> : DateTimeNullableFiller
{
DateTimeFiller dateTimeFiller = new DateTimeFiller();
public DateTimeAdapterFiller(GenFuInstance genFu) : base(genFu)
{

}

DateTimeFiller _dateTimeFiller = null;
DateTimeFiller DateTimeFiller
{
get
{
_dateTimeFiller = _dateTimeFiller ?? new DateTimeFiller(this.GenFu);
return _dateTimeFiller;
}
}
private Random rand = new Random();

public override object GetValue(object instance)
Expand All @@ -18,11 +31,11 @@ public override object GetValue(object instance)
}
else
{
return dateTimeFiller.GetValue(instance);
return DateTimeFiller.GetValue(instance);
}
}

return dateTimeFiller.GetValue(instance);
return DateTimeFiller.GetValue(instance);
}
}
}
Loading