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


C# EdmModel.DirectValueAnnotations方法代码示例

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


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

示例1: ExerciseBadtypes

        public void ExerciseBadtypes()
        {
            IEdmModel model = new EdmModel();

            IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "BadEntity");
            IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);
            IEdmComplexType complexDef = new EdmComplexType("MyNamespace", "BadComplex");
            IEdmComplexTypeReference complexRef = new EdmComplexTypeReference(complexDef, false);

            IEdmCollectionTypeReference badCollectionRef = entityRef.AsCollection();
            IEdmEntityTypeReference badEntityRef = complexRef.AsEntity();
            IEdmComplexTypeReference badComplexRef = entityRef.AsComplex();
            IEdmEntityReferenceTypeReference badEntityRefRef = entityRef.AsEntityReference();
            IEdmPrimitiveTypeReference badTemporal = entityRef.AsTemporal();
            IEdmPrimitiveTypeReference badDecimal = entityRef.AsDecimal();
            IEdmPrimitiveTypeReference badString = entityRef.AsString();
            IEdmPrimitiveTypeReference badSpatial = entityRef.AsSpatial();
            IEdmPrimitiveTypeReference badBinary = entityRef.AsBinary();
            IEdmPrimitiveTypeReference badPrimitive = entityRef.AsPrimitive();
            IEdmEnumTypeReference badEnum = entityRef.AsEnum();

            Assert.IsTrue(badCollectionRef.IsCollection(), "Bad collection is collection");

            Assert.IsTrue(badEntityRef.IsEntity(), "Bad Entity is Entity");
            Assert.AreEqual(0, badEntityRef.Key().Count(), "Bad Entity has no key");
            Assert.AreEqual("MyNamespace.BadComplex", badEntityRef.FullName(), "Bad named refs keep name");
            Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, badEntityRef.EntityDefinition().SchemaElementKind, "Bad named type definitions are still type definitions");
            Assert.IsNull(badEntityRef.EntityDefinition().BaseType, "Bad Entity has no base type");
            Assert.AreEqual(Enumerable.Empty<IEdmProperty>(), badEntityRef.EntityDefinition().DeclaredProperties, "Bad structured types have no properties");
            Assert.IsFalse(badEntityRef.EntityDefinition().IsAbstract, "Bad structured types are not abstract");
            Assert.IsFalse(badEntityRef.EntityDefinition().IsOpen, "Bad structured types are not open");
            model.SetAnnotationValue(badEntityRef.Definition, "foo", "bar", new EdmStringConstant(new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false), "baz"));
            Assert.AreEqual(1, model.DirectValueAnnotations(badEntityRef.Definition).Count(), "Bad Entity can hold annotations");
            Assert.IsNotNull(model.GetAnnotationValue(badEntityRef.Definition, "foo", "bar"), "Bad Entity can find annotations");
            Assert.AreEqual(EdmTermKind.Type, badEntityRef.EntityDefinition().TermKind, "EntityType has correct term kind");

            Assert.IsTrue(badComplexRef.IsComplex(), "Bad Complex is Bad");
            Assert.IsNull(badComplexRef.ComplexDefinition().FindProperty("PropertyName"), "Bad structured types return null for find property");

            Assert.AreEqual(EdmTypeKind.EntityReference, badEntityRefRef.TypeKind(), "Bad Entity Reference is Entity Reference");
            Assert.AreEqual(String.Empty, badEntityRefRef.EntityType().Name, "Bad Entity Reference has empty named EntityType");
            model.SetAnnotationValue(badEntityRefRef.Definition, "foo", "bar", new EdmStringConstant(new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false), "baz"));
            Assert.AreEqual(1, model.DirectValueAnnotations(badEntityRefRef.Definition).Count(), "Bad Entity Reference can hold annotations");
            Assert.IsNotNull(model.GetAnnotationValue(badEntityRefRef.Definition, "foo", "bar"), "Bad Entity Reference can find annotations");

            Assert.AreEqual(EdmPrimitiveTypeKind.None, badPrimitive.PrimitiveKind(), "Bad Primitive has no primitive kind");
            Assert.AreEqual(EdmTypeKind.Primitive, badPrimitive.TypeKind(), "Bad Primitive has primitive type kind");
            Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, badPrimitive.PrimitiveDefinition().SchemaElementKind, "Bad Primitive is still Type Definition");
            Assert.AreEqual("BadEntity", badPrimitive.PrimitiveDefinition().Name, "Bad Primitive retains name");
            Assert.AreEqual("MyNamespace", badPrimitive.PrimitiveDefinition().Namespace, "Bad Primitive retains namespace name");

            Assert.AreEqual(EdmTypeKind.Enum, badEnum.TypeKind(), "Bad enum has right kind.");
            Assert.AreEqual(EdmPrimitiveTypeKind.Int32, badEnum.EnumDefinition().UnderlyingType.PrimitiveKind, "Underlying type has correct kind.");
            Assert.AreEqual(0, badEnum.EnumDefinition().Members.Count(), "bad enum has no members.");
            Assert.AreEqual(false, badEnum.EnumDefinition().IsFlags, "bad enum not treated as bits.");
            Assert.AreEqual(EdmSchemaElementKind.TypeDefinition, badEnum.EnumDefinition().SchemaElementKind, "bad enum is type definition.");
            Assert.AreEqual("BadEntity", badEnum.EnumDefinition().Name, "Bad enum retains name");
            Assert.AreEqual("MyNamespace", badEnum.EnumDefinition().Namespace, "Bad enum retains namespace name");

            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badSpatial.Definition.Errors().First().ErrorCode, "Bad spatial has correct error code.");
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:61,代码来源:TypeSemanticsUnitTests.cs

示例2: CsdlWriterShouldFailWithGoodMessageWhenWritingInvalidXml

        public void CsdlWriterShouldFailWithGoodMessageWhenWritingInvalidXml()
        {
            var model = new EdmModel();
            model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4);
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // set annotation which will be serialzed (because the value is an IEdmValue) with a name that doesn't match the xml spec for NCName.
            model.SetAnnotationValue(fredFlintstone, "sap", "-contentversion", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            var stringWriter = new StringWriter();
            var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true });

            try
            {
                IEnumerable<EdmError> errors;
                model.TryWriteCsdl(xmlWriter, out errors);
                Assert.Fail("Excepted an exception when trying to serialize a direct value annotation which does not match the xml naming spec.");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(e.Message, "Invalid name character in '-contentversion'. The '-' character, hexadecimal value 0x2D, cannot be included in a name.", "Expected exception message did not match.");
            }

            xmlWriter.Close();
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:29,代码来源:SemanticValidationTests.cs

示例3: ValidationShouldFailOnNonXmlValidAnnotation

        public void ValidationShouldFailOnNonXmlValidAnnotation()
        {
            var model = new EdmModel();
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // Set annnotation which would be serialized as an attribute to be a value that is invalid per the xml spec.
            model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            IEnumerable<EdmError> errors;
            model.Validate(out errors);
            Assert.AreEqual(1, errors.Count(), "Model expected to be invalid.");
            EdmError error = errors.Single();
            Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code");
            Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message");
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:19,代码来源:SemanticValidationTests.cs

示例4: ValidationShouldFailOnNonXmlValidAnnotationWhichWontBeSerialized

        public void ValidationShouldFailOnNonXmlValidAnnotationWhichWontBeSerialized()
        {
            var model = new EdmModel();
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // Making the value of the annotation not an IEdmValue means that it won't be serialized out as an attribute annotation.
            // We should still fail on this anyway, since being strict now has fewer consequences than trying to introduce strictness later.
            model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", 1);

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            IEnumerable<EdmError> errors;
            model.Validate(out errors);
            Assert.AreEqual(1, errors.Count(), "Model expected to be invalid.");
            EdmError error = errors.Single();
            Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code");
            Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message");
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:20,代码来源:SemanticValidationTests.cs

示例5: AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation

        public void AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation()
        {
            var model = new EdmModel();
            model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4);
            var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
            fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            model.AddElement(fredFlintstone);

            // set the annotation name to a value which is valid XML, but not a valid SimpleIdentifier.
            model.SetAnnotationValue(fredFlintstone, "sap", "content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));

            Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);

            IEnumerable<EdmError> errors;
            model.Validate(out errors);
            Assert.AreEqual(0, errors.Count(), "Model expected to be valid.");
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:17,代码来源:SemanticValidationTests.cs


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