Skip to content

Create a refactoring for asserting exceptions properties #55

Open
@Meir017

Description

@Meir017

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions