machine/machine.specifications — Issue #80: Checking for ParamName in a NullArgumentException is complicated
Author: thedrow
Created: 2011-11-28 16:39:32+00:00
State: open

I am currently testing the initialization of a class with null constructor arguments and I'd like to be sure that the correct exception is thrown in terms of the faulting argument name.
I haven't found a one liner that expresses that sort of assertion except this one:

```csharp
It should_throw_a_null_argument_exception_with_a_param_name_that_is_equal_to_allowed_hours_service_plans_validator_factory = () => (exception as ArgumentNullException).ParamName.ShouldBeTheSameAs("allowedHoursServicePlansValidatorFactory");
```

If the thrown exception isn't an ArgumentNullException the assertion hides it's true intention by throwing a NullReferenceException which isn't helpful.
Is there a better way to implement this kind of test? Is this a missing feature?