Skip to content

Commit 6b2342c

Browse files
Basyrasbchavez
authored andcommitted
Fixing null reference exception
1 parent c429ae9 commit 6b2342c

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Source/Bogus.Tests/StrictModeTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Bogus.Tests.Models;
23
using FluentAssertions;
34
using Xunit;
45

@@ -94,5 +95,15 @@ public void cannot_use_rules_with_strictmode_inside_rulesets()
9495
Action act2 = () => faker2.AssertConfigurationIsValid();
9596
act2.Should().Throw<ValidationException>();
9697
}
98+
99+
[Fact]
100+
public void StrictMode_True_NoRules()
101+
{
102+
Assert.Throws<ValidationException>(() =>
103+
{
104+
new Faker<Order>()
105+
.StrictMode(true).Generate(1);
106+
});
107+
}
97108
}
98109
}

Source/Bogus/Faker[T].cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ private ValidationResult ValidateInternal(string[] ruleSets)
744744
{
745745
foreach( var propOrFieldOfT in userSet )
746746
{
747-
if( populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
747+
if( populateActions != null && populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
748748
{
749749
// Very much a .Rules() action
750750
if( populateAction.ProhibitInStrictMode )

0 commit comments

Comments
 (0)