Scoping contant FsCheck generator to each test

53 views Asked by At

I am trying to test a domain model for a SaaS application with FsCheck and XUnit. Each model entity has a column TenantId with some unique tenant identifier. There are numerous Asserts checking that TenantIds are not mixed up.

For now, I have this TenantId generated with Gen.Constant generator. However, this is fixing the value for the whole test run, so all tests are using the same TenantId. It would be more convenient if this value would be reset for each test but stay constant within a test.

To be more specific, let's say that there are two entities and the class for TenantId:

public record TenantId(Guid value);

public record EntityA(TenantId TenantId, string SomeString);

public record EntityA(TenantId TenantId, int SomeNumber);

And some xUnit tests annotated with [Property]:

[Property]
public void PropertyTest1(EntityA a, EntityB b) => Assert(a.TenantId == b.TenantId);

[Property]
public void PropertyTest2(EntityA a, EntityB b) => Assert(a.TenantId == b.TenantId);

Is it possible to configure an Arbitrary for TenantId type so it will different values for PropertyTest1 and PropertyTest2, but constant value inside these tests?

0

There are 0 answers