當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpRequestMessage.SetODataPath方法代碼示例

本文整理匯總了C#中System.Net.Http.HttpRequestMessage.SetODataPath方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.SetODataPath方法的具體用法?C# HttpRequestMessage.SetODataPath怎麽用?C# HttpRequestMessage.SetODataPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.SetODataPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PostResponse_Throws_IfODataPathDoesNotStartWithEntitySet

        public void PostResponse_Throws_IfODataPathDoesNotStartWithEntitySet()
        {
            ApiController controller = new Mock<ApiController>().Object;
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Customers");
            controller.Configuration = new HttpConfiguration();
            request.SetODataPath(new ODataPath(new MetadataPathSegment()));
            controller.Request = request;

            Assert.Throws<InvalidOperationException>(
                () => EntitySetControllerHelpers.PostResponse<Customer, int>(controller, new Customer(), 5),
                "A Location header could not be generated because the request's OData path does not start with an entity set path segment.");
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:12,代碼來源:EntitySetControllerHelpersTest.cs

示例2: GetSampleRequest

 private HttpRequestMessage GetSampleRequest()
 {
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/employees");
     HttpConfiguration configuration = new HttpConfiguration();
     string routeName = "Route";
     configuration.Routes.MapODataRoute(routeName, null, GetSampleModel());
     request.SetConfiguration(configuration);
     IEdmEntitySet entitySet = _model.EntityContainers().Single().FindEntitySet("employees");
     request.SetEdmModel(_model);
     request.SetODataPath(new ODataPath(new EntitySetPathSegment(entitySet)));
     request.SetODataRouteName(routeName);
     return request;
 }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:13,代碼來源:FeedTest.cs

示例3: TryMatchMediaTypeWithBinaryRawValueMatchesRequest

        public void TryMatchMediaTypeWithBinaryRawValueMatchesRequest()
        {
            IEdmModel model = GetBinaryModel();
            PropertyAccessPathSegment propertySegment = new PropertyAccessPathSegment((model.GetEdmType(typeof(RawValueEntity)) as IEdmEntityType).FindProperty("BinaryProperty"));
            ODataPath path = new ODataPath(new EntitySetPathSegment("RawValue"), new KeyValuePathSegment("1"), propertySegment, new ValuePathSegment());
            ODataBinaryValueMediaTypeMapping mapping = new ODataBinaryValueMediaTypeMapping();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/RawValue(1)/BinaryProperty/$value");
            request.SetEdmModel(model);
            request.SetODataPath(path);

            double mapResult = mapping.TryMatchMediaType(request);

            Assert.Equal(1.0, mapResult);
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:14,代碼來源:ODataRawValueMediaTypeMappingTests.cs

示例4: TryMatchMediaTypeWithNonRawvalueRequestDoesntMatchRequest

        public void TryMatchMediaTypeWithNonRawvalueRequestDoesntMatchRequest()
        {
            IEdmModel model = ODataTestUtil.GetEdmModel();
            PropertyAccessPathSegment propertySegment = new PropertyAccessPathSegment((model.GetEdmType(typeof(FormatterPerson)) as IEdmEntityType).FindProperty("Age"));
            ODataPath path = new ODataPath(new EntitySetPathSegment("People"), new KeyValuePathSegment("1"), propertySegment);
            ODataPrimitiveValueMediaTypeMapping mapping = new ODataPrimitiveValueMediaTypeMapping();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/People(1)/Age/");
            request.SetEdmModel(model);
            request.SetODataPath(path);

            double mapResult = mapping.TryMatchMediaType(request);

            Assert.Equal(0, mapResult);
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:14,代碼來源:ODataRawValueMediaTypeMappingTests.cs

示例5: Match

        public override bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (routeDirection != HttpRouteDirection.UriResolution)
            {
                return true;
            }

            object odataPathValue;
            if (!values.TryGetValue(ODataRouteConstants.ODataPath, out odataPathValue))
            {
                return false;
            }

            var pathString = odataPathValue as string;
            if (pathString == null) pathString = string.Empty;

            ODataPath path = null;
            try
            {
                path = VersionAwarePathHandler.Parse(request, EdmModel, pathString);
            }
            catch (ODataException e)
            {
                throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid OData path", e));
            }

            if (path != null)
            {
                values[ODataRouteConstants.ODataPath] = path.Segments.First();
                // Set all the properties we need for routing, querying, formatting
                request.SetEdmModel(EdmModel);
                request.SetODataPathHandler(VersionAwarePathHandler);
                request.SetODataPath(path);
                request.SetODataRouteName(RouteName);
                request.SetODataRoutingConventions(RoutingConventions);

                if (!values.ContainsKey(ODataRouteConstants.Controller))
                {
                    // Select controller name using the routing conventions
                    string controllerName = SelectControllerName(path, request);
                    if (controllerName != null)
                    {
                        values[ODataRouteConstants.Controller] = controllerName;
                    }
                }
            }

            return path != null;
        }
開發者ID:jordansjones,項目名稱:ODataVersioning,代碼行數:49,代碼來源:VersionAwareODataPathRouteConstraint.cs

示例6: OnActionExecuted_DoesntChangeTheResponse_IfResponseIsntSuccessful

        public void OnActionExecuted_DoesntChangeTheResponse_IfResponseIsntSuccessful()
        {
            IEdmModel model = new Mock<IEdmModel>().Object;
            ODataPath path = new ODataPath(new EntitySetPathSegment("FakeEntitySet"),
                                           new KeyValuePathSegment("FakeKey"),
                                           new PropertyAccessPathSegment("FakeProperty"),
                                           new ValuePathSegment());
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/");
            request.SetEdmModel(model);
            request.SetODataPath(path);
            ODataNullValueAttribute odataNullValue = new ODataNullValueAttribute();
            HttpResponseMessage response = SetUpResponse(HttpStatusCode.InternalServerError, null, typeof(object));
            HttpActionExecutedContext context = SetUpContext(request, response);

            odataNullValue.OnActionExecuted(context);

            Assert.Equal(response, context.Response);
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:18,代碼來源:ODataNullValueAttributeTests.cs

示例7: OnActionExecuted_Generates404_IfContentIsNull

        public void OnActionExecuted_Generates404_IfContentIsNull()
        {
            IEdmModel model = new Mock<IEdmModel>().Object;
            ODataPath path = new ODataPath(new EntitySetPathSegment("FakeEntitySet"),
                                           new KeyValuePathSegment("FakeKey"),
                                           new PropertyAccessPathSegment("FakeProperty"),
                                           new ValuePathSegment());
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/");
            request.SetEdmModel(model);
            request.SetODataPath(path);
            ODataNullValueAttribute odataNullValue = new ODataNullValueAttribute();
            HttpResponseMessage response = SetUpResponse(HttpStatusCode.OK, null, typeof(object));
            HttpActionExecutedContext context = SetUpContext(request, response);

            odataNullValue.OnActionExecuted(context);

            Assert.NotNull(context.Response);
            Assert.Equal(HttpStatusCode.NotFound, context.Response.StatusCode);
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:19,代碼來源:ODataNullValueAttributeTests.cs

示例8: Match

        /// <summary>
        /// Determines whether this instance equals a specified route.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="route">The route to compare.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="values">A list of parameter values.</param>
        /// <param name="routeDirection">The route direction.</param>
        /// <returns>
        /// True if this instance equals a specified route; otherwise, false.
        /// </returns>
        public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (values == null)
            {
                throw Error.ArgumentNull("values");
            }

            if (routeDirection == HttpRouteDirection.UriResolution)
            {
                object odataPathRouteValue;
                if (values.TryGetValue(ODataRouteConstants.ODataPath, out odataPathRouteValue))
                {
                    string odataPath = odataPathRouteValue as string;
                    if (odataPath == null)
                    {
                        // No odataPath means the path is empty; this is necessary for service documents
                        odataPath = String.Empty;
                    }

                    ODataPath path = _pathHandler.Parse(odataPath);
                    if (path != null)
                    {
                        request.SetODataPath(path);
                        return true;
                    }
                }
                return false;
            }
            else
            {
                // This constraint only applies to URI resolution
                return true;
            }
        }
開發者ID:Swethach,項目名稱:aspnetwebstack,代碼行數:50,代碼來源:ODataPathRouteConstraint.cs

示例9: AddRequestInfo

 private void AddRequestInfo(HttpRequestMessage request)
 {
     request.SetODataPath(new DefaultODataPathHandler().Parse(_model, GetODataPath(
         request.RequestUri.AbsoluteUri)));
     request.SetEdmModel(_model);
     request.SetFakeODataRouteName();
 }
開發者ID:sujiantao,項目名稱:aspnetwebstack,代碼行數:7,代碼來源:InheritanceTests.cs

示例10: Property_LocationHeader_IsEvaluatedOnlyOnce

        public void Property_LocationHeader_IsEvaluatedOnlyOnce()
        {
            // Arrange
            Uri editLink = new Uri("http://edit-link");
            Mock<EntitySetLinkBuilderAnnotation> linkBuilder = new Mock<EntitySetLinkBuilderAnnotation>();
            linkBuilder.Setup(b => b.BuildEditLink(It.IsAny<EntityInstanceContext>(), ODataMetadataLevel.Default, null))
                .Returns(editLink);

            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            model.Model.SetEntitySetLinkBuilder(model.Customers, linkBuilder.Object);
            ODataPath path = new ODataPath(new EntitySetPathSegment(model.Customers));
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(model.Model);
            request.SetODataPath(path);
            TestController controller = new TestController { Request = request, Configuration = new HttpConfiguration() };
            CreatedODataResult<TestEntity> createdODataResult = new CreatedODataResult<TestEntity>(_entity, controller);

            // Act
            Uri locationHeader = createdODataResult.LocationHeader;

            // Assert
            linkBuilder.Verify(
                (b) => b.BuildEditLink(It.IsAny<EntityInstanceContext>(), ODataMetadataLevel.Default, null),
                Times.Once());
        }
開發者ID:RhysC,項目名稱:aspnetwebstack,代碼行數:26,代碼來源:CreatedODataResultTest.cs

示例11: GetODataPayloadSerializer_ReturnsRawValueSerializer_ForValueRequests

        public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForValueRequests(Type type, EdmPrimitiveTypeKind edmPrimitiveTypeKind)
        {
            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetODataPath(new ODataPath(new ValuePathSegment()));

            var serializer = serializerProvider.GetODataPayloadSerializer(_edmModel, type, request);

            Assert.NotNull(serializer);
            Assert.Equal(ODataPayloadKind.Value, serializer.ODataPayloadKind);
        }
開發者ID:quentez,項目名稱:aspnetwebstack,代碼行數:11,代碼來源:DefaultODataSerializerProviderTests.cs

示例12: GenerateLocationHeader_UsesEntitySetLinkBuilder_ToGenerateLocationHeader

        public void GenerateLocationHeader_UsesEntitySetLinkBuilder_ToGenerateLocationHeader()
        {
            // Arrange
            string idLink = "http://id-link";
            Uri editLink = new Uri(idLink);
            Mock<EntitySetLinkBuilderAnnotation> linkBuilder = new Mock<EntitySetLinkBuilderAnnotation>();
            linkBuilder.Setup(b => b.BuildIdLink(It.IsAny<EntityInstanceContext>(), ODataMetadataLevel.Default))
                .Returns(idLink);
            linkBuilder.Setup(b => b.BuildEditLink(It.IsAny<EntityInstanceContext>(), ODataMetadataLevel.Default, idLink))
                .Returns(editLink);

            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            model.Model.SetEntitySetLinkBuilder(model.Customers, linkBuilder.Object);
            ODataPath path = new ODataPath(new EntitySetPathSegment(model.Customers));
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(model.Model);
            request.SetODataPath(path);
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act
            var locationHeader = createdODataResult.GenerateLocationHeader();

            // Assert
            Assert.Same(editLink, locationHeader);
        }
開發者ID:RhysC,項目名稱:aspnetwebstack,代碼行數:26,代碼來源:CreatedODataResultTest.cs

示例13: GenerateLocationHeader_ThrowsEditLinkNullForLocationHeader_IfEntitySetLinkBuilderReturnsNull

        public void GenerateLocationHeader_ThrowsEditLinkNullForLocationHeader_IfEntitySetLinkBuilderReturnsNull()
        {
            // Arrange
            Mock<EntitySetLinkBuilderAnnotation> linkBuilder = new Mock<EntitySetLinkBuilderAnnotation>();
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            model.Model.SetAnnotationValue(model.Customer, new ClrTypeAnnotation(typeof(TestEntity)));
            model.Model.SetEntitySetLinkBuilder(model.Customers, linkBuilder.Object);
            ODataPath path = new ODataPath(new EntitySetPathSegment(model.Customers));
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(model.Model);
            request.SetODataPath(path);
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act
            Assert.Throws<InvalidOperationException>(() => createdODataResult.GenerateLocationHeader(),
                "The edit link builder for the entity set 'Customers' returned null. An edit link is required for the location header.");
        }
開發者ID:RhysC,項目名稱:aspnetwebstack,代碼行數:17,代碼來源:CreatedODataResultTest.cs

示例14: GenerateLocationHeader_ThrowsEntityTypeNotInModel_IfContentTypeIsNotThereInModel

        public void GenerateLocationHeader_ThrowsEntityTypeNotInModel_IfContentTypeIsNotThereInModel()
        {
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath path = new ODataPath(new EntitySetPathSegment(model.Customers));
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(model.Model);
            request.SetODataPath(path);
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => createdODataResult.GenerateLocationHeader(),
                "Cannot find the entity type 'System.Web.Http.OData.Results.CreatedODataResultTest+TestEntity' in the model.");
        }
開發者ID:RhysC,項目名稱:aspnetwebstack,代碼行數:13,代碼來源:CreatedODataResultTest.cs

示例15: GenerateLocationHeader_ThrowsTypeMustBeEntity_IfMappingTypeIsNotEntity

        public void GenerateLocationHeader_ThrowsTypeMustBeEntity_IfMappingTypeIsNotEntity()
        {
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataPath path = new ODataPath(new EntitySetPathSegment(model.Customers));
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(model.Model);
            request.SetODataPath(path);
            model.Model.SetAnnotationValue(model.Address, new ClrTypeAnnotation(typeof(TestEntity)));
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => createdODataResult.GenerateLocationHeader(),
                "NS.Address is not an entity type. Only entity types are supported.");
        }
開發者ID:RhysC,項目名稱:aspnetwebstack,代碼行數:14,代碼來源:CreatedODataResultTest.cs


注:本文中的System.Net.Http.HttpRequestMessage.SetODataPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。