Skip to content

Commit

Permalink
Updated example and unit tests to cover ConditionalGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
kesac committed Nov 17, 2021
1 parent 93d9b95 commit 8cfc1e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Archigen/Archigen.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public static void Main(string[] args)
.ForProperty<string>(x => x.PlayerName, new StringGenerator()))
.UsingSize(10);

var c = new ConditionalGenerator<Team>(g)
.WithCondition(team => team.TeamName.Contains("a"));

for(int i = 0; i < 3; i++)
{
var team = g.Next();
var team = c.Next();
Console.WriteLine("Team {0}", team);

foreach(var player in team.Players)
Expand Down
9 changes: 6 additions & 3 deletions Archigen/Archigen.Tests/ArchigenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ public void Generator_CanAssignProperties()
[TestMethod]
public void Generator_CanPopulateListProperties()
{
var lookingFor = "a";
var names = new NameGenerator();
var conditionalNames = new ConditionalGenerator<string>(names)
.WithCondition(x => x.Contains(lookingFor));

var numbers = new NumberGenerator();

// When using ForListProperty() we expect both the list itself
// and the elements within the list to be instantiated.
var g = new Generator<Character>()
.ForProperty<string>(x => x.Name, names)
.ForProperty<string>(x => x.Name, conditionalNames)
.ForProperty<int>(x => x.Level, numbers)
.ForProperty<int>(x => x.Age, 30)
.ForListProperty<Ability>(x => x.Abilities, new Generator<Ability>()
Expand All @@ -121,6 +125,7 @@ public void Generator_CanPopulateListProperties()
{
var character = g.Next();
Assert.IsFalse(string.IsNullOrEmpty(character.Name));
Assert.IsTrue(character.Name.Contains(lookingFor));
Assert.IsTrue(character.Level > 0 && character.Level <= 10);
Assert.IsTrue(character.Abilities.Count == 10);
Assert.IsTrue(character.Age == 32);
Expand All @@ -132,8 +137,6 @@ public void Generator_CanPopulateListProperties()

}



}

}
Expand Down

0 comments on commit 8cfc1e3

Please sign in to comment.