Skip to content

Create a refactoring for asserting exceptions properties #55

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
Meir017 opened this issue Jun 21, 2018 · 3 comments
Open

Create a refactoring for asserting exceptions properties #55

Meir017 opened this issue Jun 21, 2018 · 3 comments
Labels

Comments

@Meir017
Copy link
Member

Meir017 commented Jun 21, 2018

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;
    }
}
@Meir017 Meir017 added the idea label Jun 21, 2018
@Meir017
Copy link
Member Author

Meir017 commented Jun 21, 2018

@jnyrup @dennisdoomen does this make sense?

@dennisdoomen
Copy link
Member

Sure.

@jnyrup
Copy link
Member

jnyrup commented Jun 24, 2018

I don't really have any gut feelings about this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants