Skip to content

Commit

Permalink
Rename BogusGenerator.cs to BogusGeneratorDescriptor.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bardin08 committed Jun 20, 2024
1 parent 448d28e commit db28c86
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions DbSeeder/Data/Bogus/BogusUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static class BogusUtilities
}
};

public static Dictionary<string, List<BogusGenerator>> GetBogusGenerators()
public static Dictionary<string, List<BogusGeneratorDescriptor>> GetBogusGenerators()

Check failure on line 20 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 20 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
{
var generators = new Dictionary<string, List<BogusGenerator>>();
var generators = new Dictionary<string, List<BogusGeneratorDescriptor>>();

var fakerType = typeof(Faker);

Expand All @@ -44,7 +44,7 @@ public static Dictionary<string, List<BogusGenerator>> GetBogusGenerators()
foreach (var m in methods)
{
var methodParams = m.GetParameters().ToDictionary(x => x.Name!, x => x.ParameterType);
var generator = new BogusGenerator(
var generator = new BogusGeneratorDescriptor(
generatorCategory,
generatorCategory + m.Name.ToLower(),
m.ReturnType,
Expand All @@ -57,12 +57,12 @@ public static Dictionary<string, List<BogusGenerator>> GetBogusGenerators()
return generators;
}

public static Dictionary<string, List<BogusGenerator>> GetFiltersForReturnType(
this Dictionary<string, List<BogusGenerator>> src, string returnType)
public static Dictionary<string, List<BogusGeneratorDescriptor>> GetFiltersForReturnType(

Check failure on line 60 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
this Dictionary<string, List<BogusGeneratorDescriptor>> src, string returnType)

Check failure on line 61 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 61 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
{
var allowed = AllowedTypes[returnType];

var allowedGenerators = new Dictionary<string, List<BogusGenerator>>();
var allowedGenerators = new Dictionary<string, List<BogusGeneratorDescriptor>>();
foreach (var (category, generators) in src)
{
allowedGenerators.Add(category, []);
Expand All @@ -78,12 +78,12 @@ public static Dictionary<string, List<BogusGenerator>> GetFiltersForReturnType(
return allowedGenerators;
}

public static dynamic? Generate(BogusGenerator generator)
public static dynamic? Generate(BogusGeneratorDescriptor generatorDescriptor)

Check failure on line 81 in DbSeeder/Data/Bogus/BogusUtilities.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
{
var faker = new Faker();
var generationMethod = generator.GeneratorIdentifier[generator.Category.Length..];
var generationMethod = generatorDescriptor.GeneratorIdentifier[generatorDescriptor.Category.Length..];

var generatorProperty = faker.GetType().GetProperty(generator.Category,
var generatorProperty = faker.GetType().GetProperty(generatorDescriptor.Category,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (generatorProperty != null)
{
Expand All @@ -97,19 +97,19 @@ public static Dictionary<string, List<BogusGenerator>> GetFiltersForReturnType(
var parameters = generatorMethod.GetParameters();
if (parameters.Length > 0)
{
@params = ParamsGenerator.GetParams(generator.GeneratorIdentifier);
@params = ParamsGenerator.GetParams(generatorDescriptor.GeneratorIdentifier);
}

// TODO[#27]: Implement constraints handling
var result = generatorMethod.Invoke(categoryGenerator, @params);
return Convert.ChangeType(result, generatorMethod.ReturnType)!;
}

Console.WriteLine($"Method '{generationMethod}' not found in '{generator.Category}' category");
Console.WriteLine($"Method '{generationMethod}' not found in '{generatorDescriptor.Category}' category");
}
else
{
Console.WriteLine($"Category '{generator.Category}' not found on Faker object");
Console.WriteLine($"Category '{generatorDescriptor.Category}' not found on Faker object");
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions DbSeeder/Data/Bogus/DataGeneratorsEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace DbSeeder.Data.Bogus;

public static class DataGeneratorsEvaluator
{
public static List<BogusGenerator> FindBestNGenerators(
this Dictionary<string, List<BogusGenerator>> allGenerators,
public static List<BogusGeneratorDescriptor> FindBestNGenerators(

Check failure on line 7 in DbSeeder/Data/Bogus/DataGeneratorsEvaluator.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
this Dictionary<string, List<BogusGeneratorDescriptor>> allGenerators,

Check failure on line 8 in DbSeeder/Data/Bogus/DataGeneratorsEvaluator.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)
Column column,
int n = 1)
{
var weights = new Dictionary<int, List<BogusGenerator>>();
var weights = new Dictionary<int, List<BogusGeneratorDescriptor>>();

foreach (var (_, generatorsCategory) in allGenerators)
{
Expand Down
2 changes: 1 addition & 1 deletion DbSeeder/Data/GeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class GeneratorFactory
private static readonly HashSet<string> OtherTypes =
["uniqueidentifier", "timestamp", "xml", "udt", "structured", "variant"];

private static readonly Dictionary<string, List<BogusGenerator>> Generators = BogusUtilities.GetBogusGenerators();
private static readonly Dictionary<string, List<BogusGeneratorDescriptor>> Generators = BogusUtilities.GetBogusGenerators();

Check failure on line 21 in DbSeeder/Data/GeneratorFactory.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 21 in DbSeeder/Data/GeneratorFactory.cs

View workflow job for this annotation

GitHub Actions / main

The type or namespace name 'BogusGeneratorDescriptor' could not be found (are you missing a using directive or an assembly reference?)

public static object? GetGeneratorByColumnV2(Column col)
{
Expand Down

0 comments on commit db28c86

Please sign in to comment.