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


C# EdmModel.EntitySet方法代码示例

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


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

示例1: NullValueNonPropertyErrorTests

        public void NullValueNonPropertyErrorTests()
        {
            EdmModel model = new EdmModel();
            var entityType = model.EntityType("OwningType", "TestModel").KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);
            model.EntityContainer("DefaultContainer");
            var entitySet = model.EntitySet("EntitySet", entityType);

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null collection - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.PrimitiveCollection().ExpectedCollectionItemType(EdmDataTypes.Int32)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Collection")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null entry - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.NullEntity().ExpectedEntityType(entityType, entitySet)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Entry")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null feed - should fail.",
                    PayloadEdmModel = model,
                    PayloadElement = PayloadBuilder.EntitySet().ExpectedEntityType(entityType, entitySet)
                        .JsonRepresentation(
                            "{" + 
                            "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                            "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Feed")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    if (testConfiguration.IsRequest)
                    {
                        return;
                    }

                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    testDescriptor.RunTest(testConfiguration);
                });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:60,代码来源:NullValueTests.cs

示例2: ActionAndFunctionTest


//.........这里部分代码省略.........
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1, function_r1_t2),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1, function_r2_t1 },
                    Atom = GetAtom(function_r1_t1) + GetAtom(function_r2_t1),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1) + "," + GetJsonLightForRelGroup(function_r2_t1),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r1_t1, function_r2_t1, function_r1_t2 },
                    Atom = GetAtom(function_r1_t1) + GetAtom(function_r2_t1) + GetAtom(function_r1_t2),
                    JsonLight = GetJsonLightForRelGroup(function_r1_t1, function_r1_t2) + "," + GetJsonLightForRelGroup(function_r2_t1),
                },
                new {
                    ODataFunctions = new ODataFunction[] { function_r3_t1 },
                    Atom = GetAtom(function_r3_t1),
                    JsonLight = GetJsonLightForRelGroup(function_r3_t1),
                },
            };

            var queryResults =
                from actionCase in actionCases
                from functionCase in functionCases
                select new
                {
                    actionCase.ODataActions,
                    functionCase.ODataFunctions,
                    Atom = string.Concat(actionCase.Atom, functionCase.Atom),
                    JsonLight = string.Join(",", new[] { actionCase.JsonLight, functionCase.JsonLight }.Where(x => x != null))
                };

            EdmModel model = new EdmModel();
            EdmEntityType edmEntityTypeCustomer = model.EntityType("Customer", "TestModel");
            EdmEntityContainer edmEntityContainer = model.EntityContainer("DefaultContainer","TestModel" );
            EdmEntitySet edmEntitySetCustermors = model.EntitySet("Customers", edmEntityTypeCustomer);

            var testDescriptors = queryResults.Select(testCase =>
            {
                ODataEntry entry = ObjectModelUtils.CreateDefaultEntry("TestModel.Customer");

                if (testCase.ODataActions != null)
                {
                    foreach (var action in testCase.ODataActions)
                    {
                        entry.AddAction(action);
                    }
                }

                if (testCase.ODataFunctions != null)
                {
                    foreach (var function in testCase.ODataFunctions)
                    {
                        entry.AddFunction(function);
                    }
                }

                return new PayloadWriterTestDescriptor<ODataItem>(
                    this.Settings,
                    entry,
                    (testConfiguration) =>
                    {
                        if (testConfiguration.Format == ODataFormat.Atom)
                        {
                            return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                            {
                                Xml = "<ODataOperations>" + testCase.Atom + "</ODataOperations>",
                                ExpectedException2 =
开发者ID:AlineGuan,项目名称:odata.net,代码行数:67,代码来源:WriterActionAndFunctionTests.cs

示例3: StreamPropertiesProjectionTest

        public void StreamPropertiesProjectionTest()
        {
            EdmModel model = new EdmModel();
            var container = new EdmEntityContainer("TestModel", "DefaultContainer");
            model.AddElement(container);
            EdmEntityType townType = model.EntityType("TownType");
            townType.KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            townType.StreamProperty("MapSmall");
            townType.StreamProperty("MapMedium");
            townType.NavigationProperty("NavProp", townType);

            EdmEntityType cityType = model.EntityType("CityType", null, townType);
            cityType.StreamProperty("CityLogo");

            EdmEntitySet townsSet = model.EntitySet("Towns", townType);
            model.Fixup();

            var testCases = new ProjectionTestCase[]
            {
                #region No $select
                new ProjectionTestCase
                {
                    DebugDescription = "No $select => three templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + one property in the payload => two templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = null,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "No $select + three properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read").NavigationProperty("NavProp", /*url*/null),
                    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).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ProjectionString = string.Empty,
                },
                new ProjectionTestCase
                {
                    DebugDescription = "Empty $select + three properties in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ProjectionString = string.Empty,
                },
                #endregion Empty $select
                #region $select=*
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* => three templatized stream properties and and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + one property in the payload => two templatized stream properties and one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium").StreamProperty("CityLogo").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=* + three properties in the payload => no templatized stream properties, one templatized navigation.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read"),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapSmall", "http://odata.org/stream/read").StreamProperty("MapMedium", "http://odata.org/stream/read").StreamProperty("CityLogo", "http://odata.org/stream/read").NavigationProperty("NavProp", /*url*/null),
                    ProjectionString = "*",
                },
                #endregion $select=*
                #region $select=MapMedium
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium => one templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1),
                    ExpectedEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapMedium"),
                    ProjectionString = "MapMedium",
                },
                new ProjectionTestCase
                {
                    DebugDescription = "$select=MapMedium + MapMedium property in the payload => no templatized properties.",
                    PayloadEntity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("MapMedium", "http://odata.org/stream/read"),
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:EntryReaderJsonLightTests.cs

示例4: 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

示例5: 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


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