Change NUnit Assertion behaviour

himanshu.dwivedi's Avatar


14 Jun, 2018 07:34 PM

How can I change my Assert statement behaviour from:

Assert.That(User.HasOrderInvoice, Is.True)
Assert.That(User.HasOrderInvoice, Is.True, "Assert.That(User.HasOrderInvoice, Is.True)")

I don't see a way to do this on PostSharp.

  1. Support Staff 1 Posted by PostSharp Techn... on 15 Jun, 2018 09:21 AM

    PostSharp Technologies's Avatar


    is your goal to preserve the code exactly? If so, it's probably better to do this with Roslyn as you would have access to the actual code.

    PostSharp currently doesn't have supported (documented) way to alter code on call site level. Most of aspects actually change either type or method declarations, not the site these are used on.

    Best regards,

  2. 2 Posted by himanshu.dwived... on 18 Jun, 2018 11:25 PM

    himanshu.dwivedi's Avatar

    If that's not possible then at least there should be a way to change the behaviour by intercepting the call?

  3. Support Staff 3 Posted by PostSharp Techn... on 19 Jun, 2018 01:17 PM

    PostSharp Technologies's Avatar


    using PostSharp's method interception you don't get access to the original code, just to the methods signatures and values of method call parameters. So as Daniel recommended, you'd need Roslyn (or another tool) to obtain the source code of the method call.

    Best regards,

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac