0

In FluentAssertions, how does one capture an exception thrown by an invocation? Exceptions shows basic code samples, but in my case I have a CustomException with a public enum. I'd like to assert that the correct enum value was thrown.

public class CustomException : Exception
{
   public MyEnum MyEnum { get; private set; }

   public CustomException(MyEnum myEnum)
   {
      MyEnum = myEnum;
   }
}
user246392
  • 2,661
  • 11
  • 54
  • 96

1 Answers1

4

I believe you can use .Where() to apply a custom condition to the caught exception:

act.Should().Throw<CustomException>().Where(e => e.MyEnum == MyEnum.Cheese);
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86