0

I am just starting with FsCheck and wanted to dig a little deeper, I have the following test case:

[Property]
public void some_test(HttpStatusCode httpStatusCode)

Now, I only want httpStatusCode which are failures, how do I achieve that using FsCheck? I have the following code:

Prop.ForAll<HttpStatusCode>(code => new Func<bool>(() => !new HttpResponseMessage(code).IsSuccessStatusCode).When(true)).QuickCheck();

But have no idea how to hook that into the Property attribute for my test case. Examples online are fairly convoluted for something so trivial. Any help or guidance will be appreciated.

Would be nice to have something like this but for custom objects and custom logic.

Cheers.

Ruskin
  • 1,504
  • 13
  • 25

1 Answers1

0

You can use the When method to filter.

Something like:

Prop.ForAll<HttpStatusCode>(code => 
    !new HttpResponseMessage(code).IsSuccessStatusCode)
    .When(code is failure)   
)
.QuickCheck();
Kurt Schelfthout
  • 8,880
  • 1
  • 30
  • 48