From 9339cb8e657da6198ab9312bf8015bd7ac29c1f3 Mon Sep 17 00:00:00 2001 From: bchavez Date: Sat, 12 Dec 2020 12:40:21 -0800 Subject: [PATCH] Update unit test and use C# 9 feature for null checking. --- Source/Bogus.Tests/StrictModeTests.cs | 20 +++++++++++++------- Source/Bogus/Faker[T].cs | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/Bogus.Tests/StrictModeTests.cs b/Source/Bogus.Tests/StrictModeTests.cs index 4a615668..1c5e705f 100644 --- a/Source/Bogus.Tests/StrictModeTests.cs +++ b/Source/Bogus.Tests/StrictModeTests.cs @@ -1,5 +1,4 @@ using System; -using Bogus.Tests.Models; using FluentAssertions; using Xunit; @@ -97,13 +96,20 @@ public void cannot_use_rules_with_strictmode_inside_rulesets() } [Fact] - public void StrictMode_True_NoRules() + public void strictmode_with_no_rules_should_throw() { - Assert.Throws(() => - { - new Faker() - .StrictMode(true).Generate(1); - }); + 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 746418dd..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 != null && 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 )