Exemple #1
0
        /// <summary>
        /// Gets an entity metadata builder for the given entry.
        /// </summary>
        /// <param name="entryState">Entry state to use as reference for information needed by the builder.</param>
        /// <returns>An entity metadata builder.</returns>
        public ODataEntityMetadataBuilder GetEntityMetadataBuilderForReader(IODataJsonLightReaderEntryState entryState)
        {
            Debug.Assert(entryState != null, "entry != null");

            // Only apply the conventional template builder on response. On a request we would only report what's on the wire.
            if (entryState.MetadataBuilder == null)
            {
                ODataEntry entry = entryState.Entry;
                if (this.isResponse)
                {
                    ODataTypeAnnotation typeAnnotation = entry.GetAnnotation <ODataTypeAnnotation>();

                    Debug.Assert(typeAnnotation != null, "The JSON light reader should have already set the ODataTypeAnnotation.");
                    IEdmNavigationSource navigationSource = typeAnnotation.NavigationSource;

                    IEdmEntityType navigationSourceElementType         = this.edmTypeResolver.GetElementType(navigationSource);
                    IODataFeedAndEntryTypeContext typeContext          = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, navigationSource, navigationSourceElementType, entryState.EntityType, this.model, /*throwIfMissingTypeInfo*/ true);
                    IODataEntryMetadataContext    entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, /*serializationInfo*/ null, (IEdmEntityType)entry.GetEdmType().Definition, this, entryState.SelectedProperties);

                    UrlConvention urlConvention            = UrlConvention.ForUserSettingAndTypeContext(/*keyAsSegment*/ null, typeContext);
                    ODataConventionalUriBuilder uriBuilder = new ODataConventionalUriBuilder(this.ServiceBaseUri, urlConvention);

                    entryState.MetadataBuilder = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, this, uriBuilder);
                }
                else
                {
                    entryState.MetadataBuilder = new NoOpEntityMetadataBuilder(entry);
                }
            }

            return(entryState.MetadataBuilder);
        }
Exemple #2
0
        public void ShouldCreateSubclassWithoutModelWhenSerializationInfoIsGiven()
        {
            var typeContext = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: EdmCoreModel.Instance, throwIfMissingTypeInfo: true);

            typeContext.Should().NotBeNull();
            typeContext.GetType().Name.EndsWith("WithoutModel").Should().BeTrue();
        }
Exemple #3
0
        public void ShouldCreateSubclassWithoutModelWhenBothSerializationInfoAndMetadataAreGiven()
        {
            var typeContext = ODataFeedAndEntryTypeContext.Create(SerializationInfo, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);

            typeContext.Should().NotBeNull();
            typeContext.GetType().Name.EndsWith("WithoutModel").Should().BeTrue();
        }
Exemple #4
0
        static ODataFeedAndEntryTypeContextTests()
        {
            Model = new EdmModel();
            EntitySetElementType = new EdmEntityType("ns", "Customer");
            ExpectedEntityType   = new EdmEntityType("ns", "VipCustomer", EntitySetElementType);
            ActualEntityType     = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType);

            EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer");

            Model.AddElement(defaultContainer);
            Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));

            EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType);
            Model.AddElement(EntitySetElementType);
            Model.AddElement(ExpectedEntityType);
            Model.AddElement(ActualEntityType);
            defaultContainer.AddElement(EntitySet);

            SerializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer"
            };
            TypeContextWithoutModel         = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            TypeContextWithModel            = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatThrows       = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false);
        }
        public void InitTest()
        {
            this.testSubject = new ODataStreamReferenceValue();

            var entry = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };

            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
            var fullMetadataBuilder  = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));

            this.streamWithFullBuilder = new ODataStreamReferenceValue();
            this.streamWithFullBuilder.SetMetadataBuilder(fullMetadataBuilder, "Stream");
        }
Exemple #6
0
        public ODataEntryTests()
        {
            this.odataEntry = new ODataEntry();

            this.odataEntryWithFullBuilder = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };
            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(this.odataEntryWithFullBuilder, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);

            this.odataEntryWithFullBuilder.MetadataBuilder = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(new Uri("http://service/", UriKind.Absolute), UrlConvention.CreateWithExplicitValue(false)));

            this.odataEntryWithNullBuilder = new ODataEntry {
                MetadataBuilder = ODataEntityMetadataBuilder.Null
            };
        }
Exemple #7
0
        public void EntryContextUriShouldNotBeWrittenIfNotProvided()
        {
            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "MyContainer.MyCities", NavigationSourceEntityTypeName = "TestModel.MyCity", ExpectedTypeName = "TestModel.MyCity"
            };
            var typeContext = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);

            this.builderWithNoMetadataDocumentUri.BuildContextUri(ODataPayloadKind.Entry, ODataContextUrlInfo.Create(typeContext, true)).Should().BeNull();
        }
Exemple #8
0
        public void ShouldNotIncludeEntityOnSingletonWithoutModel()
        {
            ODataFeedAndEntrySerializationInfo serializationInfo = new ODataFeedAndEntrySerializationInfo()
            {
                ExpectedTypeName = "People", NavigationSourceEntityTypeName = "People", NavigationSourceName = "Boss", NavigationSourceKind = EdmNavigationSourceKind.Singleton,
            };
            var requestSingletonTypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(serializationInfo, /*navigationSource*/ null, /*navigationSourceEntityType*/ null, /*expectedEntityType*/ null, EdmCoreModel.Instance, true);

            this.CreateEntryContextUri(requestSingletonTypeContextWithoutModel).OriginalString.Should().Be(BuildExpectedContextUri("#Boss", false));
        }
