Skip to content

Mark Substitute.For<T> method as Pure #842

@Dzliera

Description

@Dzliera

Problem Description:

Consider I have piece of code var a = Substitute.For<ISomeIterface>();. After some time I do no longer use this variable a in code, so my IDE shows warning with quick fix to delete declaration of this variable, I accept this quick fix, but instead of removing whole statement he removes only left part of assigment. After quick fix, this line looks like this: Substitute.For<ISomeIterface>();. I had such cases many time and its very inconvenient, because after IDE code cleanup you have to look for such leftover Substitute.For<T>(); calls.

Cause:

This behavior is caused because IDE does not know that Substitute.For<ISomeIterface>(); in fact is Pure method, meaning that it just returns value and does not have any side effects.

Fix:

This has a very easy fix: Add PureAttribute (See Docs) to Substitute.For<T>() (and all other overloads).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions