当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestMessage.SetEdmModel方法代码示例

本文整理汇总了C#中System.Net.Http.HttpRequestMessage.SetEdmModel方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.SetEdmModel方法的具体用法?C# HttpRequestMessage.SetEdmModel怎么用?C# HttpRequestMessage.SetEdmModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.SetEdmModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSampleRequest

 private static HttpRequestMessage GetSampleRequest()
 {
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/property");
     request.SetEdmModel(GetSampleModel());
     HttpConfiguration configuration = new HttpConfiguration();
     configuration.Routes.MapFakeODataRoute();
     request.SetConfiguration(configuration);
     request.SetFakeODataRouteName();
     return request;
 }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:10,代码来源:ComplexTypeTest.cs

示例2: GetODataPathHandlerReturnsDefaultPathHandlerByDefault

        public void GetODataPathHandlerReturnsDefaultPathHandlerByDefault()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            IEdmModel model = new EdmModel();
            request.SetEdmModel(model);

            var pathHandler = request.GetODataPathHandler();

            Assert.NotNull(pathHandler);
            Assert.IsType<DefaultODataPathHandler>(pathHandler);
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:11,代码来源:ODataHttpRequestMessageExtensionsTest.cs

示例3: 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

示例4: SetEdmModelThenGetReturnsWhatYouSet

        public void SetEdmModelThenGetReturnsWhatYouSet()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage();
            IEdmModel model = new EdmModel();

            // Act
            request.SetEdmModel(model);
            IEdmModel newModel = request.GetEdmModel();

            // Assert
            Assert.Same(model, newModel);
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:13,代码来源:ODataHttpRequestMessageExtensionsTest.cs

示例5: GetODataPathHandlerReturnsDefaultPathHandlerByDefault

        public void GetODataPathHandlerReturnsDefaultPathHandlerByDefault()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Customer>(typeof(Customer).Name);
            IEdmModel model = modelBuilder.GetEdmModel();
            request.SetEdmModel(model);

            var pathHandler = request.GetODataPathHandler();

            Assert.NotNull(pathHandler);
            Assert.IsType<DefaultODataPathHandler>(pathHandler);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:13,代码来源:ODataHttpRequestMessageExtensionsTest.cs

示例6: 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

示例7: 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

示例8: 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

示例9: SetEdmModelThenGetReturnsWhatYouSet

        public void SetEdmModelThenGetReturnsWhatYouSet()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage();
            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<Customer>(typeof(Customer).Name);
            IEdmModel model = modelBuilder.GetEdmModel();

            // Act
            request.SetEdmModel(model);
            IEdmModel newModel = request.GetEdmModel();

            // Assert
            Assert.Same(model, newModel);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataHttpRequestMessageExtensionsTest.cs

示例10: 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

示例11: 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

示例12: 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

示例13: GenerateLocationHeader_ThrowsEntitySetMissingDuringSerialization_IfODataPathEntitySetIsNull

        public void GenerateLocationHeader_ThrowsEntitySetMissingDuringSerialization_IfODataPathEntitySetIsNull()
        {
            ODataPath path = new ODataPath();
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(EdmCoreModel.Instance);
            request.SetODataPath(path);
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => createdODataResult.GenerateLocationHeader(),
                "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.");
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:12,代码来源:CreatedODataResultTest.cs

示例14: GenerateLocationHeader_ThrowsODataPathMissing_IfRequestDoesNotHaveODataPath

        public void GenerateLocationHeader_ThrowsODataPathMissing_IfRequestDoesNotHaveODataPath()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            request.SetEdmModel(EdmCoreModel.Instance);
            CreatedODataResult<TestEntity> createdODataResult = GetCreatedODataResult(request);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => createdODataResult.GenerateLocationHeader(),
                "The operation cannot be completed because no ODataPath is available for the request.");
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:10,代码来源:CreatedODataResultTest.cs

示例15: PrimitiveTypesSerializeAsOData

        public void PrimitiveTypesSerializeAsOData(Type valueType, object value, MediaTypeHeaderValue mediaType,
            string resourceName)
        {
            string expectedEntity = Resources.GetString(resourceName);
            Assert.NotNull(expectedEntity);

            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<WorkItem>("WorkItems");
            IEdmModel model = modelBuilder.GetEdmModel();

            string actualEntity;

            using (HttpConfiguration configuration = CreateConfiguration())
            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
                "http://localhost/WorkItems(10)/ID"))
            {
                request.SetConfiguration(configuration);
                IEdmProperty property =
                    model.EntityContainers().Single().EntitySets().Single().ElementType.Properties().First();
                request.SetEdmModel(model);
                request.SetODataPath(new ODataPath(new PropertyAccessPathSegment(property)));
                request.SetFakeODataRouteName();

                ODataMediaTypeFormatter formatter = CreateFormatter(request);
                formatter.SupportedMediaTypes.Add(mediaType);

                Type type = (value != null) ? value.GetType() : typeof(Nullable<int>);

                using (ObjectContent content = new ObjectContent(type, value, formatter))
                {
                    actualEntity = content.ReadAsStringAsync().Result;
                }
            }

            bool isJson = resourceName.EndsWith(".json");

            if (isJson)
            {
                JsonAssert.Equal(expectedEntity, actualEntity);
            }
            else
            {
                Assert.Xml.Equal(expectedEntity, actualEntity);
            }
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:45,代码来源:PrimitiveTypesTest.cs


注:本文中的System.Net.Http.HttpRequestMessage.SetEdmModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。