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


C# EdmModel.Fixup方法代码示例

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


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

示例1: ODataJsonLightParameterReaderTests

 public ODataJsonLightParameterReaderTests()
 {
     referencedModel = new EdmModel();
     referencedModel.Fixup();
     this.action = new EdmAction("FQ.NS", "ActionImport", null);
     referencedModel.AddElement(this.action);
     this.model = TestUtils.WrapReferencedModelsToMainModel("TestModel", "DefaultContainer", referencedModel);
 }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:8,代码来源:ODataJsonLightParameterReaderTests.cs

示例2: Init

 public void Init()
 {
     referencedModel = new EdmModel();
     referencedModel.Fixup();
     this.action = new EdmAction("FQ.NS", "ActionImport", null);
     referencedModel.AddElement(this.action);
     this.model = TestUtils.WrapReferencedModelsToMainModel("TestModel", "DefaultContainer", referencedModel);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:ParameterReaderTests.cs

示例3: ComplexValueTest

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

            var emptyComplexType = new EdmComplexType(DefaultNamespaceName, "EmptyComplexType");
            model.AddElement(emptyComplexType);

            var complexTypeWithStringProperty = new EdmComplexType(DefaultNamespaceName, "ComplexTypeWithStringProperty");
            complexTypeWithStringProperty.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            complexTypeWithStringProperty.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            model.AddElement(complexTypeWithStringProperty);

            model.Fixup();
            

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Empty element is a valid complex value
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("TestModel.EmptyComplexType")
                        .XmlValueRepresentation(new XNode[0])
                        .WithTypeAnnotation(emptyComplexType),
                    PayloadEdmModel = model
                },
            };

            testDescriptors = testDescriptors.Concat(
                PropertiesElementAtomValues.CreatePropertiesElementPaddingPayloads<ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.ComplexTypeWithStringProperty")
                            .WithTypeAnnotation(complexTypeWithStringProperty),
                        PayloadEdmModel = model
                    },
                    (complexInstance, xmlValue) => complexInstance.XmlValueRepresentation(xmlValue)));

            testDescriptors = testDescriptors.Select(td => td.InProperty());

            testDescriptors = testDescriptors.Concat(new []
            {
                // Top-level property without expected type and no type name - this is read as primitive string!
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property(null, PayloadBuilder.PrimitiveValue(string.Empty))
                        .XmlRepresentation("<m:value/>"),
                    PayloadEdmModel = model,
                },
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:58,代码来源:ComplexValueReaderAtomTests.cs

示例4: ODataJsonLightReaderIntegrationTests

 static ODataJsonLightReaderIntegrationTests()
 {
     EdmModel tmp = new EdmModel();
     EntityType = new EdmEntityType("Namespace", "EntityType");
     EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub");
     EntitySet = edmEntityContainer.AddEntitySet("EntitySet", EntityType);
     tmp.AddElement(edmEntityContainer);
     tmp.Fixup();
     Model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:ODataJsonLightReaderIntegrationTests.cs

示例5: ODataAtomWriterIntegrationTests

        static ODataAtomWriterIntegrationTests()
        {
            Model = new EdmModel();
            EntityType = new EdmEntityType("Namespace", "EntityType");

            Model.AddElement(EntityType);
            var entityContainer = new EdmEntityContainer("Namespace", "Container");
            EntitySet = entityContainer.AddEntitySet("EntitySet", EntityType);
            Model.AddElement(entityContainer);
            Model.Fixup();
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:ODataAtomWriterIntegrationTests.cs

示例6: HeterogeneousCollectionReaderTest

        public void HeterogeneousCollectionReaderTest()
        {
            EdmModel model = new EdmModel();
            var cityType = new EdmComplexType("TestModel", "CityType");
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            model.AddElement(cityType);

            var addressType = new EdmComplexType("TestModel", "AddressType");
            addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
            model.AddElement(addressType);

            var testContainer = new EdmEntityContainer("TestModel", "TestContainer");
            model.AddElement(testContainer);
            EdmFunction citiesFunction = new EdmFunction("TestModel", "Cities", EdmCoreModel.GetCollection(cityType.ToTypeReference()));
            model.AddElement(citiesFunction);
            EdmOperationImport citiesFunctionImport = testContainer.AddFunctionImport("Cities", citiesFunction);
            model.Fixup();
            
            // Add some hand-crafted payloads
            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // expected type without type names in the payload and heterogeneous items
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = new ComplexInstanceCollection(
                        PayloadBuilder.ComplexValue().Property("Name", PayloadBuilder.PrimitiveValue("Vienna")),
                        PayloadBuilder.ComplexValue().Property("Street", PayloadBuilder.PrimitiveValue("Am Euro Platz")))
                        .ExpectedFunctionImport(citiesFunctionImport)
                        .CollectionName(null),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "Street", "TestModel.CityType"),
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:42,代码来源:CollectionReaderTests.cs

示例7: NavigationPropertiesProjectionTest

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

            EdmEntityType townType = model.EntityType("TownType");
            townType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);
            townType.NavigationProperty("NavProp1", townType);
            EdmEntitySet townsSet = model.EntitySet("Towns", townType);

            EdmEntityType cityType = new EdmEntityType("TestModel", "CityType", townType);
            model.AddElement(cityType);
            cityType.NavigationProperty("NavProp2", townType);
            model.EntitySet("Cities", cityType);

            EdmEntityType cityType2 = new EdmEntityType("TestModel", "DuplicateCityType", townType);
            model.AddElement(cityType2);
            cityType2.NavigationProperty("NavProp2", townType);
            model.EntitySet("DuplicateCities", cityType2);

            model.Fixup();

            var testCases = new ProjectionTestCase[]
            {
                #region No $select
                new ProjectionTestCase
                {
                    DebugDescription = "No $select => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + one property in the payload => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = null,
                },
                #endregion No $select
                #region Empty $select
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + one property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1"),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = string.Empty,
                },
                #endregion Empty $select
                #region $select=*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", /*url*/null).NavigationProperty("NavProp2", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + one property in the payload => one templatized property.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp2", "http://odata.org/nav2").NavigationProperty("NavProp1", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + two properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).NavigationProperty("NavProp1", "http://odata.org/nav1").NavigationProperty("NavProp2", "http://odata.org/nav2"),
                    ProjectionString = "*",
                },
                #endregion $select=*
                #region $select=NavProp2,*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=NavProp2,* => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:EntryReaderJsonLightTests.cs

示例8: ComplexValueWithMetadataTest

        public void ComplexValueWithMetadataTest()
        {
            // Use some standard complex value payloads first
            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateComplexValueTestDescriptors(this.Settings, true);

            // Add metadata validation tests
            EdmModel model = new EdmModel();
            var innerComplexType = model.ComplexType("InnerComplexType");
            innerComplexType.AddStructuralProperty("name", EdmCoreModel.Instance.GetString(true));

            var complexType = model.ComplexType("ComplexType");
            complexType.AddStructuralProperty("number", EdmPrimitiveTypeKind.Int32);
            complexType.AddStructuralProperty("string", EdmCoreModel.Instance.GetString(true));
            complexType.AddStructuralProperty("complex", MetadataUtils.ToTypeReference(innerComplexType, true));

            var entityType = model.EntityType("EntityType");
            entityType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            model.Fixup();

            // Test that different types of properties not present in the metadata all fail
            IEnumerable<PropertyInstance> undeclaredPropertyTestCases = new PropertyInstance[]
            {
                PayloadBuilder.PrimitiveProperty("undeclared", 42),
                PayloadBuilder.Property("undeclared", PayloadBuilder.ComplexValue(innerComplexType.FullName())),
                PayloadBuilder.Property("undeclared", PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.Int32"))),
                PayloadBuilder.Property("undeclared", PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName("TestModel.InnerComplexType"))),
            };

            testDescriptors = testDescriptors.Concat(
                undeclaredPropertyTestCases.Select(tc =>
                {
                    return new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType)
                            .Property(tc),
                        PayloadEdmModel = model,
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "undeclared", "TestModel.ComplexType"),
                    };
                }));

            testDescriptors = testDescriptors.Concat(new[]
            {
                // Property which should take typename not from value but from the parent metadata
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType)
                        .Property("complex", PayloadBuilder.ComplexValue(innerComplexType.FullName()).PrimitiveProperty("name", null)
                            .JsonRepresentation("{ \"name\" : null }").XmlRepresentation("<d:name m:null=\"true\" />")
                            .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null })),
                    PayloadEdmModel = model,
                },
                // Property which is declared in the metadata but with a different type
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType)
                        .Property("complex", PayloadBuilder.ComplexValue(complexType.FullName())),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "TestModel.ComplexType", "TestModel.InnerComplexType"),
                },
                // Property which is declared in the metadata but with a wrong kind
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue(complexType.FullName()).WithTypeAnnotation(complexType)
                        .Property("complex", PayloadBuilder.ComplexValue(entityType.FullName())),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.EntityType", "Complex", "Entity"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("").WithTypeAnnotation(complexType),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", string.Empty)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexValue("TestModel.NonExistant").WithTypeAnnotation(complexType),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "TestModel.NonExistant"),
                },
            });

            // Wrap the complex type in a property
            testDescriptors = testDescriptors
                .Select((td, index) => new PayloadReaderTestDescriptor(td) { PayloadDescriptor = td.PayloadDescriptor.InProperty("propertyName" + index)})
                .SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td));

            // Handcrafted cases
            testDescriptors = testDescriptors.Concat(new[]
            {
                // Top-level complex property without expected type
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Property("property", PayloadBuilder.ComplexValue(complexType.FullName()).PrimitiveProperty("number", 42)),
                    PayloadEdmModel = model
                },
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ComplexValueReaderTests.cs

示例9: GetFeeds

        /// <summary>
        /// Creates a feed containing entities of types that derive from the same base 
        /// </summary>
        /// <param name="model">The entity model schema. The method will modify the model and call Fixup().</param>
        /// <param name="withTypeNames">True if the payloads should specify type names.</param>
        /// <returns>The feed containing derived typed entities.</returns>
        public static IEnumerable<Taupo.OData.Common.PayloadTestDescriptor> GetFeeds(EdmModel model, bool withTypeNames)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            List<Taupo.OData.Common.PayloadTestDescriptor> payloads = new List<Taupo.OData.Common.PayloadTestDescriptor>();

            EdmEntityType baseType = model.EntityType("MyBaseType").KeyProperty("Id", (EdmPrimitiveTypeReference) EdmCoreModel.Instance.GetGuid(false));
            model.Fixup();

            EntityInstance instance = PayloadBuilder.Entity(withTypeNames ? "TestModel." + baseType.Name : null).Property("Id", PayloadBuilder.PrimitiveValue(Guid.NewGuid()));
            instance.Id = "urn:id";

            EntitySetInstance emptySet = PayloadBuilder.EntitySet().WithTypeAnnotation(baseType);

            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor() 
            { 
                PayloadEdmModel = model, 
                PayloadElement = emptySet
            });

            var emptySetWithInlineCount = emptySet.DeepCopy();
            emptySetWithInlineCount.InlineCount = 0;

            // Inline count (note we skip for v1 and request because inline count is valid on response only on V2 and above.
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = emptySetWithInlineCount,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });

            var emptySetWithNextLinkAndCount = emptySet.DeepCopy();
            emptySetWithNextLinkAndCount.InlineCount = 0;
            emptySetWithNextLinkAndCount.NextLink = "http://www.odata.org/Feed";
            
            // inline count + next link
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = emptySetWithNextLinkAndCount,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });

            var emptySetWithNextLink = emptySet.DeepCopy();
            emptySetWithNextLink.NextLink = "http://www.odata.org/Feed";

            // next link
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = emptySetWithNextLink,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });

            EntitySetInstance singleEntity = PayloadBuilder.EntitySet().Append(instance).WithTypeAnnotation(baseType);

            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = singleEntity.DeepCopy()
            });

            var singleEntityWithInlineCount = singleEntity.DeepCopy();
            singleEntityWithInlineCount.InlineCount = 1;

            // inline count
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = singleEntityWithInlineCount,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });

            var singleEntityWithNextLinkAndCount = singleEntity.DeepCopy();
            singleEntityWithInlineCount.InlineCount = 1;
            singleEntityWithNextLinkAndCount.NextLink = "http://www.odata.org/Feed";

            // inline count + next link
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = singleEntityWithNextLinkAndCount,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });

            var singleEntityWithNextLink = singleEntity.DeepCopy();
            singleEntityWithNextLink.NextLink = "http://www.odata.org/Feed";

            // next link 
            payloads.Add(new Taupo.OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = model,
                PayloadElement = singleEntityWithNextLink,
                SkipTestConfiguration = (tc => tc.IsRequest)
            });
