-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FsCheck generating test objects in C# #656
Comments
For number 2, you can use the query syntax var generator =
from name in Arb.Generate<string>()
from phone in Arb.Generate<string>()
select new Department
{
Name = name,
Shorthand = name.Substring(0, 2),
InternalPhonePrefix = phone
} |
Thanks! That's quite handy |
It's also useful if you're using the CSharpFunctionalExtensions nuget package. You can do the same thing with a bunch of |
FsCheck cannot currently do this, based on the type alone. From a quick searc, since .NET 6 or 7 we can check the nullability of a type at runtime, so this may be possible to implement via that route.
@BennieCopeland's is probably the best way to do that. |
Interesting 👍
Yup, that actually works pretty well. |
Hi there 👋
I'm trying to generate a list of C# records as test data for a property based test, but face a few issues.
1. Nullable reference types
How can I configure the generator to respect nullability of reference types in C#?
FullName
is not allowed to be null -> don't generate null valuesNotes
is allowed to be null -> generate null values2. Generating complex objects
Let's assume I need to generate random samples of the type below, but there are certain rules on what's valid input.
Example Rules:
Name: Any not null string
Shorthand: First 3 chars from Name, if Name is shorter then 3 then equal to Name.
InternalPhonePrefix: Any random string.
(excuse my silly examples 🙃)
I guess this would work, but is there a better way?
The text was updated successfully, but these errors were encountered: