Last active
June 11, 2021 10:48
-
-
Save leegould/5782638 to your computer and use it in GitHub Desktop.
Faking ODataQueryOptions for WebAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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