title: Exception while API Response cast
body: <p><a href="https://i.stack.imgur.com/HUrln.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HUrln.png" alt="enter image description here"></a></p>
  
  <p>I am facing issue while casting API response in a unit test case for testing an API call.</p>
  
  <p>I am using below line to compare Response Status code.</p>
  
  <pre><code>Assert.Equal(((int)eResp.Warn), ((ApiResponse)((ObjectResult)response).Value).StatusCode);
  </code></pre>
  
  <p>I am using below line to compare validation message.</p>
  
  <pre><code>Assert.Equal("Please enter a unique Name.", ((ApiResponse)((ObjectResult)response).Value).Message);
  </code></pre>
  
  <p>Below line returns response from controller</p>
  
  <pre><code> return Ok(new { Response = GetWarning(Warningmessage, MessageType) });
  </code></pre>
  
  <p>GetWarning method returns response as follows</p>
  
  <pre><code>return new ApiResponse((int)HttpStatusCode.Accepted, warningMessage, MessageType);
  </code></pre>
  
  <p>But I am getting an error of "Invalid cast". Attached is a screenshot of response object</p>
  
  <p><a href="https://i.stack.imgur.com/AdSpv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AdSpv.png" alt="enter image description here"></a></p>
  
  <p>How to cast correctly and solve this issue?</p>