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


C# HttpRequestMessage.SetAcceptHeader方法代码示例

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


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

示例1: ODataTypeAnnotationShouldAppearForComplexTypesLikeCollectionAndUserDefinedTypes

        public void ODataTypeAnnotationShouldAppearForComplexTypesLikeCollectionAndUserDefinedTypes(string acceptHeader)
        {
            //Arrange
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Complex/EntityWithComplexProperties/";
            JObject complexProperty;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);
            
            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JsonAssert.ContainsProperty("value", result);
            JArray returnedEntities = (JArray)result["value"];
            for (int i = 0; i < returnedEntities.Count; i++)
            {
                JObject returnedEntity = (JObject)returnedEntities[i];
                if (!acceptHeader.Contains("fullmetadata"))
                {
                    JsonAssert.DoesNotContainProperty("odata.*", returnedEntity);
                }
                else
                {
                    JsonAssert.Equal("Collection(Edm.String)", "[email protected]", returnedEntity);
                    JsonAssert.ContainsProperty("ComplexProperty", returnedEntity);
                    complexProperty = (JObject)returnedEntity["ComplexProperty"];
                    JsonAssert.Equal("WebStack.QA.Test.OData.Formatter.JsonLight.Metadata.Model.ComplexType", "odata.type", complexProperty);
                    JsonAssert.Equal("Collection(Edm.String)", "[email protected]", complexProperty); 
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:32,代码来源:ComplexTypeTests.cs

示例2: ODataCountAndNextLinkAnnotationsAppearsOnAllMetadataLevelsWhenSpecified

        public void ODataCountAndNextLinkAnnotationsAppearsOnAllMetadataLevelsWhenSpecified(string acceptHeader)
        {
            //Arrange
            StubEntity[] entities = MetadataTestHelpers.CreateInstances<StubEntity[]>();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, BaseAddress.ToLowerInvariant() + "/StubEntity/Default.Paged");
            message.SetAcceptHeader(acceptHeader);
            string expectedNextLink = new Uri("http://differentServer:5000/StubEntity/Default.Paged?$skip=" + entities.Length).ToString();

            //Act
            HttpResponseMessage response = Client.SendAsync(message).Result;
            JObject result = response.Content.ReadAsAsync<JObject>().Result;

            //Assert
            JsonAssert.PropertyEquals(entities.Length, "@odata.count", result);
            JsonAssert.PropertyEquals(expectedNextLink, "@odata.nextLink", result);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:16,代码来源:FeedMetadataTests.cs

示例3: NavigationLinksAppearOnlyInFullMetadata

        public void NavigationLinksAppearOnlyInFullMetadata(string acceptHeader)
        {
            //Arrange
            OneToOneParent[] entities = MetadataTestHelpers.CreateInstances<OneToOneParent[]>();
            var entity = entities.First();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Relationships/OneToOneParent(" + entity.Id + ")";
            string expectedNavigationLinkUrl = BaseAddress.ToLowerInvariant() + "/Relationships/OneToOneParent(" + entity.Id + ")/Child";
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            if (acceptHeader.Contains("fullmetadata"))
            {
                JsonAssert.Equal(expectedNavigationLinkUrl, "[email protected]", result);
            }
            else
            {
                JsonAssert.DoesNotContainProperty("[email protected]", result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:24,代码来源:EntryMetadataTests.cs

示例4: BaseEntity

        public void ODataTypeAnnotationAppearsForAllEntitiesInFullMetadataAndForDerivedEntityTypesInFullAndMinimalMetadata(string acceptHeader)
        {
            //Arrange
            BaseEntity[] baseEntities = new BaseEntity[] { new BaseEntity(1), new BaseEntity(2), new BaseEntity(3), new BaseEntity(4), new BaseEntity(5), new BaseEntity(6), new BaseEntity(7) }; //InstanceCreator.CreateInstanceOf<BaseEntity[]>(new Random(RandomSeedGenerator.GetRandomSeed()));
            DerivedEntity[] derivedEntities = new DerivedEntity[] { new DerivedEntity(8), new DerivedEntity(9), new DerivedEntity(10), new DerivedEntity(11), new DerivedEntity(12), new DerivedEntity(13), new DerivedEntity(14) };  //InstanceCreator.CreateInstanceOf<DerivedEntity[]>(new Random(RandomSeedGenerator.GetRandomSeed()));
            BaseEntity[] entities = baseEntities.Union(derivedEntities, new BaseEntity.IdEqualityComparer()).ToArray();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Inheritance/BaseEntity/";
            string expectedTypeName;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JArray returnedEntities = (JArray)result["value"];
            for (int i = 0; i < returnedEntities.Count; i++)
            {
                JObject returnedEntity = (JObject)returnedEntities[i];
                BaseEntity originalEntity = entities.FirstOrDefault(x => x.Id == (int)returnedEntity["Id"]);
                Assert.NotNull(originalEntity);
                if (acceptHeader.Contains("nometadata"))
                {
                    JsonAssert.DoesNotContainProperty("odata.type", returnedEntity);
                }
                else if (acceptHeader.Contains("fullmetadata"))
                {
                    expectedTypeName = originalEntity.GetType().FullName;
                    JsonAssert.Equal(expectedTypeName, "odata.type", returnedEntity);
                }
                else
                {
                    if (originalEntity is DerivedEntity)
                    {
                        expectedTypeName = originalEntity.GetType().FullName;
                        JsonAssert.Equal(expectedTypeName, "odata.type", returnedEntity);
                    }
                    else
                    {
                        JsonAssert.DoesNotContainProperty("odata.type", returnedEntity);
                    }
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:45,代码来源:EntryMetadataTests.cs

示例5: TransientActionsGetAdvertisedForDerivedTypesWhenTheyAreAvailable

        public void TransientActionsGetAdvertisedForDerivedTypesWhenTheyAreAvailable(string acceptHeader)
        {
            //Arrange
            JObject container;
            JObject derivedContainer;
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(8)/";
            string expectedContainerNamePrefix = acceptHeader.Contains("fullmetadata") ? "#Container." : "#";
            string expectedTransientActionName = "TransientActionBaseType";
            string expectedTransientActionContainer = expectedContainerNamePrefix + expectedTransientActionName;
            string expectedTargetUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(8)/TransientActionBaseType";

            string expectedDerivedTypeTransientActionName = "TransientActionDerivedType";
            string expectedDerivedTypeTransientActionContainer = expectedContainerNamePrefix + expectedDerivedTypeTransientActionName;
            string expectedDerivedTypeTargetUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(8)/WebStack.QA.Test.OData.Formatter.JsonLight.Metadata.Model.DerivedEntity/TransientActionDerivedType";
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JsonAssert.ContainsProperty(expectedTransientActionContainer, result);
            JsonAssert.ContainsProperty(expectedDerivedTypeTransientActionContainer, result);

            container = (JObject)result[expectedTransientActionContainer];
            derivedContainer = (JObject)result[expectedDerivedTypeTransientActionContainer];
            if (acceptHeader.Contains("fullmetadata"))
            {
                JsonAssert.Equal(expectedTargetUrl, "target", container);
                JsonAssert.Equal(expectedTransientActionName, "title", container);

                JsonAssert.Equal(expectedDerivedTypeTargetUrl, "target", derivedContainer);
                JsonAssert.Equal(expectedDerivedTypeTransientActionName, "title", derivedContainer);
            }
            else
            {
                JsonAssert.DoesNotContainProperty("target", container);
                JsonAssert.DoesNotContainProperty("title", container);

                JsonAssert.DoesNotContainProperty("target", container);
                JsonAssert.DoesNotContainProperty("title", container);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:44,代码来源:ActionMetadataTests.cs

示例6: TransientActionsDontGetAdvertisedForDerivedTypesWhenTheyArentAvailable

        public void TransientActionsDontGetAdvertisedForDerivedTypesWhenTheyArentAvailable(string acceptHeader)
        {
            //Arrange
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(9)/";
            string expectedContainerNamePrefix = acceptHeader.Contains("fullmetadata") ? "#Container." : "#";
            string expectedTransientActionName = "TransientActionBaseType";
            string expectedTransientActionContainer = expectedContainerNamePrefix + expectedTransientActionName;
            string expectedDerivedTypeTransientActionName = "TransientActionDerivedType";
            string expectedDerivedTypeTransientActionContainer = expectedContainerNamePrefix + expectedDerivedTypeTransientActionName;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JsonAssert.DoesNotContainProperty(expectedTransientActionContainer, result);
            JsonAssert.DoesNotContainProperty(expectedDerivedTypeTransientActionContainer, result);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:20,代码来源:ActionMetadataTests.cs

示例7: AlwaysAvailableActionsGetAdvertisedOnFullMetadataOnly

        public void AlwaysAvailableActionsGetAdvertisedOnFullMetadataOnly(string acceptHeader)
        {
            //Arrange
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(1)/";
            string expectedTargetUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(1)/AlwaysAvailableActionBaseType";
            string expectedContainerNamePrefix = acceptHeader.Contains("fullmetadata") ? "#Container." : "#";
            string expectedAlwaysAvailableActionName = "AlwaysAvailableActionBaseType";
            string expectedAlwaysAvailableActionContainer = expectedContainerNamePrefix + expectedAlwaysAvailableActionName;
            JObject container;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            if (acceptHeader.Contains("fullmetadata"))
            {
                JsonAssert.ContainsProperty(expectedAlwaysAvailableActionContainer, result);
                container = (JObject)result[expectedAlwaysAvailableActionContainer];
                JsonAssert.Equal(expectedTargetUrl, "target", container);
                JsonAssert.Equal(expectedAlwaysAvailableActionName, "title", container);
            }
            else
            {
                JsonAssert.DoesNotContainProperty(expectedAlwaysAvailableActionContainer, result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:29,代码来源:ActionMetadataTests.cs

示例8: MetadataIsCorrectForAnEntryWithJustPrimitiveTypeProperties

        public void MetadataIsCorrectForAnEntryWithJustPrimitiveTypeProperties(string acceptHeader)
        {
            //Arrange
            EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances<EntityWithSimpleProperties[]>();
            EntityWithSimpleProperties entity = entities.First();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties(" + entity.Id + ")";
            string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#EntityWithSimpleProperties/@Element";
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            message.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(message).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JsonAssert.DoesNotContainProperty("[email protected]", result);
            JsonAssert.DoesNotContainProperty("[email protected]", result);
            JsonAssert.DoesNotContainProperty("[email protected]", result);
            if (!(((string)result["DoubleProperty"]).Equals("Infinity", StringComparison.InvariantCultureIgnoreCase) ||
                 ((string)result["DoubleProperty"]).Equals("-Infinity", StringComparison.InvariantCultureIgnoreCase) ||
               ((string)result["DoubleProperty"]).Equals("NaN", StringComparison.InvariantCultureIgnoreCase)))
            {
                JsonAssert.DoesNotContainProperty("[email protected]", result);
            }
            JsonAssert.DoesNotContainProperty("[email protected]", result);
            if (acceptHeader.Contains("nometadata"))
            {
                JsonAssert.DoesNotContainProperty("odata.metadata", result);
            }
            else
            {
                JsonAssert.Equal(expectedMetadataUrl, "odata.metadata", result);
            }
            if (acceptHeader.Contains("fullmetadata"))
            {
                JsonAssert.Equal(requestUrl, "odata.id", result);
                JsonAssert.Equal("Edm.Binary", "[email protected]", result);
                JsonAssert.Equal("Edm.DateTime", "[email protected]", result);
                JsonAssert.Equal("Edm.Decimal", "[email protected]ta.type", result);
                JsonAssert.Equal("Edm.Single", "[email protected]", result);
                JsonAssert.Equal("Edm.Guid", "[email protected]", result);
                JsonAssert.Equal("Edm.Int16", "[email protected]", result);
                JsonAssert.Equal("Edm.Int64", "[email protected]", result);
                JsonAssert.Equal("Edm.SByte", "[email protected]", result);
                JsonAssert.Equal("Edm.DateTimeOffset", "[email protected]", result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:47,代码来源:PrimitiveTypesMetadataTests.cs

示例9: CanReturnTheWholeResultSetUsingNextLink

        public void CanReturnTheWholeResultSetUsingNextLink(string acceptHeader)
        {
            //Arrange
            StubEntity[] entities = MetadataTestHelpers.CreateInstances<StubEntity[]>();
            string nextUrlToQuery = BaseAddress.ToLowerInvariant() + "/StubEntity/";
            JToken token = null;
            JArray returnedEntities = new JArray();
            JObject result = null;

            //Act
            do
            {
                HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, nextUrlToQuery);
                message.SetAcceptHeader(acceptHeader);
                HttpResponseMessage response = Client.SendAsync(message).Result;
                result = response.Content.ReadAsAsync<JObject>().Result;
                JArray currentResults = (JArray)result["value"];
                for (int i = 0; i < currentResults.Count; i++)
                {
                    returnedEntities.Add(currentResults[i]);
                }
                if (result.TryGetValue("@odata.nextLink", out token))
                {
                    nextUrlToQuery = (string)token;
                }
                else
                {
                    nextUrlToQuery = null;
                }
            }
            while (nextUrlToQuery != null);

            //Assert
            Assert.Equal(entities.Length, returnedEntities.Count);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:35,代码来源:FeedMetadataTests.cs

示例10: MetadataIsCorrectForFeedsOfEntriesWithJustPrimitiveTypeProperties

        public void MetadataIsCorrectForFeedsOfEntriesWithJustPrimitiveTypeProperties(string acceptHeader)
        {
            //Arrange
            EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances<EntityWithSimpleProperties[]>();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties/";
            string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#EntityWithSimpleProperties";
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            message.SetAcceptHeader(acceptHeader);

            //Act
            var response = Client.SendAsync(message).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            JsonAssert.ArrayLength(entities.Length, "value", result);
            if (acceptHeader.Contains("nometadata"))
            {
                JsonAssert.DoesNotContainProperty("odata.metadata", result);
            }
            else
            {
                JsonAssert.Equal(expectedMetadataUrl, "odata.metadata", result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:24,代码来源:PrimitiveTypesMetadataTests.cs

示例11: AlwaysAvailableActionsGetAdvertisedForDerivedTypesOnFullMetadataOnly

        public void AlwaysAvailableActionsGetAdvertisedForDerivedTypesOnFullMetadataOnly(string acceptHeader)
        {
            //Arrange
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(9)/";

            string expectedTargetUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(9)/Default.AlwaysAvailableActionBaseType";
            string expectedAlwaysAvailableActionName = "AlwaysAvailableActionBaseType";
            string expectedAlwaysAvailableActionContainer = "#Default." + expectedAlwaysAvailableActionName;

            string expectedDerivedTypeTargetUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(9)/WebStack.QA.Test.OData.Formatter.JsonLight.Metadata.Model.DerivedEntity/Default.AlwaysAvailableActionDerivedType";
            string expectedAlwaysAvailableDerivedTypeActionName = "AlwaysAvailableActionDerivedType";
            string expectedAlwaysAvailableDerivedTypeActionContainer = "#Default." + expectedAlwaysAvailableDerivedTypeActionName;
            string expectedContextUrl = BaseAddress.ToLowerInvariant() + "/Actions/$metadata#BaseEntity/$entity";
            JObject container;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsAsync<JObject>().Result;

            //Assert
            if (acceptHeader.Contains("odata.metadata=full"))
            {
                // full metadata
                JsonAssert.ContainsProperty(expectedAlwaysAvailableActionContainer, result);
                container = (JObject)result[expectedAlwaysAvailableActionContainer];
                JsonAssert.PropertyEquals(expectedTargetUrl, "target", container);
                JsonAssert.PropertyEquals(expectedAlwaysAvailableActionName, "title", container);

                JsonAssert.ContainsProperty(expectedAlwaysAvailableDerivedTypeActionContainer, result);
                container = (JObject)result[expectedAlwaysAvailableDerivedTypeActionContainer];
                JsonAssert.PropertyEquals(expectedDerivedTypeTargetUrl, "target", container);
                JsonAssert.PropertyEquals(expectedAlwaysAvailableDerivedTypeActionName, "title", container);

                JsonAssert.PropertyEquals(expectedContextUrl, "@odata.context", result);
                JsonAssert.PropertyEquals("#WebStack.QA.Test.OData.Formatter.JsonLight.Metadata.Model.DerivedEntity", "@odata.type", result);
            }
            else if (acceptHeader.Contains("odata.metadata=none"))
            {
                // none metadata
                JsonAssert.DoesNotContainProperty("@odata.context", result);
                JsonAssert.DoesNotContainProperty(expectedAlwaysAvailableActionContainer, result);
                JsonAssert.DoesNotContainProperty(expectedAlwaysAvailableDerivedTypeActionContainer, result);
            }
            else
            {
                // minimal metadata, "application/json" equal to "application/json;odata.metadata=minimal"
                JsonAssert.PropertyEquals(expectedContextUrl, "@odata.context", result);
                JsonAssert.PropertyEquals("#WebStack.QA.Test.OData.Formatter.JsonLight.Metadata.Model.DerivedEntity", "@odata.type", result);

                JsonAssert.DoesNotContainProperty(expectedAlwaysAvailableActionContainer, result);
                JsonAssert.DoesNotContainProperty(expectedAlwaysAvailableDerivedTypeActionContainer, result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:55,代码来源:ActionMetadataTests.cs

示例12: TransientActionsDontGetAdvertisedWhenTheyArentAvailable

        public void TransientActionsDontGetAdvertisedWhenTheyArentAvailable(string acceptHeader)
        {
            //Arrange
            string requestUrl = BaseAddress.ToLowerInvariant() + "/Actions/BaseEntity(1)/";
            string expectedTransientActionName = "TransientActionBaseType";
            string expectedTransientActionContainer = "#Default." + expectedTransientActionName;
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.SetAcceptHeader(acceptHeader);

            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsAsync<JObject>().Result;

            //Assert
            if (acceptHeader.Contains("odata.metadata=full"))
            {
                JsonAssert.ContainsProperty(expectedTransientActionContainer, result);
            }
            else
            {
                JsonAssert.DoesNotContainProperty(expectedTransientActionContainer, result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:23,代码来源:ActionMetadataTests.cs

示例13: MetadataAnnotationAppearsOnlyForFullAndMinimalMetadata

        public void MetadataAnnotationAppearsOnlyForFullAndMinimalMetadata(string acceptHeader)
        {
            //Arrange
            StubEntity[] entities = MetadataTestHelpers.CreateInstances<StubEntity[]>();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, BaseAddress.ToLowerInvariant() + "/StubEntity/");
            message.SetAcceptHeader(acceptHeader);
            string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#StubEntity";

            //Act
            HttpResponseMessage response = Client.SendAsync(message).Result;
            JObject result = response.Content.ReadAsAsync<JObject>().Result;

            //Assert
            if (acceptHeader.Contains("odata.metadata=none"))
            {
                JsonAssert.DoesNotContainProperty("@odata.context", result);
            }
            else
            {
                JsonAssert.PropertyEquals(expectedMetadataUrl, "@odata.context", result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:22,代码来源:FeedMetadataTests.cs

示例14: CustomReadLinksAppearInFullAndMinimalMetadata

        public void CustomReadLinksAppearInFullAndMinimalMetadata(string acceptHeader)
        {
            //Arrange
            OneToOneParent[] entities = MetadataTestHelpers.CreateInstances<OneToOneParent[]>();
            var entity = entities.First();
            string requestUrl = BaseAddress.ToLowerInvariant() + "/CustomReadLinkConventions/OneToOneParent(" + entity.Id + ")";
            string expectedReadLinkUrl = "http://localhost:5000/CustomReadLink";
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, BaseAddress + "/CustomReadLinkConventions/OneToOneParent(" + entity.Id + ")");
            request.SetAcceptHeader(acceptHeader);
            
            //Act
            HttpResponseMessage response = Client.SendAsync(request).Result;
            JObject result = response.Content.ReadAsJObject();

            //Assert
            if (!acceptHeader.Contains("nometadata"))
            {
                JsonAssert.Equal(expectedReadLinkUrl, "odata.readLink", result);
            }
            else
            {
                JsonAssert.DoesNotContainProperty("odata.readLink", result);
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:24,代码来源:EntryMetadataTests.cs

示例15: MetadataIsCorrectForThePropertiesOfAnEntryWithJustPrimitiveTypeProperties

        public void MetadataIsCorrectForThePropertiesOfAnEntryWithJustPrimitiveTypeProperties(string acceptHeader, string propertyName, string edmType)
        {
            //Arrange
            EntityWithSimpleProperties[] entities = MetadataTestHelpers.CreateInstances<EntityWithSimpleProperties[]>();
            EntityWithSimpleProperties entity = entities.First();
            string entryUrl = BaseAddress.ToLowerInvariant() + "/EntityWithSimpleProperties(" + entity.Id + ")/" + propertyName;
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, entryUrl);
            message.SetAcceptHeader(acceptHeader);
            string expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#" + edmType;
            string[] inferableTypes = new string[] { "Edm.Int32", "Edm.Double", "Edm.String", "Edm.Boolean" };
            bool isODataNull = false;

            //Act
            var response = Client.SendAsync(message).Result;
            JObject result = response.Content.ReadAsJObject();
            isODataNull = result.Property("odata.null") != null;

            //Assert
            if (isODataNull)
            {
                expectedMetadataUrl = BaseAddress.ToLowerInvariant() + "/$metadata#Edm.Null";
            }
            if (acceptHeader.Contains("nometadata"))
            {
                if (!isODataNull)
                {
                    JsonAssert.DoesNotContainProperty("odata.*", result);
                }
                else
                {
                    JsonAssert.Equals(true, (bool)result.Property("odata.null"));
                }
            }
            else
            {
                JsonAssert.Equal(expectedMetadataUrl, "odata.metadata", result);
                if (!acceptHeader.Contains("fullmetadata") || (inferableTypes.Contains(edmType) && !IsSpecialValue(result)))
                {
                    JsonAssert.DoesNotContainProperty("odata.type", result);
                }
                else
                {
                    JsonAssert.Equal(edmType, "odata.type", result);
                }
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:46,代码来源:PrimitiveTypesMetadataTests.cs


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