Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NFluent: fluently check a property of an exception

I have a function that is supposed to raise an exception FooException. This exception has a list of items stored in one of its properties AffectedElements. How can I perform tests against this list? For example:

Check.ThatCode(() => somefunction("qux", 1, null))
     .Throws<FooException>()
     .«WhatDoIPutHere»
     .IsInAscendingOrder();
like image 525
liori Avatar asked Oct 17 '25 06:10

liori


1 Answers

As of now, there is no way to extract a field/property from an exception to check it. The best you can do is use WithProperty which only support equality check:

Check.ThatCode(() => somefunction("qux", 1, null))
 .Throws<FooException>()
 .WithProperty("propName", expectedValue);

Update: The latest version of NFluent offers a feature for that. see the wiki

like image 130
Cyrille Dupuydauby Avatar answered Oct 18 '25 22:10

Cyrille Dupuydauby