Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
+ Added a verification that no-parameter constructors get called correctly
  • Loading branch information
kesac committed Oct 30, 2021
1 parent c6d9267 commit 7e8ddb6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/Archigen/Archigen.Tests/bin/Debug/net5.0
/Archigen/Archigen.Tests/obj
/Archigen/.vs/Archigen/DesignTimeBuild
/Archigen/Archigen.Tests/bin/Release/net5.0
35 changes: 26 additions & 9 deletions Archigen/Archigen.Tests/ArchigenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ public class NumberGenerator : IGenerator<int>

public int Next()
{
return this.Random.Next(100) + 1;
return this.Random.Next(10) + 1;
}
}

// A POCO for testing
public class Character
{
public string Name { get; set; }
public int Level { get; set; }
public List<Ability> Abilities{ get; set; }

public Character()
{
this.Abilities = new List<Ability>();
}

}

public class Ability
Expand Down Expand Up @@ -65,8 +70,14 @@ public void Generator_CanInstantiatePrimitivesAndStructsAndObjects()
Ability ability = abilityGenerator.Next();
Assert.IsNotNull(ability);
Assert.IsNull(ability.Name);

var characterGenerator = new Generator<Character>();
var c = characterGenerator.Next();

Assert.IsNotNull(c.Abilities);
}


[TestMethod]
public void Generator_CanAssignProperties()
{
Expand Down Expand Up @@ -102,16 +113,22 @@ public void Generator_CanPopulateListProperties()
.ForProperty<string>(x => x.Name, names))
.UsingSize(10);

var character = g.Next();
Assert.IsNotNull(character.Name);
Assert.IsTrue(character.Level > 0 && character.Level <= 100);
Assert.IsTrue(character.Abilities.Count == 10);

foreach(var ability in character.Abilities)
for (int i = 0; i < 1000; i++)
{
Assert.IsNotNull(ability.Name);
var character = g.Next();
Assert.IsTrue(string.IsNullOrEmpty(character.Name));
Assert.IsTrue(character.Level > 0 && character.Level <= 10);
Assert.IsTrue(character.Abilities.Count == 10);

foreach (var ability in character.Abilities)
{
Assert.IsNotNull(ability.Name);
}

}



}

}
Expand Down
8 changes: 1 addition & 7 deletions Archigen/Archigen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ VisualStudioVersion = 16.0.31229.75
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Archigen", "Archigen\Archigen.csproj", "{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Archigen.Example", "Archigen.Example\Archigen.Example.csproj", "{4F72A841-2B84-43C4-80EF-08C14D35FBFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archigen.Tests", "Archigen.Tests\Archigen.Tests.csproj", "{B5AB6149-F642-4EE3-A2A4-221685592484}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Archigen.Tests", "Archigen.Tests\Archigen.Tests.csproj", "{B5AB6149-F642-4EE3-A2A4-221685592484}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -19,10 +17,6 @@ Global
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C04E0C13-120C-4A7E-87C8-5AF8198D29FE}.Release|Any CPU.Build.0 = Release|Any CPU
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F72A841-2B84-43C4-80EF-08C14D35FBFA}.Release|Any CPU.Build.0 = Release|Any CPU
{B5AB6149-F642-4EE3-A2A4-221685592484}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5AB6149-F642-4EE3-A2A4-221685592484}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5AB6149-F642-4EE3-A2A4-221685592484}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 7e8ddb6

Please sign in to comment.