public void Property_Value_WorksWithUnTypedContext() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer); InlineCountQueryOption inlineCount = new InlineCountQueryOption("allpages", context); // Act & Assert Assert.Equal(InlineCountValue.AllPages, inlineCount.Value); }
public void GetEntityCount_WithUnTypedContext_Throws_InvalidOperation() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer); InlineCountQueryOption inlineCount = new InlineCountQueryOption("allpages", context); IQueryable queryable = new Mock <IQueryable>().Object; // Act & Assert Assert.Throws <NotSupportedException>(() => inlineCount.GetEntityCount(queryable), "The query option is not bound to any CLR type. 'GetEntityCount' is only supported with a query option bound to a CLR type."); }
public void GetEntityCount_ReturnsNull_IfValueIsNone() { var inlineCount = new InlineCountQueryOption("none", _context); Assert.Null(inlineCount.GetEntityCount(_customers)); }
public void GetEntityCount_ReturnsCount_IfValueIsAllPages() { var inlineCount = new InlineCountQueryOption("allpages", _context); Assert.Equal(3, inlineCount.GetEntityCount(_customers)); }
public void Value_ThrowsODataException_ForInvalidValues(string inlineCountValue) { var inlineCount = new InlineCountQueryOption(inlineCountValue, _context); Assert.Throws <ODataException>(() => inlineCount.Value); }
public void Value_Returns_ParsedInlineCountValue(string inlineCountValue, InlineCountValue expectedValue) { var inlineCount = new InlineCountQueryOption(inlineCountValue, _context); Assert.Equal(expectedValue, inlineCount.Value); }
public void GetEntityCount_WithUnTypedContext_Throws_InvalidOperation() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer); InlineCountQueryOption inlineCount = new InlineCountQueryOption("allpages", context); IQueryable queryable = new Mock<IQueryable>().Object; // Act & Assert Assert.Throws<NotSupportedException>(() => inlineCount.GetEntityCount(queryable), "The query option is not bound to any CLR type. 'GetEntityCount' is only supported with a query option bound to a CLR type."); }
/// <summary> /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from /// the <see cref="ODataQueryContext"/>. /// </summary> /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param> /// <param name="request">The incoming request message.</param> public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request) { if (context == null) { throw Error.ArgumentNull("context"); } if (request == null) { throw Error.ArgumentNull("request"); } if (request.GetConfiguration() != null) { _assembliesResolver = request.GetConfiguration().Services.GetAssembliesResolver(); } // fallback to the default assemblies resolver if none available. _assembliesResolver = _assembliesResolver ?? new DefaultAssembliesResolver(); // remember the context and request Context = context; Request = request; // Parse the query from request Uri RawValues = new ODataRawQueryOptions(); IEnumerable <KeyValuePair <string, string> > queryParameters = request.GetQueryNameValuePairs(); foreach (KeyValuePair <string, string> kvp in queryParameters) { switch (kvp.Key) { case "$filter": RawValues.Filter = kvp.Value; ThrowIfEmpty(kvp.Value, "$filter"); Filter = new FilterQueryOption(kvp.Value, context); break; case "$orderby": RawValues.OrderBy = kvp.Value; ThrowIfEmpty(kvp.Value, "$orderby"); OrderBy = new OrderByQueryOption(kvp.Value, context); break; case "$top": RawValues.Top = kvp.Value; ThrowIfEmpty(kvp.Value, "$top"); Top = new TopQueryOption(kvp.Value, context); break; case "$skip": RawValues.Skip = kvp.Value; ThrowIfEmpty(kvp.Value, "$skip"); Skip = new SkipQueryOption(kvp.Value, context); break; case "$select": RawValues.Select = kvp.Value; break; case "$inlinecount": RawValues.InlineCount = kvp.Value; ThrowIfEmpty(kvp.Value, "$inlinecount"); InlineCount = new InlineCountQueryOption(kvp.Value, context); break; case "$expand": RawValues.Expand = kvp.Value; break; case "$format": RawValues.Format = kvp.Value; break; case "$skiptoken": RawValues.SkipToken = kvp.Value; break; default: // we don't throw if we can't recognize the query break; } } Validator = new ODataQueryValidator(); }
public void Value_ThrowsODataException_ForInvalidValues(string inlineCountValue) { var inlineCount = new InlineCountQueryOption(inlineCountValue, _context); Assert.Throws<ODataException>(() => inlineCount.Value); }