fluentassertions.analyzers
fluentassertions.analyzers copied to clipboard
Create a refactoring for asserting exceptions properties
for example:
public class MyCustomException : Exception
{
public string MyCustomProperty { get; }
public MyCustomException(string myCustomProperty)
{
MyCustomProperty = MyCustomProperty;
}
}
when hovering over the property MyCustomProperty I would like to have a suggestion to generate an assertion for that property.
The generated assertion will something like this:
public static class MyCustomExceptionExtensions
{
public static ExceptionAssertions<TException> WithMyCustomProperty<TException>(this ExceptionAssertions<TException> assertions,
string expectedMyCustomProperty, string because = "", params object[] becauseArgs) where TException : MyCustomException
{
Execute.Assertion
.ForCondition(assertions.And.MyCustomProperty.Equals(expectedMyCustomProperty))
.BecauseOf(because, becauseArgs)
.FailWith("Expected exception with MyCustomProperty {0}{reason}, but found {1}.", assertions.And.MyCustomProperty, expectedMyCustomProperty);
return assertions;
}
}
@jnyrup @dennisdoomen does this make sense?
Sure.
I don't really have any gut feelings about this.