Exemple #9
0
        private Uri CreateEntryContextUri(string selectClause, string expandClause)
        {
            SelectExpandClause selectExpandClause = new ODataQueryOptionParser(edmModel, this.cityType, this.citySet, new Dictionary <string, string> {
                { "$expand", expandClause }, { "$select", selectClause }
            }).ParseSelectAndExpand();
            ODataFeedAndEntryTypeContext typeContext = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, this.citySet, this.cityType, this.cityType, this.edmModel, true);
            ODataContextUrlInfo          info        = ODataContextUrlInfo.Create(typeContext, true, new ODataUri()
            {
                SelectAndExpand = selectExpandClause
            });
            Uri contextUrl = this.responseContextUriBuilder.BuildContextUri(ODataPayloadKind.Feed, info);

            return(contextUrl);
        }
Exemple #10
0
        private Uri CreateFeedContextUri(string applyClauseString)
        {
            ApplyClause applyClause = new ODataQueryOptionParser(edmModel, this.cityType, this.citySet, new Dictionary <string, string> {
                { "$apply", applyClauseString }
            }).ParseApply();
            ODataFeedAndEntryTypeContext typeContext = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, this.citySet, this.cityType, this.cityType, this.edmModel, true);
            ODataContextUrlInfo          info        = ODataContextUrlInfo.Create(typeContext, false, new ODataUri()
            {
                Apply = applyClause
            });
            Uri contextUrl = this.responseContextUriBuilder.BuildContextUri(ODataPayloadKind.Feed, info);

            return(contextUrl);
        }
Exemple #11
0
        public ODataNavigationLinkTests()
        {
            this.navigationLink = new ODataNavigationLink();

            var entry = new ODataEntry
            {
                TypeName   = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.Key
                        }
                    },
                    new ODataProperty {
                        Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo {
                            PropertyKind = ODataPropertyKind.ETag
                        }
                    }
                }
            };

            var serializationInfo = new ODataFeedAndEntrySerializationInfo {
                NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType"
            };
            var typeContext          = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext      = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
            var metadataBuilder      = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));

            this.navigationLinkWithFullBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithFullBuilder.MetadataBuilder = metadataBuilder;

            this.navigationLinkWithNoOpBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithNoOpBuilder.MetadataBuilder = new NoOpEntityMetadataBuilder(entry);

            this.navigationLinkWithNullBuilder = new ODataNavigationLink {
                Name = "NavProp"
            };
            this.navigationLinkWithNullBuilder.MetadataBuilder = ODataEntityMetadataBuilder.Null;
        }
Exemple #12
0
 public void ShouldWriteIfSerializationInfoWithoutNavigationSourceButUnknownSetOnFeedResponse()
 {
     this.CreateFeedContextUri(ODataFeedAndEntryTypeContext.Create(
                                   serializationInfo: new ODataFeedAndEntrySerializationInfo()
     {
         ExpectedTypeName = "NS.Type",
         IsFromCollection = true,
         NavigationSourceEntityTypeName = "NS.Type",
         NavigationSourceKind           = EdmNavigationSourceKind.UnknownEntitySet,
         NavigationSourceName           = null
     },
                                   navigationSource: null,
                                   navigationSourceEntityType: null,
                                   expectedEntityType: null,
                                   model: EdmCoreModel.Instance,
                                   throwIfMissingTypeInfo: true),
                               isResponse: true);
 }
Exemple #13
0
 private void InitializeTypeContext()
 {
     this.responseCityTypeContextWithoutSerializationInfo        = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, this.citySet, this.cityType, this.cityType, this.edmModel, throwIfMissingTypeInfo: true);
     this.responseCapitolCityTypeContextWithoutSerializationInfo = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, this.citySet, this.cityType, this.capitolCityType, this.edmModel, throwIfMissingTypeInfo: true);
 }
Exemple #14
0
        public void ShouldNotIncludeFragmentItemSelectorOnSingleton()
        {
            var singletonTypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, this.singletonCity, this.cityType, this.cityType, this.edmModel, throwIfMissingTypeInfo: true);

            this.CreateEntryContextUri(singletonTypeContextWithModel).OriginalString.Should().Be(BuildExpectedContextUri("#SingletonCity", false));
        }
Exemple #15
0
        public void ShouldCreateBaseClassWhenSerializationInfoAndUserModelAreBothMissingAndThrowIfMissingTypeInfoIsFalse()
        {
            var typeContext = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: EdmCoreModel.Instance, throwIfMissingTypeInfo: false);

            typeContext.Should().BeOfType <ODataFeedAndEntryTypeContext>();
        }
Exemple #16
0
        public void ShouldCreateBaseClassWhenEntitySetIsGivenButModelIsNotUserModel()
        {
            var typeContext = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, EntitySet, EntitySetElementType, ExpectedEntityType, EdmCoreModel.Instance, throwIfMissingTypeInfo: true);

            typeContext.Should().BeOfType <ODataFeedAndEntryTypeContext>();
        }