Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Source/Bogus.Tests/StrictModeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,22 @@ public void cannot_use_rules_with_strictmode_inside_rulesets()
Action act2 = () => faker2.AssertConfigurationIsValid();
act2.Should().Throw<ValidationException>();
}

[Fact]
public void strictmode_with_no_rules_should_throw()
{
var faker = new Faker<Examples.Order>()
.StrictMode(true);

Action act = () => faker.Generate(1);

act.Should().ThrowExactly<ValidationException>()
.WithMessage("*Missing Rules*")
.WithMessage("*Validation was called to ensure all properties*")
.WithMessage($"*{nameof(Examples.Order.OrderId)}*")
.WithMessage($"*{nameof(Examples.Order.Item)}*")
.WithMessage($"*{nameof(Examples.Order.Quantity)}*")
.WithMessage($"*{nameof(Examples.Order.LotNumber)}*");
}
}
}
2 changes: 1 addition & 1 deletion Source/Bogus/Faker[T].cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ private ValidationResult ValidateInternal(string[] ruleSets)
{
foreach( var propOrFieldOfT in userSet )
{
if( populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
if( populateActions is not null && populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
{
// Very much a .Rules() action
if( populateAction.ProhibitInStrictMode )
Expand Down