I'm trying to create a not empty string generator but when running the test I still have empty strings as inputs.
Here is the code I wrote:
[Test]
public void MyTest()
{
Func<Gen<string>> generateNotEmptyString = () =>
{
var gen = Any.OfType<string>()
.Where(name => !string.IsNullOrEmpty(name));
return gen;
};
Action<string> assertIdIsNeverEmpty = name =>
{
var id = MyService.CreateId(name);
id.Should().NotBeNullOrEmpty();
};
Spec.For(generateNotEmptyString(), assertIdIsNeverEmpty)
.QuickCheckThrowOnFailure()
}
I'm using NUnit v. 2.6.2.12296, FsCheck v. 0.9.4.0 and FluentAssertions v. 3.0.90.0.
What if I also want to modify the generator so that it creates not empty strings that match a regular expression?
[EDIT] This is the code I'm using to create strings that contain letters but don't contain special characters:
private static Gen<NonEmptyString> GenerateValidNames()
{
return
Any.OfType<NonEmptyString>()
.Where(s =>
!s.Get.Contains("\r") &&
!s.Get.Contains("\n") &&
!s.Get.Contains("\t"))
.Where(s =>
{
var regEx = new Regex(@"^[A-Za-z]*$");
return regEx.Match(s.Get).Success;
});
}