ApiController.Ok() returns null in unit tests
<p>I have recently moved to a new project at my company. I have been tasked with writing unit tests for one of our controllers for a REST API. The controller implements the <a href="https://msdn.microsoft.com/en-us/library/system.web.http.apicontroller(v=vs.118).aspx" rel="nofollow">System.Web.Http.ApiController</a> interface.  I am using <a href="https://www.nuget.org/packages/Moq/" rel="nofollow">Moq</a>, and it is my first time using this cool little library. My issue is that when I call </p>

<pre><code>IHttpActionResult result = Ok();
</code></pre>

<p>in the controller, the call to Ok() returns null. This only happens when I am calling this method from the unit tests. If I call my method directly using Swagger, it works as expected. </p>

<p>I am thinking that possibly the Moq statements I'm using to setup the controller arguments/controller itself are messing with the instantiation of the controller somehow and making the inherited interface methods not accessible? Here is the code I'm using to set up the unit test:</p>

<pre><code>//Mock ICrmService to return an Id for a created company
var crmCacheService = new Mock&lt;ICrmCacheService&gt;();
var crmService = new Mock&lt;ICrmService&gt;();

crmCacheService.Setup(x =&gt; x.CreateSubscription(It.IsAny&lt;CreateSubscriptionModel&gt;())).Returns(true);
crmService.Setup(x =&gt; x.CreateSubscription(It.IsAny&lt;CreateSubscriptionModel&gt;())).Returns(ReturnedSubscriptionId);

var controller = new Mock&lt;SubscriptionController&gt;(crmService.Object, crmCacheService.Object);
IHttpActionResult actionResult = controller.Object.CreateSubscriptions(Guid.NewGuid().ToString(), 1);
</code></pre>

<p>Does anyone have any idea why this would make the call to Ok() return null? And how I could set it up so that a call to Ok() will return the normal result of System.Web.Http.Results.OkResult?</p>