diff --git a/Source/Bogus.Tests/StrictModeTests.cs b/Source/Bogus.Tests/StrictModeTests.cs index 4e2d7468..1c5e705f 100644 --- a/Source/Bogus.Tests/StrictModeTests.cs +++ b/Source/Bogus.Tests/StrictModeTests.cs @@ -94,5 +94,22 @@ public void cannot_use_rules_with_strictmode_inside_rulesets() Action act2 = () => faker2.AssertConfigurationIsValid(); act2.Should().Throw(); } + + [Fact] + public void strictmode_with_no_rules_should_throw() + { + var faker = new Faker() + .StrictMode(true); + + Action act = () => faker.Generate(1); + + act.Should().ThrowExactly() + .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)}*"); + } } } diff --git a/Source/Bogus/Faker[T].cs b/Source/Bogus/Faker[T].cs index 4e8537d7..5c942ea6 100644 --- a/Source/Bogus/Faker[T].cs +++ b/Source/Bogus/Faker[T].cs @@ -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 )