示例#1
0
        public void WriteFeedWithoutOperation()
        {
            Action <ODataJsonLightOutputContext> test = outputContext =>
            {
                var entry = new ODataEntry();
                entry.Properties = new List <ODataProperty>()
                {
                    new ODataProperty()
                    {
                        Name = "ID", Value = 1
                    }
                };

                var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
                parameterWriter.WriteStart();
                var entryWriter = parameterWriter.CreateFeedWriter("feed");
                entryWriter.WriteStart(new ODataFeed());
                entryWriter.WriteStart(entry);
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                parameterWriter.WriteEnd();
                parameterWriter.Flush();
            };

            WriteAndValidate(test, "{\"feed\":[{\"ID\":1}]}", writingResponse: false);
        }
示例#2
0
        public void WriteFeedWithMultipleEntries()
        {
            EdmEntityType          entityType = new EdmEntityType("NS", "Entity");
            IEdmStructuralProperty keyProp    = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false));

            entityType.AddProperty(keyProp);
            entityType.AddKeys(keyProp);
            EdmEntityType derivedType = new EdmEntityType("NS", "DerivedType", entityType);

            derivedType.AddProperty(new EdmStructuralProperty(derivedType, "Name", EdmCoreModel.Instance.GetString(false)));

            EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true));

            operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false))));

            Action <ODataJsonLightOutputContext> test = outputContext =>
            {
                var entry = new ODataEntry();
                entry.Properties = new List <ODataProperty>()
                {
                    new ODataProperty()
                    {
                        Name = "ID", Value = 1
                    }
                };

                var entry2 = new ODataEntry()
                {
                    TypeName = "NS.DerivedType",
                };
                entry2.Properties = new List <ODataProperty>()
                {
                    new ODataProperty()
                    {
                        Name = "ID", Value = 1
                    },
                    new ODataProperty()
                    {
                        Name = "Name", Value = "TestName"
                    }
                };

                var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
                parameterWriter.WriteStart();
                var entryWriter = parameterWriter.CreateFeedWriter("feed");
                entryWriter.WriteStart(new ODataFeed());
                entryWriter.WriteStart(entry);
                entryWriter.WriteEnd();
                entryWriter.WriteStart(entry2);
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                parameterWriter.WriteEnd();
                parameterWriter.Flush();
            };

            WriteAndValidate(test, "{\"feed\":[{\"ID\":1},{\"@odata.type\":\"#NS.DerivedType\",\"ID\":1,\"Name\":\"TestName\"}]}", writingResponse: false);
        }
示例#3
0
        public void WriteContainedFeed()
        {
            EdmEntityType entityType = new EdmEntityType("NS", "Entity");

            entityType.AddProperty(new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)));

            EdmEntityType expandEntityType = new EdmEntityType("NS", "ExpandEntity");

            expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Id", EdmCoreModel.Instance.GetInt32(false)));
            expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Name", EdmCoreModel.Instance.GetString(false)));

            entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                ContainsTarget = true, Name = "Property1", Target = expandEntityType, TargetMultiplicity = EdmMultiplicity.Many
            });

            EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true));

            operation.AddParameter("entry", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false))));

            Action <ODataJsonLightOutputContext> test = outputContext =>
            {
                var entry1 = new ODataEntry();
                entry1.Properties = new List <ODataProperty>()
                {
                    new ODataProperty()
                    {
                        Name = "ID", Value = 1
                    },
                };

                var entry2 = new ODataEntry();
                entry2.Properties = new List <ODataProperty>()
                {
                    new ODataProperty()
                    {
                        Name = "ID", Value = 1
                    },
                    new ODataProperty()
                    {
                        Name = "Name", Value = "TestName"
                    }
                };

                var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
                parameterWriter.WriteStart();
                var entryWriter = parameterWriter.CreateFeedWriter("feed");
                entryWriter.WriteStart(new ODataFeed());
                entryWriter.WriteStart(entry1);
                entryWriter.WriteStart(new ODataNavigationLink()
                {
                    Name         = "Property1",
                    IsCollection = true
                });
                entryWriter.WriteStart(new ODataFeed());
                entryWriter.WriteStart(entry2);
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                entryWriter.WriteEnd();
                parameterWriter.WriteEnd();
                parameterWriter.Flush();
            };

            WriteAndValidate(test, "{\"feed\":[{\"ID\":1,\"Property1\":[{\"ID\":1,\"Name\":\"TestName\"}]}]}", writingResponse: false);
        }