//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:TestFeeds.cs

示例10: HomogeneousCollectionReaderAtomTest

        public void HomogeneousCollectionReaderAtomTest()
        {
            EdmModel edmModel = new EdmModel();

            EdmComplexType edmComplexTypeEmpty = new EdmComplexType(ModelNamespace, "EmptyComplexType");
            edmModel.AddElement(edmComplexTypeEmpty);

            EdmComplexType edmComplexTypeCity = new EdmComplexType(ModelNamespace, "CityType");
            edmComplexTypeCity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            edmModel.AddElement(edmComplexTypeCity);

            EdmComplexType edmComplexTypeAddress = new EdmComplexType(ModelNamespace, "AddressType");
            edmComplexTypeAddress.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
            edmModel.AddElement(edmComplexTypeAddress);

            edmModel.Fixup();

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // complex collection with primitive expected type
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new ComplexInstanceCollection(
                        PayloadBuilder.ComplexValue("TestModel.CityType").Property("Name", PayloadBuilder.PrimitiveValue("Vienna")),
                        PayloadBuilder.ComplexValue("TestModel.CityType").Property("Name", PayloadBuilder.PrimitiveValue("Prague"))
                        ).ExpectedCollectionItemType(EdmDataTypes.Int32).CollectionName(null),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "TestModel.CityType", "Primitive", "Complex"),
                },
                
                // primitive collection in XMLRepresentation with complex expected type. 
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new ComplexInstanceCollection(
                        PayloadBuilder.ComplexValue("TestModel.CityType"),
                        PayloadBuilder.ComplexValue("TestModel.CityType")
                        ).ExpectedCollectionItemType(edmComplexTypeCity).CollectionName(null)
                        .XmlRepresentation(@"
                                            <m:value>
                                                <m:element m:type='Edm.Int32'>1</m:element>
                                                <m:element m:type='Edm.Int32'>2</m:element>
                                            </m:value>"),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectTypeKind", "Edm.Int32", "Complex", "Primitive"),
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:55,代码来源:CollectionReaderAtomTests.cs

