示例#1
0
        private void MaterializeTest(HttpStatusCode statusCode, ODataPayloadKind payloadKind)
        {
            var uri             = new Uri("http://any");
            var context         = new DataServiceContext().ReConfigureForNetworkLoadingTests();
            var requestInfo     = new RequestInfo(context);
            var responseInfo    = new ResponseInfo(requestInfo, MergeOption.OverwriteChanges);
            var queryComponents = new QueryComponents(uri, new Version(4, 0), typeof(Product), null, null);
            var responseMessage = new HttpWebResponseMessage(
                new HeaderCollection(),
                (int)statusCode,
                () => new MemoryStream());
            var materialize = DataServiceRequest.Materialize(
                responseInfo,
                queryComponents,
                null,
                "application/json",
                responseMessage,
                payloadKind);

            Assert.IsNull(materialize.Context);
            Assert.IsNull(materialize.Current);
            var enumerable = materialize.Cast <object>();

            Assert.AreEqual(0, enumerable.Count());
        }
示例#2
0
        /// <summary>
        /// Creates an instance of <see cref="MaterializeAtom"/> for the given plan.
        /// </summary>
        /// <param name="plan">The projection plan.</param>
        /// <param name="payloadKind">expected payload kind.</param>
        /// <returns>A new materializer instance</returns>
        private MaterializeAtom CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
        {
            QueryComponents queryComponents = this.ServiceRequest.QueryComponents(this.responseInfo.Model);

            // In V2, in projection path, we did not check for assignability between the expected type and the type returned by the type resolver.
            if (plan != null || queryComponents.Projection != null)
            {
                this.RequestInfo.TypeResolver.IsProjectionRequest();
            }

            var responseMessageWrapper = new HttpWebResponseMessage(
                new HeaderCollection(this.responseMessage),
                this.responseMessage.StatusCode,
                this.GetResponseStream);

            return(DataServiceRequest.Materialize(
                       this.responseInfo,
                       queryComponents,
                       plan,
                       this.ContentType,
                       responseMessageWrapper,
                       payloadKind));
        }