Skip to content

Remove/Clear CustomHandlers just like ClearSubstitute() #947

Description

@PawelKaminski-Rel

Question
I am using for each test and each test object redirections of calls to a singleton Substitute, requirement from the project.
So for each test I am adding custom Redirect handler.

ICallRouter callRouterFor = SubstitutionContext.Current.GetCallRouterFor(substitute); callRouterFor .RegisterCustomCallHandlerFactory( factory: _ => new RedirectAllHandler(target));

Problem:
Each test is creating new redirect but I am not able to remove them in the test teardown. ClearSubstitute() method is clearing other aspects of substitute but it is not clearing CustomHandlers.
I was looking for the way to clear/dispose object from CustomHandlers but I am unable to find it. Probably my use case is weird and for normal setup this is not required to clear this list.

Question: Is there a method or option to invert RegisterCustomCallHandlerFactory?? Or Clear CustomHandlers for each test and completely "Reset" Substitute?

Regars

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