예제 #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);
        }
예제 #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;
 }
예제 #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;
 }
예제 #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"}));
        }
예제 #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"}));
        }
예제 #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;
 }
예제 #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;
        }
예제 #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;
 }
예제 #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;
 }
예제 #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;
 }
예제 #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;
 }
예제 #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" }));
        }