How to mock func delegate in .net

I have a Func<> property in a controller, and I am wondering how can I mock it.

Here is my code:

public Func<HttpRequest, string> GetId { get; set; }

Here is the usage in the controller's constructor:

GetId = req => req.HttpContext.Items["random-id"].ToString();

and here is the usage in individual methods and API calls:

var id = GetId (Request);

The above Func<> property is used in all the API calls in the controller and its constructor. I am trying to mock it so I don't have to deal with that while writing unit tests. Any suggestions?



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Network Error and Timeout on Authorize.net JS