示例11: OpenPropertiesTest

        public void OpenPropertiesTest()
        {
            // Interesting values to test as open properties.
            // Only test complex and collection values here, since open primitive properties rely on format specific primitive type support.
            // The open primitive properties tests are thus format specific and are here:
            //   JSON - PrimitiveValueReaderJsonTests.UntypedPrimitiveValueTest
            //   ATOM - PrimitiveValueReaderAtomTests.PrimitiveValueWithoutType
            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateComplexValueTestDescriptors(this.Settings, true, false);

            // Add spatial open property tests
            testDescriptors = testDescriptors.Concat(new[]
                {
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.PrimitiveValue(GeographyFactory.Point(10, 20, 30, 40).Build())
                    },
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.PrimitiveValue(GeometryFactory.Point(10, 20, 30, 40).Build())
                    }
                });

            // Add couple of hand-crafted payloads
            testDescriptors = testDescriptors.Concat(new[]
                {
                    // Open complex value with undeclared type - must fail
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.NonExistantType"),
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "TestModel.NonExistantType"),
                    },
                    // Open complex null value
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.NonEmptyComplexType", true),
                    },
                });

            testDescriptors = testDescriptors
                // Wrap the property in an open entity
                .Select(td =>
                {
                    EdmModel model = (EdmModel)td.PayloadEdmModel;
                    model = model == null ? new EdmModel() : (EdmModel)Test.OData.Utils.Metadata.MetadataUtils.Clone(model);
                    var entityType = model.EntityType("OpenEntityType", "TestModel", null, false, true);
                    entityType.AddKeys(entityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
                    entityType.AddStructuralProperty("DateTimeProperty", EdmPrimitiveTypeKind.DateTimeOffset);

                    var complexType = model.ComplexType("NonEmptyComplexType");
                    complexType.AddStructuralProperty("P1", EdmPrimitiveTypeKind.Int32);
                    complexType.AddStructuralProperty("P2", EdmCoreModel.Instance.GetString(true));
                    model = model.Fixup();

                    return new PayloadReaderTestDescriptor(td)
                    {
                        PayloadElement = PayloadBuilder.Entity("TestModel.OpenEntityType")
                            .PrimitiveProperty("ID", 42)
                            .Property("OpenProperty", td.PayloadElement),
                        PayloadEdmModel = model
                    };
                });

            // Add a couple of hand crafted payloads
            {
                EdmModel model = new EdmModel();
                var entityType = model.EntityType("OpenEntityType", null, null, false, true);
                entityType.KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false));
                model = model.Fixup();

                testDescriptors = testDescriptors.Concat(new PayloadReaderTestDescriptor[]
                {
                    // Open stream property is not allowed.
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.Entity("TestModel.OpenEntityType").PrimitiveProperty("ID", 42)
                            .StreamProperty("OpenProperty", "http://odata.org/readlink"),
                        PayloadEdmModel = model,
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_OpenStreamProperty", "OpenProperty"),
                        // TODO: In JSON we recognize this as a complex property - once we make a decision about the bug enable the test for JSON.
                        SkipTestConfiguration = tc => tc.Format != ODataFormat.Atom || tc.IsRequest
                    },
                    // Open deferred navigation property is not allowed.
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.Entity("TestModel.OpenEntityType").PrimitiveProperty("ID", 42)
                            .NavigationProperty("OpenProperty", "http://odata.org/navprop"),
                        PayloadEdmModel = model,
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_OpenNavigationProperty", "OpenProperty", "TestModel.OpenEntityType"),
                        // TODO: In JSON we recognize this as a complex property - once we make a decision about the bug enable the test for JSON.
                        SkipTestConfiguration = tc => tc.Format != ODataFormat.Atom
                    },
                    // Open expanded navigation property (entry) is not allowed.
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.Entity("TestModel.OpenEntityType").PrimitiveProperty("ID", 42)
                            .ExpandedNavigationProperty("OpenProperty", PayloadBuilder.Entity("TestModel.OpenEntityType")),
                        PayloadEdmModel = model,
                        ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_OpenNavigationProperty", "OpenProperty", "TestModel.OpenEntityType"),
                        // This can't work in JSON as it is recognized as a complex value - and will fail for different reasons
                        SkipTestConfiguration = tc => tc.Format != ODataFormat.Atom
