Ejemplo n.º 1
0
        /// <summary>
        /// Handles a GET request to query entities.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The task object that contains the response message.</returns>
        public async Task<HttpResponseMessage> Get(
            CancellationToken cancellationToken)
        {
            HttpRequestMessageProperties odataProperties = this.Request.ODataProperties();
            ODataPath path = odataProperties.Path;
            if (path == null)
            {
                throw new InvalidOperationException(Resources.ControllerRequiresPath);
            }

            IQueryable queryable = this.GetQuery();
            QueryRequest queryRequest = new QueryRequest(queryable, this.includeTotalCount)
            {
                ShouldReturnCount = this.shouldReturnCount
            };
            QueryResult queryResult = await Api.QueryAsync(queryRequest, cancellationToken);
            if (this.includeTotalCount == true)
            {
                this.Request.ODataProperties().TotalCount = queryResult.TotalCount;
            }

            this.Request.Properties[ETagGetterKey] = this.Api.Context.GetProperty(ETagGetterKey);

            return this.CreateQueryResponse(queryResult.Results.AsQueryable(), path.EdmType);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="serviceProvider">
 /// The service provider to get services.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(IServiceProvider serviceProvider, QueryRequest request)
     : base(serviceProvider)
 {
     Ensure.NotNull(request, nameof(request));
     Request = request;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="apiContext">
 /// An API context.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(ApiContext apiContext, QueryRequest request)
     : base(apiContext)
 {
     Ensure.NotNull(request, "request");
     this.Request = request;
 }
Ejemplo n.º 4
0
        public async Task ApiQueryAsyncWithQueryReturnsResults()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var request = new QueryRequest(api.GetQueryableSource<string>("Test"));
            var result = await api.Context.QueryAsync(request);
            var results = result.Results.Cast<string>();

            Assert.True(results.SequenceEqual(new[] {"Test"}));
        }
Ejemplo n.º 5
0
        public async Task ApiQueryAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var queryRequest = new QueryRequest(
                api.GetQueryableSource<string>("Test"));
            var queryResult = await api.QueryAsync(queryRequest);
            Assert.True(queryResult.Results.Cast<string>()
                .SequenceEqual(new[] {"Test"}));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="api">
 /// An Api.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(ApiBase api, QueryRequest request)
     : base(api)
 {
     Ensure.NotNull(request, nameof(request));
     Request = request;
 }
Ejemplo n.º 7
0
        private async Task<IQueryable> ExecuteQuery(IQueryable queryable, CancellationToken cancellationToken)
        {
            QueryRequest queryRequest = new QueryRequest(queryable)
            {
                ShouldReturnCount = this.shouldReturnCount
            };

            QueryResult queryResult = await Api.QueryAsync(queryRequest, cancellationToken);
            var result = queryResult.Results.AsQueryable();
            return result;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="serviceProvider">
 /// The service provider to get services.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(IServiceProvider serviceProvider, QueryRequest request)
     : base(serviceProvider)
 {
     Ensure.NotNull(request, "request");
     this.Request = request;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="domainContext">
 /// A domain context.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(DomainContext domainContext, QueryRequest request)
     : base(domainContext)
 {
     Ensure.NotNull(request, "request");
     this.Request = request;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="domainContext">
 /// A domain context.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(DomainContext domainContext, QueryRequest request)
     : base(domainContext)
 {
     Ensure.NotNull(request, "request");
     this.Request = request;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryContext" /> class.
 /// </summary>
 /// <param name="apiContext">
 /// An API context.
 /// </param>
 /// <param name="request">
 /// A query request.
 /// </param>
 public QueryContext(ApiContext apiContext, QueryRequest request)
     : base(apiContext)
 {
     Ensure.NotNull(request, "request");
     this.Request = request;
 }
Ejemplo n.º 12
0
        public async Task ApiQueryAsyncCorrectlyForwardsCall()
        {
            var api = new TestApi();

            var queryRequest = new QueryRequest(
                api.Source<string>("Test"));
            var queryResult = await api.QueryAsync(queryRequest);
            Assert.True(queryResult.Results.Cast<string>()
                .SequenceEqual(new string[] { "Test" }));
        }