Exemplo n.º 1
0
        private static void RunNegotiatedFormatTest(string requestAccept, string requestMaxVersion, Microsoft.OData.Client.ODataProtocolVersion maxProtocolVersion, ODataFormat expectedFormat)
        {
            DataServiceHostSimulator host = new DataServiceHostSimulator
            {
                RequestHttpMethod = "GET",
                RequestAccept = requestAccept,
                RequestMaxVersion = requestMaxVersion,
                RequestVersion = "4.0",
            };
            DataServiceSimulator service = new DataServiceSimulator
            {
                OperationContext = new DataServiceOperationContext(host),
                Configuration = new DataServiceConfiguration(new DataServiceProviderSimulator()),
            };

            service.Configuration.DataServiceBehavior.MaxProtocolVersion = maxProtocolVersion;
            service.OperationContext.InitializeAndCacheHeaders(service);
            service.OperationContext.RequestMessage.InitializeRequestVersionHeaders(VersionUtil.ToVersion(maxProtocolVersion));

            var d = new RequestDescription(RequestTargetKind.Primitive, RequestTargetSource.Property, new Uri("http://temp.org/"));

            d.DetermineWhetherResponseBodyOrETagShouldBeWritten(service.OperationContext.RequestMessage.HttpVerb);
            d.DetermineWhetherResponseBodyShouldBeWritten(service.OperationContext.RequestMessage.HttpVerb);
            d.DetermineResponseFormat(service);
            d.ResponseFormat.Should().NotBeNull();
            d.ResponseFormat.Format.Should().BeSameAs(expectedFormat);
        }
        private MessageWriterBuilder ForNormalRequest(RequestDescription requestDescription)
        {
            this.dataServiceSimulator.OperationContext.InitializeAndCacheHeaders(this.dataServiceSimulator);
            this.dataServiceSimulator.OperationContext.RequestMessage.CacheHeaders();
            this.dataServiceSimulator.OperationContext.RequestMessage.InitializeRequestVersionHeaders(VersionUtil.Version4Dot0);

            requestDescription.ParseExpandAndSelect(this.dataServiceSimulator);
            requestDescription.DetermineWhetherResponseBodyOrETagShouldBeWritten(HttpVerbs.GET);
            requestDescription.DetermineWhetherResponseBodyShouldBeWritten(HttpVerbs.GET);
            requestDescription.DetermineResponseFormat(this.dataServiceSimulator);
            var testSubject = MessageWriterBuilder.ForNormalRequest(this.dataServiceSimulator, requestDescription, this.responseMessageSimulator, new EdmModel());
            return testSubject;
        }