Skip to content

Commit

Permalink
Allow just adding a value.
Browse files Browse the repository at this point in the history
  • Loading branch information
bchavez committed Mar 15, 2017
1 parent 179c33b commit a369f51
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand Down
14 changes: 10 additions & 4 deletions Source/Bogus.Tests/FluentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ public User(int userId, string ssn)
public List<Order> Orders { get; set; }
}

[Test]
public void just_want_to_set_a_value()
{
var faker = new Faker<Order>()
.RuleFor(o => o.OrderId, 25)
.RuleFor(o => o.Item, "foo");

faker.Generate().OrderId.Should().Be(25);
faker.Generate().Item.Should().Be("foo");

}



}

}

}
8 changes: 8 additions & 0 deletions Source/Bogus/Faker[T].cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public Faker<T> RuleFor<TProperty>(Expression<Func<T, TProperty>> property, Func
return this;
}

/// <summary>
/// Creates a rule for a property.
/// </summary>
public Faker<T> RuleFor<TProperty>(Expression<Func<T, TProperty>> property, TProperty value)
{
return RuleFor(property, f => value);
}

/// <summary>
/// Creates a rule for a property.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Source/Bogus/IRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public interface IRuleSet<T> where T : class
/// Action is invoked after all the rules are applied.
/// </summary>
Faker<T> FinishWith(Action<Faker, T> action);

/// <summary>
/// Creates a rule for a property.
/// </summary>
Faker<T> RuleFor<TProperty>(Expression<Func<T, TProperty>> property, TProperty value);
}
}

0 comments on commit a369f51

Please sign in to comment.