當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。