• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Core.ODataCollectionValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.OData.Core.ODataCollectionValue的典型用法代码示例。如果您正苦于以下问题:C# ODataCollectionValue类的具体用法?C# ODataCollectionValue怎么用?C# ODataCollectionValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ODataCollectionValue类属于Microsoft.OData.Core命名空间,在下文中一共展示了ODataCollectionValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetSchema

 public static ArraySchema GetSchema(ODataCollectionValue colValue)
 {
     var enumerator = colValue.Items.GetEnumerator();
     enumerator.MoveNext();
     var item = enumerator.Current;
     return Schema.CreateArray(GetSchema(item));
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:7,代码来源:ODataAvroSchemaGen.cs


示例2: WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue

        public void WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue()
        {
            // Arrange
            MemoryStream stream = new MemoryStream();
            IODataResponseMessage message = new ODataMessageWrapper(stream);
            ODataMessageWriterSettings settings = new ODataMessageWriterSettings();
            settings.SetContentType(ODataFormat.Atom);
            ODataMessageWriter messageWriter = new ODataMessageWriter(message, settings);
            Mock<ODataCollectionSerializer> serializer = new Mock<ODataCollectionSerializer>(new DefaultODataSerializerProvider());
            ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "CollectionName", Model = _model };
            IEnumerable enumerable = new object[0];
            ODataCollectionValue collectionValue = new ODataCollectionValue { TypeName = "NS.Name", Items = new[] { 0, 1, 2 } };

            serializer.CallBase = true;
            serializer
                .Setup(s => s.CreateODataCollectionValue(enumerable, It.Is<IEdmTypeReference>(e => e.Definition == _edmIntType.Definition), writeContext))
                .Returns(collectionValue).Verifiable();

            // Act
            serializer.Object.WriteObject(enumerable, typeof(int[]), messageWriter, writeContext);

            // Assert
            serializer.Verify();
            stream.Seek(0, SeekOrigin.Begin);
            XElement element = XElement.Load(stream);
            Assert.Equal("value", element.Name.LocalName);
            Assert.Equal(3, element.Descendants().Count());
            Assert.Equal(new[] { "0", "1", "2" }, element.Descendants().Select(e => e.Value));
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:29,代码来源:ODataCollectionSerializerTests.cs


示例3: WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue

        public void WriteObject_WritesValueReturnedFrom_CreateODataCollectionValue()
        {
            // Arrange
            MemoryStream stream = new MemoryStream();
            IODataResponseMessage message = new ODataMessageWrapper(stream);
            ODataMessageWriterSettings settings = new ODataMessageWriterSettings()
            {
                ODataUri = new ODataUri { ServiceRoot = new Uri("http://any/") }
            };

            settings.SetContentType(ODataFormat.Json);

            ODataMessageWriter messageWriter = new ODataMessageWriter(message, settings);
            Mock<ODataCollectionSerializer> serializer = new Mock<ODataCollectionSerializer>(new DefaultODataSerializerProvider());
            ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "CollectionName", Model = _model };
            IEnumerable enumerable = new object[0];
            ODataCollectionValue collectionValue = new ODataCollectionValue { TypeName = "NS.Name", Items = new[] { 0, 1, 2 } };

            serializer.CallBase = true;
            serializer
                .Setup(s => s.CreateODataCollectionValue(enumerable, It.Is<IEdmTypeReference>(e => e.Definition == _edmIntType.Definition), writeContext))
                .Returns(collectionValue).Verifiable();

            // Act
            serializer.Object.WriteObject(enumerable, typeof(int[]), messageWriter, writeContext);

            // Assert
            serializer.Verify();
            stream.Seek(0, SeekOrigin.Begin);
            string result = new StreamReader(stream).ReadToEnd();
            Assert.Equal("{\"@odata.context\":\"http://any/$metadata#Collection(Edm.Int32)\",\"value\":[0,1,2]}", result);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:32,代码来源:ODataCollectionSerializerTests.cs


示例4: SetlineItems

 public void SetlineItems(ODataCollectionValue values)
 {
     this.lineItems = new Collection<string>();
     foreach (var item in values.Items)
     {
         this.lineItems.Add(item.ToString());
     }
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:8,代码来源:CamelCaseModels.cs


示例5: WritingCollectionValueShouldFailWhenNoTypeSpecified

        public void WritingCollectionValueShouldFailWhenNoTypeSpecified()
        {
            var serializer = CreateODataJsonLightValueSerializer(false);

            var collectionValue = new ODataCollectionValue() { Items = new List<string>() };

            Action test = () => serializer.WriteCollectionValue(collectionValue, null, false, false, false);

            test.ShouldThrow<ODataException>().WithMessage(Strings.ODataJsonLightPropertyAndValueSerializer_NoExpectedTypeOrTypeNameSpecifiedForCollectionValueInRequest);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:10,代码来源:ODataJsonLightValueSerializerTests.cs


示例6: WritingCollectionValueDifferingFromExpectedTypeShouldFail_WithoutEdmPrefix

        public void WritingCollectionValueDifferingFromExpectedTypeShouldFail_WithoutEdmPrefix()
        {
            var serializer = CreateODataJsonLightValueSerializer(true);

            var collectionValue = new ODataCollectionValue() { Items = new List<string>(), TypeName = "Collection(Int32)" };

            var stringCollectionTypeRef = EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true));
            Action test = () => serializer.WriteCollectionValue(collectionValue, stringCollectionTypeRef, false, false, false);

            test.ShouldThrow<ODataException>().WithMessage(Strings.ValidationUtils_IncompatibleType("Collection(Edm.Int32)", "Collection(Edm.String)"));
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:ODataJsonLightValueSerializerTests.cs


示例7: ComplexTypeCollectionRoundtripAtomTest

        public void ComplexTypeCollectionRoundtripAtomTest()
        {
            ODataComplexValue subject0 = new ODataComplexValue() { TypeName = "NS.Subject", Properties = new[] { new ODataProperty() { Name = "Name", Value = "English" }, new ODataProperty() { Name = "Score", Value = (Int16)98 } } };
            ODataComplexValue subject1 = new ODataComplexValue() { TypeName = "NS.Subject", Properties = new[] { new ODataProperty() { Name = "Name", Value = "Math" }, new ODataProperty() { Name = "Score", Value = (Int16)90 } } };
            ODataCollectionValue complexCollectionValue = new ODataCollectionValue { TypeName = "Collection(NS.Subject)", Items = new[] { subject0, subject1 } };
            ODataFeedAndEntrySerializationInfo info = new ODataFeedAndEntrySerializationInfo() {
                NavigationSourceEntityTypeName = subject0.TypeName,
                NavigationSourceName = "Subjects",
                ExpectedTypeName = subject0.TypeName
            };

            this.VerifyTypeCollectionRoundtrip(complexCollectionValue, "Subjects", info);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:13,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs


示例8: PropertyGettersAndSettersTest

        public void PropertyGettersAndSettersTest()
        {
            string name1 = "ODataPrimitiveProperty";
            object value1 = "Hello world";

            ODataProperty primitiveProperty = new ODataProperty()
            {
                Name = name1,
                Value = value1,
            };

            this.Assert.AreEqual(name1, primitiveProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value1, primitiveProperty.Value, "Expected reference equal values for property 'Value'.");

            string name2 = "ODataComplexProperty";
            ODataComplexValue value2 = new ODataComplexValue()
            {
                Properties = new[]
                {
                    new ODataProperty() { Name = "One", Value = 1 },
                    new ODataProperty() { Name = "Two", Value = 2 },
                }
            };

            ODataProperty complexProperty = new ODataProperty()
            {
                Name = name2,
                Value = value2,
            };

            this.Assert.AreEqual(name2, complexProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value2, complexProperty.Value, "Expected reference equal values for property 'Value'.");

            string name3 = "ODataCollectionProperty";
            ODataCollectionValue value3 = new ODataCollectionValue()
            {
                Items = new[] { 1, 2, 3 }
            };

            ODataProperty multiValueProperty = new ODataProperty()
            {
                Name = name3,
                Value = value3,
            };

            this.Assert.AreEqual(name3, multiValueProperty.Name, "Expected equal name values.");
            this.Assert.AreSame(value3, multiValueProperty.Value, "Expected reference equal values for property 'Value'.");
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:48,代码来源:ODataPropertyTests.cs


示例9: ODataAvroWriterTests

        static ODataAvroWriterTests()
        {
            var type = new EdmEntityType("NS", "SimpleEntry");
            type.AddStructuralProperty("TBoolean", EdmPrimitiveTypeKind.Boolean, true);
            type.AddStructuralProperty("TInt32", EdmPrimitiveTypeKind.Int32, true);
            type.AddStructuralProperty("TCollection", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt64(false))));
            var cpx = new EdmComplexType("NS", "SimpleComplex");
            cpx.AddStructuralProperty("TBinary", EdmPrimitiveTypeKind.Binary, true);
            cpx.AddStructuralProperty("TString", EdmPrimitiveTypeKind.String, true);
            type.AddStructuralProperty("TComplex", new EdmComplexTypeReference(cpx, true));
            TestEntityType = type;

            binary0 = new byte[] { 4, 7 };
            complexValue0 = new ODataComplexValue()
            {
                Properties = new[]
                {
                    new ODataProperty {Name = "TBinary", Value = binary0 ,},
                    new ODataProperty {Name = "TString", Value = "iamstr",},
                },
                TypeName = "NS.SimpleComplex"
            };

            longCollection0 = new[] {7L, 9L};
            var collectionValue0 = new ODataCollectionValue { Items = longCollection0 };

            entry0 = new ODataEntry
            {
                Properties = new[]
                {
                    new ODataProperty {Name = "TBoolean", Value = true,},
                    new ODataProperty {Name = "TInt32", Value = 32,},
                    new ODataProperty {Name = "TComplex", Value = complexValue0,},
                    new ODataProperty {Name = "TCollection", Value = collectionValue0 },
                },
                TypeName = "NS.SimpleEntry"
            };
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:38,代码来源:ODataAvroWriterTests.cs


示例10: AssertODataCollectionValueAreEqual

        private static void AssertODataCollectionValueAreEqual(ODataCollectionValue expectedCollectionValue, ODataCollectionValue actualCollectionValue)
        {
            Assert.IsNotNull(expectedCollectionValue);
            Assert.IsNotNull(actualCollectionValue);
            Assert.AreEqual(expectedCollectionValue.TypeName, actualCollectionValue.TypeName);
            var expectedItemsArray = expectedCollectionValue.Items.OfType<object>().ToArray();
            var actualItemsArray = actualCollectionValue.Items.OfType<object>().ToArray();

            Assert.AreEqual(expectedItemsArray.Length, actualItemsArray.Length);
            for (int i = 0; i < expectedItemsArray.Length; i++)
            {
                var expectedOdataValue = expectedItemsArray[i] as ODataValue;
                var actualOdataValue = actualItemsArray[i] as ODataValue;
                if (expectedOdataValue != null && actualOdataValue != null)
                {
                    AssertODataValueAreEqual(expectedOdataValue, actualOdataValue);
                }
                else
                {
                    Assert.AreEqual(expectedItemsArray[i], actualItemsArray[i]);
                }
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:23,代码来源:ODataValueAssertEqualHelper.cs


示例11: ConvertCollectionValue

        private static object ConvertCollectionValue(ODataCollectionValue collection, IEdmTypeReference propertyType,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmCollectionTypeReference collectionType = propertyType as IEdmCollectionTypeReference;
            Contract.Assert(collectionType != null, "The type for collection must be a IEdmCollectionType.");

            ODataEdmTypeDeserializer deserializer = deserializerProvider.GetEdmTypeDeserializer(collectionType);
            return deserializer.ReadInline(collection, collectionType, readContext);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:DeserializationHelpers.cs


示例12: CreateODataCollectionValue

        /// <summary>
        /// Creates an <see cref="ODataCollectionValue"/> for the enumerable represented by <paramref name="enumerable"/>.
        /// </summary>
        /// <param name="enumerable">The value of the collection to be created.</param>
        /// <param name="elementType">The element EDM type of the collection.</param>
        /// <param name="writeContext">The serializer context to be used while creating the collection.</param>
        /// <returns>The created <see cref="ODataCollectionValue"/>.</returns>
        public virtual ODataCollectionValue CreateODataCollectionValue(IEnumerable enumerable, IEdmTypeReference elementType,
            ODataSerializerContext writeContext)
        {
            if (writeContext == null)
            {
                throw Error.ArgumentNull("writeContext");
            }
            if (elementType == null)
            {
                throw Error.ArgumentNull("elementType");
            }

            ArrayList valueCollection = new ArrayList();

            if (enumerable != null)
            {
                ODataEdmTypeSerializer itemSerializer = null;
                foreach (object item in enumerable)
                {
                    itemSerializer = itemSerializer ?? SerializerProvider.GetEdmTypeSerializer(elementType);
                    if (itemSerializer == null)
                    {
                        throw new SerializationException(
                            Error.Format(SRResources.TypeCannotBeSerialized, elementType.FullName(), typeof(ODataMediaTypeFormatter).Name));
                    }

                    // ODataCollectionWriter expects the individual elements in the collection to be the underlying values and not ODataValues.
                    valueCollection.Add(itemSerializer.CreateODataValue(item, elementType, writeContext).GetInnerValue());
                }
            }

            // Ideally, we'd like to do this:
            // string typeName = _edmCollectionType.FullName();
            // But ODataLib currently doesn't support .FullName() for collections. As a workaround, we construct the
            // collection type name the hard way.
            string typeName = "Collection(" + elementType.FullName() + ")";

            // ODataCollectionValue is only a V3 property, arrays inside Complex Types or Entity types are only supported in V3
            // if a V1 or V2 Client requests a type that has a collection within it ODataLib will throw.
            ODataCollectionValue value = new ODataCollectionValue
            {
                Items = valueCollection,
                TypeName = typeName
            };

            AddTypeNameAnnotationAsNeeded(value, writeContext.MetadataLevel);
            return value;
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:55,代码来源:ODataCollectionSerializer.cs


示例13: ConvertCollection

            internal static object ConvertCollection(ODataCollectionValue collectionValue, IEdmTypeReference edmTypeReference,
                ModelBindingContext bindingContext, ODataDeserializerContext readContext)
            {
                Contract.Assert(collectionValue != null);

                IEdmCollectionTypeReference collectionType = edmTypeReference as IEdmCollectionTypeReference;
                Contract.Assert(collectionType != null);

                ODataCollectionDeserializer deserializer =
                    (ODataCollectionDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);

                object value = deserializer.ReadInline(collectionValue, collectionType, readContext);
                if (value == null)
                {
                    return null;
                }

                IEnumerable collection = value as IEnumerable;
                Contract.Assert(collection != null);

                Type clrType = bindingContext.ModelType;
                Type elementType;
                if (!clrType.IsCollection(out elementType))
                {
                    // EdmEntityCollectionObject and EdmComplexCollectionObject are collection types.
                    throw new ODataException(String.Format(CultureInfo.InvariantCulture,
                        SRResources.ParameterTypeIsNotCollection, bindingContext.ModelName, clrType));
                }

                IEnumerable newCollection;
                if (CollectionDeserializationHelpers.TryCreateInstance(clrType, collectionType, elementType, out newCollection))
                {
                    collection.AddToCollection(newCollection, elementType, bindingContext.ModelName, bindingContext.ModelType);
                    if (clrType.IsArray)
                    {
                        newCollection = CollectionDeserializationHelpers.ToArray(newCollection, elementType);
                    }

                    return newCollection;
                }

                return null;
            }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:43,代码来源:ODataModelBinderProvider.cs


示例14: CollectionOfPrimitiveCustomInstanceAnnotationOnErrorShouldRoundtrip

 public void CollectionOfPrimitiveCustomInstanceAnnotationOnErrorShouldRoundtrip()
 {
     var originalCollectionValue = new ODataCollectionValue
     {
         TypeName = "Collection(Edm.String)",
         Items = new[] { "value1", "value2" }
     };
     var original = new KeyValuePair<string, ODataValue>("sample.error", originalCollectionValue);
     var error = this.WriteThenReadErrorWithInstanceAnnotation(original);
     var annotation = RunBasicVerificationAndGetAnnotationValue("sample.error", error);
     annotation.Should().BeOfType<ODataCollectionValue>();
     annotation.As<ODataCollectionValue>().Items.Cast<string>().Count().Should().Be(2);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:13,代码来源:CustomInstanceAnnotationRoundtrippingTests.cs


示例15: WritingAPrimitiveCollectionValuedAnnotationWithMismatchedMetadataShouldThrow

 public void WritingAPrimitiveCollectionValuedAnnotationWithMismatchedMetadataShouldThrow()
 {
     ODataCollectionValue collection = new ODataCollectionValue { Items = new[] { 123.4 } };
     var annotation = AtomInstanceAnnotation.CreateFrom(new ODataInstanceAnnotation("custom.primitiveCollection", collection), /*target*/ null);
     Action test = () => this.serializer.WriteInstanceAnnotation(annotation);
     test.ShouldThrow<ODataException>().WithMessage(Strings.CollectionWithoutExpectedTypeValidator_IncompatibleItemTypeName("Edm.Double", "Edm.Int32"));
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:7,代码来源:ODataAtomPropertyAndValueSerializerTests.cs


示例16: SetCoverColors

 public void SetCoverColors(ODataCollectionValue values)
 {
     this.CoverColors = new Collection<Color>();
     foreach (var item in values.Items)
     {
         ODataEnumValue enumItem = item as ODataEnumValue;
         this.CoverColors.Add((Color)Enum.Parse(typeof(Color), enumItem.Value));
     }
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:9,代码来源:DefaultModels.cs


示例17: WriteCollectionValue

 public void WriteCollectionValue(ODataCollectionValue collectionValue, IEdmTypeReference metadataTypeReference, bool isTopLevelProperty, bool isInUri, bool isOpenPropertyType)
 {
     this.WriteCollectionVerifier.Should().NotBeNull("WriteCollectionValue was called.");
     this.WriteCollectionVerifier(collectionValue, metadataTypeReference, isTopLevelProperty, isInUri, isOpenPropertyType);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:5,代码来源:MockJsonLightValueSerializer.cs


示例18: SerializeTopLevelPropertyOfCollectionTypeShouldWork

        public void SerializeTopLevelPropertyOfCollectionTypeShouldWork()
        {
            EdmModel model = new EdmModel();

            EdmComplexType complexType = new EdmComplexType("ns", "complex");
            complexType.AddProperty(new EdmStructuralProperty(complexType, "propertyName1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            complexType.AddProperty(new EdmStructuralProperty(complexType, "propertyName2", EdmCoreModel.Instance.GetString(isNullable: false)));
            model.AddElement(complexType);

            ODataCollectionValue primitiveCollectionValue = new ODataCollectionValue { Items = new[] { "value1", "value2" }};
            primitiveCollectionValue.TypeName = "Collection(Edm.String)";
            ODataProperty primitiveCollectionProperty = new ODataProperty { Name = "PrimitiveCollectionProperty", Value = primitiveCollectionValue };

            string pval = SerializeProperty(model, primitiveCollectionProperty);
            pval.Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\"?><m:value xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/$metadata#Collection(Edm.String)\" m:type=\"#Collection(String)\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:element>value1</m:element><m:element>value2</m:element></m:value>");
            
            ODataComplexValue complexValue1 = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "propertyName1", Value = 1 }, new ODataProperty { Name = "propertyName2", Value = "stringValue" } }, TypeName = "ns.complex" };
            ODataComplexValue complexValue2 = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "propertyName1", Value = 1 }, new ODataProperty { Name = "propertyName2", Value = "stringValue" } }, TypeName = "ns.complex" };
            ODataCollectionValue complexCollectionValue = new ODataCollectionValue { Items = new[] { complexValue1, complexValue2 }, TypeName = "Collection(ns.complex)" };
            ODataProperty complexCollectionProperty = new ODataProperty { Name = "ComplexCollectionProperty", Value = complexCollectionValue };

            string cval = SerializeProperty(model, complexCollectionProperty);
            cval.Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\"?><m:value xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:gml=\"http://www.opengis.net/gml\" m:context=\"http://odata.org/$metadata#Collection(ns.complex)\" m:type=\"#Collection(ns.complex)\" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:element><d:propertyName1 m:type=\"Int32\">1</d:propertyName1><d:propertyName2>stringValue</d:propertyName2></m:element><m:element><d:propertyName1 m:type=\"Int32\">1</d:propertyName1><d:propertyName2>stringValue</d:propertyName2></m:element></m:value>");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:24,代码来源:ODataAtomPropertyAndValueSerializerTests.cs


示例19: ReadCollectionParameterValue

        public static ODataCollectionValue ReadCollectionParameterValue(ODataCollectionReader collectionReader)
        {
            List<object> collectionItems = new List<object>();
            while (collectionReader.Read())
            {
                if (collectionReader.State == ODataCollectionReaderState.Completed)
                {
                    break;
                }

                if (collectionReader.State == ODataCollectionReaderState.Value)
                {
                    collectionItems.Add(collectionReader.Item);
                }
            }

            ODataCollectionValue result = new ODataCollectionValue();
            result.Items = collectionItems;
            return result;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:20,代码来源:ODataObjectModelConverter.cs


示例20: WritingNullableCollectionValue

        public void WritingNullableCollectionValue()
        {
            EdmModel model = new EdmModel();
            EdmEntityType entityType = new EdmEntityType("NS", "MyTestEntity");
            EdmStructuralProperty key =
                entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);
            entityType.AddKeys(key);
            entityType.AddStructuralProperty(
                "NullableIntNumbers",
                new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt32(true))));
            model.AddElement(entityType);

            var collectionValue = new ODataCollectionValue()
            {
                Items = new int?[] { null },
                TypeName = "Collection(Edm.Int32)"
            };

            ODataEntry entry = new ODataEntry()
            {
                Id = new Uri("http://test/Id"),
                TypeName = "NS.MyTestEntity",
                Properties = new[]
                {
                    new ODataProperty { Name = "NullableIntNumbers", Value = collectionValue },
                },
                SerializationInfo = MySerializationInfo
            };

            string outputPayload = this.WriterEntry(model, entry, entityType);
            string expectedPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
                    "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" xmlns:georss=\"http://www.georss.org/georss\" " +
                    "xmlns:gml=\"http://www.opengis.net/gml\" " +
                    "m:context=\"http://odata.org/$metadata#MyTestEntity/$entity\">" +
                    "<id>http://test/Id</id>" +
                    "<category term=\"#NS.MyTestEntity\" scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" />" +
                    "<title />" +
                    "<author><name /></author>" +
                    "<content type=\"application/xml\">" +
                        "<m:properties>" +
                             "<d:NullableIntNumbers m:type=\"#Collection(Int32)\">" +
                                "<m:element m:null=\"true\" />" +
                             "</d:NullableIntNumbers>" +
                        "</m:properties>" +
                    "</content>" +
                "</entry>";

            outputPayload = Regex.Replace(outputPayload, "<updated>[^<]*</updated>", "");
            outputPayload.Should().Be(expectedPayload);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:51,代码来源:PropertyAndValueAtomWriterIntegrationTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Core.ODataComplexValue类代码示例发布时间:2022-05-26
下一篇:
C# Headers.MediaTypeHeaderValue类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap