Skip to content

Commit c05a8bd

Browse files
committed
Update unit test and use C# 9 feature for null checking.
1 parent 6b2342c commit c05a8bd

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

Source/Bogus.Tests/StrictModeTests.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Bogus.Tests.Models;
32
using FluentAssertions;
43
using Xunit;
54

@@ -97,13 +96,20 @@ public void cannot_use_rules_with_strictmode_inside_rulesets()
9796
}
9897

9998
[Fact]
100-
public void StrictMode_True_NoRules()
99+
public void strictmode_with_no_rules_should_throw()
101100
{
102-
Assert.Throws<ValidationException>(() =>
103-
{
104-
new Faker<Order>()
105-
.StrictMode(true).Generate(1);
106-
});
101+
var faker = new Faker<Examples.Order>()
102+
.StrictMode(true);
103+
104+
Action act = () => faker.Generate(1);
105+
106+
act.Should().ThrowExactly<ValidationException>()
107+
.WithMessage("*Missing Rules*")
108+
.WithMessage("*Validation was called to ensure all properties*")
109+
.WithMessage($"*{nameof(Examples.Order.OrderId)}*")
110+
.WithMessage($"*{nameof(Examples.Order.Item)}*")
111+
.WithMessage($"*{nameof(Examples.Order.Quantity)}*")
112+
.WithMessage($"*{nameof(Examples.Order.LotNumber)}*");
107113
}
108114
}
109115
}

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 != null && populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
747+
if( populateActions is not null && populateActions.TryGetValue(propOrFieldOfT, out var populateAction) )
748748
{
749749
// Very much a .Rules() action
750750
if( populateAction.ProhibitInStrictMode )

0 commit comments

Comments
 (0)