Web API, OData, $inlinecount and testing

Topics: ASP.NET Web API
Apr 4, 2013 at 12:34 PM
I previously had a Web API controller that looked like this:
public IQueryable<ApiDesignOverview> GetList(
    string brandIds = "", 
    string categoryIds = "", 
    string query = "",
    string categoryOp = "or")
I heard that the OData NuGet package now supports the $inlinecount OData parameter, so I tried to add it using the instructions from http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options - I don't want to have to use OData wholesale as that would entail a large amount of re-architecturing of the app, so I went for the PageResult<T> option.

So now my controller looks like this:
public PageResult<ApiDesignOverview> GetList(
    ODataQueryOptions<ApiDesignOverview> options,
    string brandIds = "", 
    string categoryIds = "", 
    string query = "",
    string categoryOp = "or")
My problems are now:
  • How do I mock a ODataQueryOptions for unit testing?
  • If they can't be mocked, how do I create one? I need a ODataQueryContext to construct one, which requires a Microsoft.Data.Edm.IEdmModel, which requires... what? I can't find any documentation for this.
Really, it would be better if I could remove the ODataQueryOptions from the controller signature like before. Is this possible?
Apr 4, 2013 at 4:24 PM
I answered your question already on stackoverflow. http://stackoverflow.com/questions/15790695/web-api-odata-inlinecount-and-testing/

Also, regarding the testability thing, we have this bug for making it easier to build inferred models used by QueryableAttribute. That issue once resolved would make it easier to build ODataQueryOptions<T> for testing.
Apr 4, 2013 at 5:00 PM
Thanks raghuramn - as I received only one answer there I though I would bring it here to check if there were any other suggestions from the developers - I didn't realise that the answer on SO was from a developer! I will follow your suggestion there.