-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tunittest): add fluentbogus unit tests (#15)
Add FluentBogus unit tests Fixes #6 --------- Co-authored-by: Bruno DUVAL <bruno.duval@datatunning.com>
- Loading branch information
1 parent
3e768d6
commit 24bd68e
Showing
25 changed files
with
966 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
...FluentBogus.UnitTest/Faker/PersonFaker.cs → ...sting.Example.Domain/Faker/PersonFaker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
NineteenSevenFour.Testing.FluentBogus.Relation.UnitTest/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
global using AutoBogus; | ||
global using Xunit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Fake.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using FluentAssertions; | ||
|
||
using NineteenSevenFour.Testing.Example.Domain.Model; | ||
using NineteenSevenFour.Testing.FluentBogus.Extension; | ||
|
||
namespace NineteenSevenFour.Testing.FluentBogus.UnitTest; | ||
|
||
public class FluentBogusBuilder_Fake | ||
{ | ||
[Fact] | ||
public void Should_Return_ABuilder_WhenCalled() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var builder = FluentBogusBuilder.Fake<PersonModel>(); | ||
|
||
// Assert | ||
builder.Should() | ||
.NotBeNull().And | ||
.BeOfType<FluentBogusBuilder<PersonModel>>(); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_Generate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using FluentAssertions; | ||
|
||
using NineteenSevenFour.Testing.Example.Domain.Faker; | ||
using NineteenSevenFour.Testing.Example.Domain.Model; | ||
using NineteenSevenFour.Testing.FluentBogus.Extension; | ||
|
||
namespace NineteenSevenFour.Testing.FluentBogus.UnitTest; | ||
|
||
public class FluentBogusBuilder_Generate | ||
{ | ||
[Fact] | ||
public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithoutSkipOrConfigOrSeed() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker> (); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var person = builder.Generate(); | ||
|
||
// Assert | ||
person.Should().NotBeNull(); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(0); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithSkip() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var person = builder.Skip(p => p.Addresses).Generate(); | ||
|
||
// Assert | ||
person.Should().NotBeNull(); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(1); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnAnInstanceOfEntity_WhenCalled_WithConfig() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var person = builder.UseConfig(b => b.WithTreeDepth(1)).Generate(); | ||
|
||
// Assert | ||
person.Should().NotBeNull(); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(0); | ||
typedBuilder.fakerConfigBuilder.Should().NotBeNull(); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithoutSkipOrConfigOrSeed() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var persons = builder.Generate(2); | ||
|
||
// Assert | ||
persons.Should().NotBeNullOrEmpty().And.HaveCount(2); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(0); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithSkip() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var persons = builder.Skip(p => p.Addresses).Generate(2); | ||
|
||
// Assert | ||
persons.Should().NotBeNullOrEmpty().And.HaveCount(2); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(1); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnAnArrayOfInstanceOfEntity_WhenCalled_WithConfig() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
|
||
// Act | ||
var persons = builder.UseConfig(b => b.WithTreeDepth(1)).Generate(2); | ||
|
||
// Assert | ||
persons.Should().NotBeNullOrEmpty().And.HaveCount(2); | ||
#pragma warning disable CS8602 // Dereference of a possibly null reference. | ||
typedBuilder.skipProperties.Should().HaveCount(0); | ||
typedBuilder.fakerConfigBuilder.Should().NotBeNull(); | ||
#pragma warning restore CS8602 // Dereference of a possibly null reference. | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
NineteenSevenFour.Testing.FluentBogus.UnitTest/FluentBogusBuilder_RuleSetString.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using FluentAssertions; | ||
|
||
using NineteenSevenFour.Testing.Example.Domain.Faker; | ||
using NineteenSevenFour.Testing.Example.Domain.Model; | ||
using NineteenSevenFour.Testing.FluentBogus.Extension; | ||
|
||
namespace NineteenSevenFour.Testing.FluentBogus.UnitTest; | ||
|
||
public class FluentBogusBuilder_RuleSetString | ||
{ | ||
[Fact] | ||
public void Should_ReturnJoinedList_WhenCalled_WithRuleset() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
|
||
// Act | ||
builder.UseRuleSet("rule1", "rule2"); | ||
|
||
// Assert | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
Assert.NotNull(typedBuilder); | ||
typedBuilder.RuleSetString.Should() | ||
.NotBeNullOrEmpty() | ||
.And | ||
.Be("rule1,rule2"); | ||
} | ||
|
||
[Fact] | ||
public void Should_ReturnEmptyString_WhenCalled_WithoutRuleset() | ||
{ | ||
// Arrange | ||
var builder = FluentBogusBuilder.Fake<PersonModel>().With<PersonFaker>(); | ||
|
||
// Act | ||
|
||
// Assert | ||
var typedBuilder = builder as FluentBogusBuilder<PersonFaker, PersonModel>; | ||
Assert.NotNull(typedBuilder); | ||
typedBuilder.RuleSetString.Should() | ||
.BeNullOrEmpty(); | ||
} | ||
} |
Oops, something went wrong.