diff --git a/HISTORY.md b/HISTORY.md index 0af1db15..36aaa3f7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,6 @@ +## v11.0.4 +* Added `.RuleFor(x.Item, "foo")`. Eliminates ceremony of `f =>` for simple values. + ## v11.0.3 * Added range option to `Sentence`. diff --git a/Source/Bogus.Tests/FluentTests.cs b/Source/Bogus.Tests/FluentTests.cs index 393bd70b..c83e1818 100644 --- a/Source/Bogus.Tests/FluentTests.cs +++ b/Source/Bogus.Tests/FluentTests.cs @@ -259,12 +259,18 @@ public User(int userId, string ssn) public List Orders { get; set; } } + [Test] + public void just_want_to_set_a_value() + { + var faker = new Faker() + .RuleFor(o => o.OrderId, 25) + .RuleFor(o => o.Item, "foo"); + faker.Generate().OrderId.Should().Be(25); + faker.Generate().Item.Should().Be("foo"); - } - - - + } + } } diff --git a/Source/Bogus/Faker[T].cs b/Source/Bogus/Faker[T].cs index d1b7bb8e..271004f7 100644 --- a/Source/Bogus/Faker[T].cs +++ b/Source/Bogus/Faker[T].cs @@ -90,6 +90,14 @@ public Faker RuleFor(Expression> property, Func return this; } + /// + /// Creates a rule for a property. + /// + public Faker RuleFor(Expression> property, TProperty value) + { + return RuleFor(property, f => value); + } + /// /// Creates a rule for a property. /// diff --git a/Source/Bogus/IRuleSet.cs b/Source/Bogus/IRuleSet.cs index d53aeb46..a2f5afa9 100644 --- a/Source/Bogus/IRuleSet.cs +++ b/Source/Bogus/IRuleSet.cs @@ -47,5 +47,10 @@ public interface IRuleSet where T : class /// Action is invoked after all the rules are applied. /// Faker FinishWith(Action action); + + /// + /// Creates a rule for a property. + /// + Faker RuleFor(Expression> property, TProperty value); } } \ No newline at end of file