OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
855 stars 473 forks source link

Support: Add interface to create ODataQueryOptions via a mock framework #1645

Open ynauls opened 6 years ago

ynauls commented 6 years ago

Add interface/support to unit test ODataQueryOptions with a mock framework. I implemented logic using the following sample from here Server-Driven Paging. The code works, however, i am unable to unit test due to complexity of creating ODataQueryOptions

public PageResult<Product> Get(ODataQueryOptions<Product> options)
{
    ODataQuerySettings settings = new ODataQuerySettings()
    {
        PageSize = 5
    };

    IQueryable results = options.ApplyTo(_products.AsQueryable(), settings);

    return new PageResult<Product>(
        results as IEnumerable<Product>, 
        Request.GetNextPageLink(), 
        Request.GetInlineCount());
}

Assemblies affected

Microsoft.AspNet.OData.Query (7.0.1)

Reproduce steps

Create unit test sample outside "Microsoft.AspNet.OData" package.

Expected result

Able to easily create unit test for logic passing in a ODataQueryOptions

Actual result

unable to create unit tests

freeranger commented 6 years ago

@ynauls https://github.com/OData/WebApi/issues/1352#issuecomment-397385479 may help you with your unit testing - not nice, but it works :)

ynauls commented 6 years ago

@freeranger, thank you, i saw that earlier and it works. I would def like some support out of the box :)