//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:EntryReaderTests.cs

示例12: ComplexValuePropertyOrderingTest

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

            var complexType = new EdmComplexType(DefaultNamespaceName, "ComplexType");
            complexType.AddStructuralProperty("stringProperty", EdmCoreModel.Instance.GetString(isNullable: false));
            complexType.AddStructuralProperty("numberProperty", EdmCoreModel.Instance.GetInt32(isNullable: false));
            complexType.AddStructuralProperty("nullProperty", EdmCoreModel.Instance.GetString(isNullable: true));
            model.AddElement(complexType);

            model.Fixup();

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors =
                PropertiesElementAtomValues.CreatePropertiesElementOrderingPayloads<ComplexInstance>(
                    new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = PayloadBuilder.ComplexValue("TestModel.ComplexType"),
                        PayloadEdmModel = model
                    },
                    (complexInstance, xmlNodes) => complexInstance.XmlValueRepresentation(xmlNodes)).Select(td =>
                    new PayloadReaderTestDescriptor(td)
                    {
                        PayloadElement = PayloadBuilder.Property(null, td.PayloadElement).ExpectedPropertyType(new EdmComplexTypeReference(complexType, isNullable: false)),
                    });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:33,代码来源:ComplexValueReaderAtomTests.cs

示例13: CollectionReaderAtomErrorTest

        public void CollectionReaderAtomErrorTest()
        {
            EdmModel edmModel = new EdmModel();

            EdmComplexType edmComplexTypeEmpty = new EdmComplexType(ModelNamespace, "EmptyComplexType");
            edmModel.AddElement(edmComplexTypeEmpty);

            EdmComplexType edmComplexTypeCity = new EdmComplexType(ModelNamespace, "CityType");
            edmComplexTypeCity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            edmModel.AddElement(edmComplexTypeCity);

            EdmComplexType edmComplexTypeAddress = new EdmComplexType(ModelNamespace, "AddressType");
            edmComplexTypeAddress.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
            edmModel.AddElement(edmComplexTypeAddress);

            edmModel.Fixup();

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Verify that collections do not support top level collection type.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new ComplexInstanceCollection().CollectionName(null)
                        .XmlRepresentation(@"<m:value>
                                           <m:element m:type='" + EntityModelUtils.GetCollectionTypeName("Edm.Int32") + @"'>
                                                <m:element>42</m:element>
                                           </m:element>
                                           </m:value>"),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("CollectionWithoutExpectedTypeValidator_InvalidItemTypeKind", "Collection"),
                    SkipTestConfiguration = tc => tc.Version < Microsoft.OData.Core.ODataVersion.V4,
                },

                // Verify that collection inside complex type is not supported.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new  ComplexInstanceCollection().CollectionName(null)
                        .XmlRepresentation(@"<m:value>
                                               <m:element>
                                                <m:element m:type='" + EntityModelUtils.GetCollectionTypeName("Edm.Int32") + @"'>
                                                 <m:element>42</m:element>
                                                </m:element>
                                               </m:element>
                                             </m:value>"),
                    PayloadEdmModel = null, // No model, since otherwise we would fail to read the top-level item as it has no type information
                    ExpectedException = ODataExpectedExceptions.ODataException("CollectionWithoutExpectedTypeValidator_InvalidItemTypeKind", "Collection"),
                    SkipTestConfiguration = tc => tc.Version < Microsoft.OData.Core.ODataVersion.V4,
                },

                // Collection with m:type attribute in the root collection element.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new PrimitiveCollection().CollectionName(null)
                        .XmlRepresentation("<m:value m:type='Edm.Int32'></m:value>"),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomCollectionDeserializer_TypeOrNullAttributeNotAllowed"),
                },

                // Collection with m:null attribute in the Collection element.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new PrimitiveCollection().CollectionName(null)
                        .XmlRepresentation("<m:value m:null='true'></m:value>"),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomCollectionDeserializer_TypeOrNullAttributeNotAllowed"),
                },

                // Collection with both m:type and m:null attribute in the Collection element.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new PrimitiveCollection().CollectionName(null)
                        .XmlRepresentation("<m:value m:null='true' m:type='Edm.Int32'></m:value>"),
                    PayloadEdmModel = edmModel,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomCollectionDeserializer_TypeOrNullAttributeNotAllowed"),
                },

                // root collection element not in the d namespace.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new PrimitiveCollection().CollectionName("PrimitiveCollection")
                        .XmlRepresentation("<d:PrimitiveCollection></d:PrimitiveCollection>"),
                    PayloadEdmModel = edmModel,  
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomCollectionDeserializer_TopLevelCollectionElementWrongNamespace", "http://docs.oasis-open.org/odata/ns/data", "http://docs.oasis-open.org/odata/ns/metadata"),
                },

                // complex value instead of collection.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                    PayloadElement = new PrimitiveCollection().CollectionName(null)
                        .XmlRepresentation(@"<m:value>
                                              <m:city>Seattle</m:city>
                                             </m:value>"),
                    PayloadEdmModel = edmModel, 
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomCollectionDeserializer_WrongCollectionItemElementName", "city", "http://docs.oasis-open.org/odata/ns/data", "http://docs.oasis-open.org/odata/ns/data"),
                },

                // complex collection with expected type and no metadata.
                new PayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings)
                {
                     PayloadElement = new ComplexInstanceCollection(
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:CollectionReaderAtomTests.cs

示例14: BatchReaderMixedEncodingTest

        public void BatchReaderMixedEncodingTest()
        {
            EdmModel model = new EdmModel();
            EdmEntityType personType = model.EntityType("Person")
                .KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference)
                .Property("Name", EdmPrimitiveTypeKind.String, isNullable: true);
            model.Fixup();

            EdmEntitySet personSet = model.EntitySet("Person", personType);

            EntityInstance personInstance = PayloadBuilder.Entity("TestModel.Person")
                .Property("Id", PayloadBuilder.PrimitiveValue(1))
                .Property("Name", PayloadBuilder.PrimitiveValue("Mr Foo Baz"));

            ODataUriSegment root = ODataUriBuilder.Root(new Uri("http://www.odata.org"));
            ODataUri testUri = new ODataUri(root, ODataUriBuilder.EntitySet(personSet));


            Encoding[] encodings = new Encoding[] 
            { 
                Encoding.UTF8, 
                Encoding.BigEndianUnicode, 
                Encoding.Unicode 
            };

            IEnumerable<BatchReaderMixedEncodingTestCase> testCases =
                encodings.SelectMany(batchEncoding =>
                    encodings.Select(changesetEncoding =>
                        new BatchReaderMixedEncodingTestCase
                        {
                            BatchEncoding = batchEncoding,
                            Changesets = new[]
                            {
                                new BatchReaderMixedEncodingChangeset
                                {
                                    ChangesetEncoding = changesetEncoding,
                                    Operations = new[]
                                    {
                                       new BatchReaderMixedEncodingOperation
                                       {
                                           OperationEncoding = Encoding.Unicode,
                                           PayloadFormat = ODataFormat.Atom,
                                       },
                                       new BatchReaderMixedEncodingOperation
                                       {
                                           // Uses changeset's encoding
                                           PayloadFormat = ODataFormat.Atom,
                                       },
                                    },
                                },
                                new BatchReaderMixedEncodingChangeset
                                {
                                    Operations = new[]
                                    {
                                        new BatchReaderMixedEncodingOperation
                                        {
                                            // Uses batch's encoding
                                            OperationEncoding = batchEncoding,
                                            PayloadFormat = ODataFormat.Atom,
                                        },
                                    },
                                },
                            },
                        }
                    ));

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                this.ReaderTestConfigurationProvider.DefaultFormatConfigurations,
                (testCase, testConfiguration) =>
                {
                    var testPayload = personInstance.DeepCopy();
                    if (!testConfiguration.IsRequest)
                    {
                        testPayload.AddAnnotation(new PayloadFormatVersionAnnotation() { Response = true, ResponseWrapper = true });
                    }

                    var testDescriptor = this.CreateTestDescriptor(testCase, testPayload, testUri, testConfiguration.IsRequest);
                    testDescriptor.PayloadEdmModel = model;
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:82,代码来源:BatchReaderMixedEncodingTests.cs

示例15: CollectionWithHeterogenousItemsErrorTest

        public void CollectionWithHeterogenousItemsErrorTest()
        {
            EdmModel model = new EdmModel();
            
            var complexType1 = model.ComplexType("ComplexTypeWithStringAndInteger32")
                .Property("Property1", EdmCoreModel.Instance.GetString(true) as EdmTypeReference)
                .Property("Property2", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);

            var complexType2 = model.ComplexType("ComplexTypeWithStringAndDateTime")
                .Property("Property1", EdmCoreModel.Instance.GetString(true) as EdmTypeReference)
                .Property("Property2", EdmPrimitiveTypeKind.DateTimeOffset);

            model.Fixup();

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Primitive collection containing items of different primitive types
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.PrimitiveMultiValue(EntityModelUtils.GetCollectionTypeName("Edm.Int32")).Item(1).Item(true).Item(2).WithTypeAnnotation(EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false))),
                    PayloadEdmModel = model,
                    ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings)
                    {
                        ExpectedException = tc.Format == ODataFormat.Atom ?
                            ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Boolean", "Edm.Int32") :
                            ODataExpectedExceptions.ODataException("ReaderValidationUtils_CannotConvertPrimitiveValue", "True", "Edm.Int32")
                    }
                },
                // Complex collection containing items of different complex type (correct type attribute value)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName(complexType1.FullName()))
                        .Item(PayloadBuilder.ComplexValue(complexType1.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", -1))
                        .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", DateTimeOffset.Now))
                        .WithTypeAnnotation(EdmCoreModel.GetCollection(complexType1.ToTypeReference())),
                    PayloadEdmModel = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "TestModel.ComplexTypeWithStringAndDateTime", "TestModel.ComplexTypeWithStringAndInteger32"),
                },
                // Complex collection containing items of different complex type (incorrect type attribute value)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ComplexMultiValue(EntityModelUtils.GetCollectionTypeName(complexType2.FullName()))
                        .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", -1))
                        .Item(PayloadBuilder.ComplexValue(complexType2.FullName()).PrimitiveProperty("Property1", "Foo").PrimitiveProperty("Property2", DateTimeOffset.Now))
                        .WithTypeAnnotation(EdmCoreModel.GetCollection(complexType2.ToTypeReference())),
                    PayloadEdmModel = model,
                    ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings)
                    {
                        ExpectedException = tc.Format == ODataFormat.Atom ?
                            ODataExpectedExceptions.ODataException("ValidationUtils_IncompatibleType", "Edm.Int32", "Edm.DateTimeOffset") :
                            ODataExpectedExceptions.ODataException("ReaderValidationUtils_CannotConvertPrimitiveValue", "-1", "Edm.DateTimeOffset")
                    }
                },
            };

           this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    if (testConfiguration.Format == ODataFormat.Atom)
                    {
                        testDescriptor = testDescriptor.InProperty();
                    }
                    else
                    {
                        testDescriptor = testDescriptor.InProperty("RootProperty");
                    }

                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:72,代码来源:CollectionValueReaderTests.cs


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