diff --git a/HISTORY.md b/HISTORY.md index 6f99466e..d1e5064a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## v5.1.1-beta-3 +* Removed RuleFor(x = x.Prop, constantValue), was confusing the API. +* Added 0-arity RuleFor(x = x.Prop, () => someValue) + ## v5.1.1-beta-2 * Make f.UniqueIndex as int for convenience. * Use generic RuleFor(x = x.Prop, constantValue). diff --git a/README.md b/README.md index 6c36a84a..d75c91c3 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ var testUsers = new Faker() .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName)) .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName)) .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}") - .RuleFor(u => u.SomethingConstant, "AConstantStringValue") //Use an enum outside scope. .RuleFor(u => u.Gender, f => f.PickRandom()) diff --git a/Source/Bogus.Tests/FluentTests.cs b/Source/Bogus.Tests/FluentTests.cs index 33bd9251..f843f75e 100644 --- a/Source/Bogus.Tests/FluentTests.cs +++ b/Source/Bogus.Tests/FluentTests.cs @@ -53,7 +53,7 @@ public void TestAPIDesign() .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName)) .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName)) .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}") - .RuleFor(u => u.SomethingConstant, "SomeConstantStringValue") + .RuleFor(u => u.SomeGuid, Guid.NewGuid) //Use an enum outside scope. .RuleFor(u => u.Gender, f => f.PickRandom()) @@ -177,8 +177,9 @@ public User(int userId, string ssn) public string FullName { get; set; } public string UserName { get; set; } public string Email { get; set; } - public string SomethingConstant { get; set; } public string SomethingUnique { get; set; } + public Guid SomeGuid { get; set; } + public string Avatar { get; set; } public Guid CartId { get; set; } public string SSN { get; set; } diff --git a/Source/Bogus.Tests/RandomizerTest.cs b/Source/Bogus.Tests/RandomizerTest.cs index fc2984c0..4832ea11 100644 --- a/Source/Bogus.Tests/RandomizerTest.cs +++ b/Source/Bogus.Tests/RandomizerTest.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Runtime.InteropServices; using FluentAssertions; using NUnit.Framework; @@ -69,6 +71,13 @@ public void can_get_some_random_words() r.Words().Should().Be("Handcrafted Granite Gloves Directives"); r.Words().Should().Be("Corner Handcrafted Frozen Chair transmitting"); } + + [Test] + public void can_shuffle_some_enumerable() + { + new string(r.Shuffle("123456789").ToArray()) + .Should().Be("628753491"); + } } diff --git a/Source/Bogus.Tests/UniquenessTests.cs b/Source/Bogus.Tests/UniquenessTests.cs index 1db09b40..0b9216b5 100644 --- a/Source/Bogus.Tests/UniquenessTests.cs +++ b/Source/Bogus.Tests/UniquenessTests.cs @@ -72,5 +72,19 @@ public void should_be_able_to_create_some_hash_ids() ids.Should().BeEquivalentTo("gY", "jR", "k5", "l5", "mO"); } + [Test] + public void should_be_able_to_drive_manual_index() + { + int indexer = 0; + var faker = new Faker() + .RuleFor(u => u.FirstName, f => f.Name.FirstName()) + .RuleFor(u => u.LastName, f => new[] {"A", "B", "C", "D"}[indexer % 4]) + .FinishWith((f, u) => indexer++); + + var fakes = faker.Generate(10).ToList(); + + fakes.Dump(); + } + } } \ No newline at end of file diff --git a/Source/Bogus/Faker[T].cs b/Source/Bogus/Faker[T].cs index 2172ccf0..b86733f0 100644 --- a/Source/Bogus/Faker[T].cs +++ b/Source/Bogus/Faker[T].cs @@ -83,13 +83,11 @@ public Faker RuleFor(Expression> property, Func } /// - /// RuleFor helper for constant string values. + /// Creates a rule for a property. /// - /// Constant string value used to set the property. - /// - public Faker RuleFor(Expression> property, TProperty constantValue) + public Faker RuleFor(Expression> property, Func valueFunction) { - return RuleFor(property, (f) => constantValue); + return RuleFor(property, (f) => valueFunction()); } ///