Skip to content

Getting errors when attempting to setup a method with an out parameter #436

@sspringer

Description

@sspringer

I am having a very difficult time attempting to mock the ASP.Net Core IMemoryCache object. I have the mock set up as follows:

var memoryCacheMoq = new Mock<IMemoryCache>();
Lookup dummy = new Lookup {  };
memoryCacheMoq.Setup(m => m.TryGetValue(It.IsAny<object>(), out dummy)).Returns(false);

I want the method to return false so my database mock performs what it's supposed to do.

When I debug this, I get the following error when it gets to the setup line:

Message: System.NotSupportedException : Invalid setup on an extension method: m => m.TryGetValue<Lookup>(It.IsAny<Object>(), .dummy)

From everything I've read, and even watched an example on PluralSight, this is the way to set this up.

Any assistance is greatly appreciated! Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions