/// <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); }
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(); }
public void ShouldCreateSubclassWithoutModelWhenBothSerializationInfoAndMetadataAreGiven() { var typeContext = ODataFeedAndEntryTypeContext.Create(SerializationInfo, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true); typeContext.Should().NotBeNull(); typeContext.GetType().Name.EndsWith("WithoutModel").Should().BeTrue(); }
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"); }
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 }; }
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(); }
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)); }
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); }
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); }
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; }
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); }
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); }
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)); }
public void ShouldCreateBaseClassWhenSerializationInfoAndUserModelAreBothMissingAndThrowIfMissingTypeInfoIsFalse() { var typeContext = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: EdmCoreModel.Instance, throwIfMissingTypeInfo: false); typeContext.Should().BeOfType <ODataFeedAndEntryTypeContext>(); }
public void ShouldCreateBaseClassWhenEntitySetIsGivenButModelIsNotUserModel() { var typeContext = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/ null, EntitySet, EntitySetElementType, ExpectedEntityType, EdmCoreModel.Instance, throwIfMissingTypeInfo: true); typeContext.Should().BeOfType <ODataFeedAndEntryTypeContext>(); }