title: Unit-testing a Stored Procedure who is implemented in WebAPI Ctrl
body: <p>I have the following problem. I'm new in unit testing and need to test WebAPI Ctrl with GET-Requests who has implemented stored procedures. The Model are created with Entity Framework who generated code with connection to the stored procedures in my MS SQL Server.</p>
  
  <p>To understand it, here is the generic code:</p>
  
  <pre><code>//Controller
  namespace WebApi.Controllers
  {
      [RoutePrefix("api/ds21")]
      public class DS21Controller : ApiController
      {
          private SampleContext db = new SampleContext();
  
          [HttpGet]
          public IQueryable&lt;RepDTO&gt; GetByDate(DateTime endDate)
          {
              var res = db.getDayRep(endDate).AsQueryable();
              return res;
          }
      ...
      }
  }
  </code></pre>
  
  <p>The generated Model Context of Entity Framework:</p>
  
  <pre><code>//Model SampleModel.Context.cs (created from EF)
  public partial class SampleContext : DbContext
  {
     public SampleContext()
       : base("name=SampleContext")
     {
     }
  
     ...
  
     public DbSet&lt;DS21&gt; DS21s { get; set; }
  
     public virtual ObjectResult&lt;RepDTO&gt; getDayRep(Nullable&lt;System.DateTime&gt; endDate)
     {
        var endDateParameter = endDate.HasValue ?
            new ObjectParameter("endDate", endDate) :
            new ObjectParameter("endDate", typeof(System.DateTime));
  
        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;RepDTO&gt;("getDayRep", endDateParameter);
     }
  </code></pre>
  
  <p>That's the Model DTO:</p>
  
  <pre><code>public partial class RepDTO
  {
     public System.DateTime datum { get; set; }
     public string articleNr { get; set; }
     public string fname { get; set; }
  }
  </code></pre>
  
  <p>I don't know how to test the WebAPI Controllers like the sample code above?! Can anyone give me some help? I've tried to combine <a href="http://www.asp.net/web-api/overview/testing-and-debugging/mocking-entity-framework-when-unit-testing-aspnet-web-api-2" rel="nofollow">this</a> but the author doesn't use stored procedures in his article.</p>