Skip to content

Unit testing classes using IFusionCache is difficult due to reliance on extension methods #610

@petriceko

Description

@petriceko

Hi 👋

I’m trying to write unit tests for a class that depends on IFusionCache.

The issue I’m facing is that most of the commonly used methods (like GetOrSetAsync, etc.) are implemented as extension methods in the NuGet package. Because of that:

  • These methods are static extension methods
  • They are not directly part of the IFusionCache interface
  • They cannot be mocked with standard mocking frameworks (e.g. Moq, NSubstitute, etc.)
  • It’s unclear which underlying interface method is actually being invoked internally

As a result, when I mock IFusionCache, my tests fail because the extension methods are not interceptable, and I don’t know which original interface method I should be setting up in my mock.

Would it be possible to move key methods into the interface instead of extension methods to improve mockability?

Regards

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