-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #218 - Fixed bug that prevented global static `Faker.DefaultStr…
…ictMode` from working.
- Loading branch information
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using Bogus.Tests.Models; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Bogus.Tests.GitHubIssues | ||
{ | ||
public class Issue218 : SeededTest | ||
{ | ||
[Fact] | ||
public void global_strict_mode_should_throw_on_incomplete_rules() | ||
{ | ||
Faker.DefaultStrictMode = true; | ||
|
||
var orderFaker = new Faker<Order>() | ||
.RuleFor(x => x.Item, f => f.Commerce.Product()); | ||
|
||
Action gen = () => orderFaker.Generate(); | ||
|
||
gen.ShouldThrow<ValidationException>(); | ||
|
||
Faker.DefaultStrictMode = false; | ||
} | ||
|
||
[Fact] | ||
public void local_struct_mode_faker_t_scope_should_throw_on_incomplete_rules() | ||
{ | ||
Faker.DefaultStrictMode = false; | ||
|
||
var orderFaker = new Faker<Order>() | ||
.StrictMode(true) | ||
.RuleFor(x => x.Item, f => f.Commerce.Product()); | ||
|
||
Action gen = () => orderFaker.Generate(); | ||
|
||
gen.ShouldThrow<ValidationException>(); | ||
} | ||
|
||
|
||
[Fact] | ||
public void local_strict_mode_should_take_precedence_always() | ||
{ | ||
Faker.DefaultStrictMode = true; | ||
|
||
var orderFaker = new Faker<Order>() | ||
.StrictMode(false) | ||
.RuleFor(x => x.Item, f => f.Commerce.Product()); | ||
|
||
Action gen = () => orderFaker.Generate(); | ||
|
||
gen.ShouldNotThrow<ValidationException>(); | ||
|
||
Faker.DefaultStrictMode = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters