Skip to content

Instantly share code, notes, and snippets.

@leegould
Last active June 11, 2021 10:48
Show Gist options
  • Save leegould/5782638 to your computer and use it in GitHub Desktop.
Save leegould/5782638 to your computer and use it in GitHub Desktop.
Faking ODataQueryOptions for WebAPI
public static class Fakes
{
public static ODataQueryOptions ODataQueryOptionsFake(Type itemtype, HttpRequestMessage request, string expandValue, string inlineCountValue)
{
var odataQueryOptionsFake = new ODataQueryOptions(Substitute.For<ODataQueryContext>(Substitute.For<IEdmModel>(), itemtype), request);
var rawValuesFake = new ODataRawQueryOptions();
typeof(ODataRawQueryOptions).GetProperty("Expand").SetValue(rawValuesFake, expandValue);
typeof(ODataRawQueryOptions).GetProperty("InlineCount").SetValue(rawValuesFake, inlineCountValue);
typeof(ODataQueryOptions).GetProperty("RawValues").SetValue(odataQueryOptionsFake, rawValuesFake);
return odataQueryOptionsFake;
}
public static ODataQueryOptions<T> ODataQueryOptionsFake<T>(HttpRequestMessage request, string expandValue, string inlineCountValue)
{
var odataQueryOptionsFake = new ODataQueryOptions<T>(Substitute.For<ODataQueryContext>(Substitute.For<IEdmModel>(), typeof(T)), request);
var rawValuesFake = new ODataRawQueryOptions();
typeof(ODataRawQueryOptions).GetProperty("Expand").SetValue(rawValuesFake, expandValue);
typeof(ODataRawQueryOptions).GetProperty("InlineCount").SetValue(rawValuesFake, inlineCountValue);
typeof(ODataQueryOptions).GetProperty("RawValues").SetValue(odataQueryOptionsFake, rawValuesFake);
return odataQueryOptionsFake;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment