-
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.
- Loading branch information
1 parent
32c0551
commit 8b741c5
Showing
4 changed files
with
112 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Ace.CSharp.DataFaker.Exceptions; | ||
using Ace.CSharp.DataFaker.Internal.Symbols; | ||
using Ace.CSharp.DataFaker.Tests.Fakers; | ||
|
||
namespace Ace.CSharp.DataFaker.Tests; | ||
|
||
public sealed class AbstractDataFakerTests | ||
{ | ||
[Fact] | ||
internal void GivenOfWhenPropertyIsConfiguredThenGeneratesData() | ||
{ | ||
// Arrange | ||
AbstractDataFaker<FakeEntity> fakeEntity = new FakeEntity(); | ||
|
||
// Act | ||
var entity = fakeEntity.Of<FooEntity>(); | ||
|
||
// Assert | ||
entity.Should().NotBeNull().And.BeOfType<FooEntity>(); | ||
} | ||
|
||
[Fact] | ||
internal void GivenOfWhenPropertyIsNotConfiguredThenThrowsException() | ||
{ | ||
// Arrange | ||
AbstractDataFaker<FakeEntity> fakeEntity = new FakeEntity(); | ||
|
||
// Act | ||
var action = () => fakeEntity.Of<BarEntity>(); | ||
|
||
// Assert | ||
action.Should().Throw<InstanceFakerNotFoundException<BarEntity, FakeEntity>>(); | ||
} | ||
|
||
[Fact] | ||
internal void GivenManyOfWhenPropertyIsConfiguredThenGeneratesData() | ||
{ | ||
// Arrange | ||
AbstractDataFaker<FakeEntity> fakeEntity = new FakeEntity(); | ||
|
||
// Act | ||
var entities = fakeEntity.ManyOf<FooEntity>(); | ||
|
||
// Assert | ||
entities.Should().NotBeNull().And.BeOfType<List<FooEntity>>(); | ||
entities.Should().NotBeEmpty().And.HaveCount(Constants.ManyOfCount); | ||
} | ||
|
||
[Fact] | ||
internal void GivenManyOfWhenPropertyIsConfiguredAndCountIsSpecifiedThenGeneratesData() | ||
{ | ||
// Arrange | ||
AbstractDataFaker<FakeEntity> fakeEntity = new FakeEntity(); | ||
int count = 10; | ||
|
||
// Act | ||
var entities = fakeEntity.ManyOf<FooEntity>(count); | ||
|
||
// Assert | ||
entities.Should().NotBeNull().And.BeOfType<List<FooEntity>>(); | ||
entities.Should().NotBeEmpty().And.HaveCount(count); | ||
} | ||
|
||
[Fact] | ||
internal void GivenManyOfWhenPropertyIsNotConfiguredThenThrowsException() | ||
{ | ||
// Arrange | ||
AbstractDataFaker<FakeEntity> fakeEntity = new FakeEntity(); | ||
|
||
// Act | ||
var action = () => fakeEntity.ManyOf<BarEntity>(); | ||
|
||
// Assert | ||
action.Should().Throw<InstanceFakerNotFoundException<BarEntity, FakeEntity>>(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Bogus; | ||
|
||
namespace Ace.CSharp.DataFaker.Tests.Fakers; | ||
|
||
public sealed class FakeEntity : AbstractDataFaker<FakeEntity> | ||
{ | ||
private Faker<FooEntity> FakeFooEntity => | ||
new Faker<FooEntity>(locale: LocaleCode) | ||
.RuleFor( | ||
person => person.Value, | ||
func => func.Random.Number(1, 100)) | ||
.RuleFor( | ||
person => person.Description, | ||
func => func.Lorem.Sentence(wordCount: 10)) | ||
.StrictMode(ensureRulesForAllProperties: true); | ||
} | ||
|
||
internal sealed class FooEntity | ||
{ | ||
public int Value { get; set; } | ||
public string Description { get; set; } = default!; | ||
} | ||
|
||
internal sealed class BarEntity | ||
{ | ||
public Guid Uuid { get; set; } | ||
} |
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