public Task ExtendModelAsync( ModelContext context, CancellationToken cancellationToken) { var model = context.Model; var entityContainer = model.EntityContainer as EdmEntityContainer; foreach (ActionMethodInfo actionInfo in this.ActionInfos) { var returnTypeReference = ConventionalActionProvider.GetReturnTypeReference(actionInfo.Method.ReturnType); var action = new EdmAction(entityContainer.Namespace, actionInfo.ActionName, returnTypeReference); foreach (ParameterInfo parameter in actionInfo.Method.GetParameters()) { EdmOperationParameter actionParam = new EdmOperationParameter( action, parameter.Name, ConventionalActionProvider.GetTypeReference(parameter.ParameterType)); action.AddParameter(actionParam); } model.AddElement(action); if (!action.IsBound) { EdmActionImport actionImport = new EdmActionImport(entityContainer, action.Name, action); entityContainer.AddElement(actionImport); } } return Task.FromResult<object>(null); }
/// <summary> /// Creates and adds an action import to this entity container. /// </summary> /// <param name="name">Name of the action import.</param> /// <param name="action">Action that the action import is importing to the container.</param> /// <param name="entitySet">An entity set containing entities returned by this action import. /// The two expression kinds supported are <see cref="IEdmEntitySetReferenceExpression"/> and <see cref="IEdmPathExpression"/>.</param> /// <returns>Created action import.</returns> public virtual EdmActionImport AddActionImport(string name, IEdmAction action, IEdmExpression entitySet) { EdmActionImport actionImport = new EdmActionImport(this, name, action, entitySet); this.AddElement(actionImport); return(actionImport); }
/// <summary> /// Creates and adds an action import to this entity container. /// </summary> /// <param name="name">Name of the action import.</param> /// <param name="action">Action that the action import is importing to the container.</param> /// <returns>Created action import.</returns> public virtual EdmActionImport AddActionImport(string name, IEdmAction action) { EdmActionImport actionImport = new EdmActionImport(this, name, action, null); this.AddElement(actionImport); return(actionImport); }
public void EdmActionImportConstructorShouldDefaultNonSpecifiedPropertiesCorrectly() { var edmAction = new EdmAction("DefaultNamespace", "Checkout", this.boolType); var edmActionImport = new EdmActionImport(this.entityContainer, "CheckoutImport", edmAction, null); edmActionImport.Name.Should().Be("CheckoutImport"); edmActionImport.EntitySet.Should().BeNull(); edmActionImport.Container.Should().Be(this.entityContainer); edmActionImport.Action.Should().Be(edmAction); }
public void AmbigiousOperationBindingShouldReferToFirstOperationAlwaysWhenNotNull() { var container1 =new EdmEntityContainer("n", "d"); var container2 =new EdmEntityContainer("n", "d"); var action1Import = new EdmActionImport(container1, "name", new EdmAction("n", "name", null)); var functionImport = new EdmFunctionImport(container2, "name", new EdmFunction("n", "name", EdmCoreModel.Instance.GetString(true))); var ambigiousOperationBinding = new AmbiguousOperationImportBinding(action1Import, functionImport); ambigiousOperationBinding.ContainerElementKind.Should().Be(EdmContainerElementKind.ActionImport); ambigiousOperationBinding.Name.Should().Be("name"); ambigiousOperationBinding.EntitySet.Should().BeNull(); ambigiousOperationBinding.Container.Should().Be(container1); }
public void EdmActionImportConstructorShouldHaveSpecifiedConstructorValues() { var actionEntitySetPath = new EdmPathExpression("Param1/Nav"); var edmAction = new EdmAction("DefaultNamespace", "Checkout", this.boolType, true, actionEntitySetPath); edmAction.AddParameter(new EdmOperationParameter(edmAction, "Param1", new EdmEntityTypeReference(personType, true))); var actionImportEntitySetPath = new EdmPathExpression("Param1/Nav2"); var edmActionImport = new EdmActionImport(this.entityContainer, "checkoutImport", edmAction, actionImportEntitySetPath); edmActionImport.Name.Should().Be("checkoutImport"); edmActionImport.Container.Should().Be(this.entityContainer); edmActionImport.EntitySet.Should().Be(actionImportEntitySetPath); edmActionImport.Action.Should().Be(edmAction); }
public void Initialize() { this.edmModel = new EdmModel(); this.defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); this.edmModel.AddElement(this.defaultContainer); this.townType = new EdmEntityType("TestModel", "Town"); this.edmModel.AddElement(townType); EdmStructuralProperty townIdProperty = townType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); townType.AddKeys(townIdProperty); townType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false)); townType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); this.cityType = new EdmEntityType("TestModel", "City", this.townType); cityType.AddStructuralProperty("Photo", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(cityType); this.districtType = new EdmEntityType("TestModel", "District"); EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); districtType.AddKeys(districtIdProperty); districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); districtType.AddStructuralProperty("Thumbnail", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(districtType); cityType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Districts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo { Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.One }); this.defaultContainer.AddEntitySet("Cities", cityType); this.defaultContainer.AddEntitySet("Districts", districtType); this.metropolisType = new EdmEntityType("TestModel", "Metropolis", this.cityType); this.metropolisType.AddStructuralProperty("MetropolisStream", EdmCoreModel.Instance.GetStream(/*isNullable*/false)); this.edmModel.AddElement(metropolisType); metropolisType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MetropolisNavigation", Target = districtType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.action = new EdmAction("TestModel", "Action", new EdmEntityTypeReference(this.cityType, true)); this.action.AddParameter("Param", EdmCoreModel.Instance.GetInt32(false)); this.edmModel.AddElement(action); this.actionImport = new EdmActionImport(this.defaultContainer, "Action", action); this.actionConflictingWithPropertyName = new EdmAction("TestModel", "Zip", new EdmEntityTypeReference(this.districtType, true)); this.actionConflictingWithPropertyName.AddParameter("Param", EdmCoreModel.Instance.GetInt32(false)); this.edmModel.AddElement(actionConflictingWithPropertyName); this.actionImportConflictingWithPropertyName = new EdmActionImport(this.defaultContainer, "Zip", actionConflictingWithPropertyName); this.openType = new EdmEntityType("TestModel", "OpenCity", this.cityType, false, true); }
static ODataEntryMetadataContextTest() { ActualEntityType = new EdmEntityType("ns", "TypeName"); ActualEntityType.AddKeys(new IEdmStructuralProperty[] {ActualEntityType.AddStructuralProperty("ID2", EdmPrimitiveTypeKind.Int32), ActualEntityType.AddStructuralProperty("ID3", EdmPrimitiveTypeKind.Int32)}); ActualEntityType.AddStructuralProperty("Name2", EdmCoreModel.Instance.GetString(isNullable:true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("Name3", EdmCoreModel.Instance.GetString(isNullable: true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("StreamProp1", EdmPrimitiveTypeKind.Stream); ActualEntityType.AddStructuralProperty("StreamProp2", EdmPrimitiveTypeKind.Stream); var navProp1 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp1" }); var navProp2 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Name = "NavProp2" }); var container = new EdmEntityContainer("Namespace", "Container"); EdmEntitySet entitySet = container.AddEntitySet("EntitySet", ActualEntityType); entitySet.AddNavigationTarget(navProp1, entitySet); entitySet.AddNavigationTarget(navProp2, entitySet); Action1 = new EdmAction("Namespace", "Action1", null, true /*isBound*/, null /*entitySetPath*/); Action2 = new EdmAction("Namespace", "Action2", null, true /*isBound*/, null /*entitySetPath*/); ActionImport1 = new EdmActionImport(container, "ActionImport1", Action1); ActionImport2 = new EdmActionImport(container, "ActionImport2", Action2); Function1 = new EdmFunction("Namespace", "Function1", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); Function2 = new EdmFunction("Namespace", "Function2", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); FunctionImport1 = new EdmFunctionImport(container, "FunctionImport1", Function1); FunctionImport2 = new EdmFunctionImport(container, "FunctionImport2", Function2); }
static ODataJsonLightEntryAndFeedDeserializerTests() { EdmModel tmpModel = new EdmModel(); EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType"); complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); tmpModel.AddElement(complexType); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); tmpModel.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); tmpModel.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); defaultContainer.AddElement(EntitySet); Action = new EdmAction("TestNamespace", "DoSomething", null, true, null); Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false)); tmpModel.AddElement(Action); ActionImport = defaultContainer.AddActionImport("DoSomething", Action); var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true)); defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction); tmpModel.AddElement(serviceOperationFunction); tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset)); tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date)); tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay)); EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel); MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings(); }
public static IEdmModel ModelWithInvalidActionImportEntitySet() { EdmModel model = new EdmModel(); var entity = new EdmEntityType("Foo", "Bar"); var id1 = new EdmStructuralProperty(entity, "Id", EdmCoreModel.Instance.GetInt16(false), null, EdmConcurrencyMode.None); entity.AddKeys(id1); EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmAction action = new EdmAction("Default", "Foo", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entity, false)))); model.AddElement(action); EdmOperationImport actionImport1 = new EdmActionImport(container, "Foo", action, new EdmIntegerConstant(EdmCoreModel.Instance.GetInt32(false), 123)); container.AddElement(actionImport1); model.AddElement(container); model.AddElement(entity); return model; }
private static void AddProcedure( this IEdmModel model, ProcedureConfiguration procedure, EdmEntityContainer container, Dictionary<Type, IEdmStructuredType> edmTypeMap, Dictionary<string, EdmEntitySet> edmEntitySetMap, bool isAction) { IEdmTypeReference returnReference = GetEdmTypeReference(edmTypeMap, procedure.ReturnType, nullable: true); IEdmExpression expression = GetEdmEntitySetExpression(edmEntitySetMap, procedure); IEdmPathExpression pathExpression = procedure.EntitySetPath != null ? new EdmPathExpression(procedure.EntitySetPath) : null; EdmOperation operation; EdmOperationImport operationImport; if (isAction) { EdmAction action = new EdmAction( container.Namespace, procedure.Name, returnReference, procedure.IsBindable, pathExpression); operation = action; operationImport = new EdmActionImport(container, procedure.Name, action, expression); } else { EdmFunction function = new EdmFunction( container.Namespace, procedure.Name, returnReference, procedure.IsBindable, pathExpression, procedure.IsComposable); operation = function; operationImport = new EdmFunctionImport( container, procedure.Name, function, expression, includeInServiceDocument: true); } AddProcedureParameters(operation, procedure, edmTypeMap); if (procedure.IsBindable) { model.SetIsAlwaysBindable(operation, procedure.IsAlwaysBindable); AddProcedureLinkBuilder(model, operation, procedure); ValidateProcedureEntitySetPath(model, operationImport, procedure); } EdmModel edmModel = model as EdmModel; if (edmModel != null) { edmModel.AddElement(operation); } container.AddElement(operationImport); }
public void EdmActionImportShouldBeActionImport() { var action = new EdmAction("d.s", "checkout", null); var actionImport = new EdmActionImport(new EdmEntityContainer("d", "c"), "checkout", action); actionImport.IsActionImport().Should().BeTrue(); actionImport.IsFunctionImport().Should().BeFalse(); }
public ODataConventionalEntityMetadataBuilderTests() { #region Product Entry this.productEntry = new ODataEntry(); this.sinlgeKeyCollection = new Dictionary<string, object>() { { "Id", 42 } }; this.multiKeysCollection = new Dictionary<string, object>() { { "KeyA", "keya" }, { "KeyB", 1 } }; TestFeedAndEntryTypeContext productTypeContext = new TestFeedAndEntryTypeContext { NavigationSourceName = EntitySetName, NavigationSourceEntityTypeName = EntityTypeName, ExpectedEntityTypeName = EntityTypeName, IsMediaLinkEntry = false, UrlConvention = UrlConvention.CreateWithExplicitValue(/*generateKeyAsSegment*/ false), IsFromCollection = false, NavigationSourceKind = EdmNavigationSourceKind.EntitySet }; TestEntryMetadataContext productEntryMetadataContext = new TestEntryMetadataContext { TypeContext = productTypeContext, Entry = this.productEntry, ETagProperties = new[] { new KeyValuePair<string, object>("Name", "Value") }, KeyProperties = this.sinlgeKeyCollection, ActualEntityTypeName = EntityTypeName, SelectedBindableOperations = new IEdmOperation[0], SelectedNavigationProperties = new IEdmNavigationProperty[0], SelectedStreamProperties = new Dictionary<string, IEdmStructuralProperty>() }; this.productConventionalEntityMetadataBuilder = new ODataConventionalEntityMetadataBuilder(productEntryMetadataContext, this.metadataContext, this.uriBuilder); this.productEntry.MetadataBuilder = this.productConventionalEntityMetadataBuilder; #endregion Product Entry #region Derived, MultiKey, Multi ETag, MLE Entry var action = new EdmAction("TestModel", "Action", /*returnType*/ null, /*isBindable*/ true, /*entitySet*/ null); var actionImport = new EdmActionImport(TestModel.Container, "Action", action); var function = new EdmFunction("TestModel", "Function", /*returnType*/ EdmCoreModel.Instance.GetInt32(true), /*isBindable*/ true, /*entitySet*/ null, false /*isComposable*/); var functionImport = new EdmFunctionImport(TestModel.Container, "Function", function); this.derivedMultiKeyMultiEtagMleEntry = new ODataEntry(); TestFeedAndEntryTypeContext derivedMultiKeyMultiEtagMleTypeContext = new TestFeedAndEntryTypeContext { NavigationSourceName = EntitySetName, NavigationSourceEntityTypeName = EntityTypeName, ExpectedEntityTypeName = DerivedEntityTypeName, IsMediaLinkEntry = true, UrlConvention = UrlConvention.CreateWithExplicitValue(/*generateKeyAsSegment*/ false), IsFromCollection = false }; TestEntryMetadataContext derivedProductMleEntryMetadataContext = new TestEntryMetadataContext { TypeContext = derivedMultiKeyMultiEtagMleTypeContext, Entry = this.derivedMultiKeyMultiEtagMleEntry, ETagProperties = new[] { new KeyValuePair<string, object>("ETag1", "ETagValue1"), new KeyValuePair<string, object>("ETag2", "ETagValue2") }, KeyProperties = this.multiKeysCollection, ActualEntityTypeName = DerivedMleEntityTypeName, SelectedBindableOperations = new IEdmOperation[] { action, function }, SelectedNavigationProperties = TestModel.ProductWithNavPropsType.NavigationProperties(), SelectedStreamProperties = new Dictionary<string, IEdmStructuralProperty> { {"Photo", new EdmStructuralProperty(TestModel.ProductType, "Photo", EdmCoreModel.Instance.GetStream( /*isNullable*/true))} }, }; this.derivedMultiKeyMultiEtagMleConventionalEntityMetadataBuilder = new ODataConventionalEntityMetadataBuilder(derivedProductMleEntryMetadataContext, this.metadataContext, this.uriBuilder); this.derivedMultiKeyMultiEtagMleEntry.MetadataBuilder = this.derivedMultiKeyMultiEtagMleConventionalEntityMetadataBuilder; #endregion Derived, MultiKey, Multi ETag, MLE Entry #region Contained Product Entry this.containedCollectionProductEntry = new ODataEntry(); this.containedSinlgeKeyCollection = new Dictionary<string, object>() { { "Id", 43 } }; this.containedMultiKeysCollection = new Dictionary<string, object>() { { "KeyA", "keya" }, { "KeyB", 2 } }; TestFeedAndEntryTypeContext containedCollectionProductTypeContext = new TestFeedAndEntryTypeContext { NavigationSourceName = EntitySetName, NavigationSourceEntityTypeName = EntityTypeName, ExpectedEntityTypeName = EntityTypeName, IsMediaLinkEntry = false, UrlConvention = UrlConvention.CreateWithExplicitValue(/*generateKeyAsSegment*/ false), NavigationSourceKind = EdmNavigationSourceKind.ContainedEntitySet, IsFromCollection = true }; TestEntryMetadataContext containedCollectionProductEntryMetadataContext = new TestEntryMetadataContext { TypeContext = containedCollectionProductTypeContext, Entry = this.containedCollectionProductEntry, ETagProperties = new[] { new KeyValuePair<string, object>("Name", "Value") }, KeyProperties = this.containedSinlgeKeyCollection, ActualEntityTypeName = EntityTypeName, SelectedBindableOperations = new IEdmOperation[0], SelectedNavigationProperties = new IEdmNavigationProperty[0], SelectedStreamProperties = new Dictionary<string, IEdmStructuralProperty>() }; this.containedCollectionProductConventionalEntityMetadataBuilder = new ODataConventionalEntityMetadataBuilder(containedCollectionProductEntryMetadataContext, this.metadataContext, this.uriBuilder); this.containedCollectionProductEntry.MetadataBuilder = this.containedCollectionProductConventionalEntityMetadataBuilder; this.containedCollectionProductEntry.MetadataBuilder.ParentMetadataBuilder = this.productConventionalEntityMetadataBuilder; this.containedProductEntry = new ODataEntry(); this.containedSinlgeKeyCollection = new Dictionary<string, object>() { { "Id", 43 } }; this.containedMultiKeysCollection = new Dictionary<string, object>() { { "KeyA", "keya" }, { "KeyB", 2 } }; TestFeedAndEntryTypeContext containedProductTypeContext = new TestFeedAndEntryTypeContext { NavigationSourceName = EntitySetName, NavigationSourceEntityTypeName = EntityTypeName, ExpectedEntityTypeName = EntityTypeName, IsMediaLinkEntry = false, UrlConvention = UrlConvention.CreateWithExplicitValue(/*generateKeyAsSegment*/ false), NavigationSourceKind = EdmNavigationSourceKind.ContainedEntitySet, IsFromCollection = false }; TestEntryMetadataContext containedProductEntryMetadataContext = new TestEntryMetadataContext { TypeContext = containedProductTypeContext, Entry = this.containedCollectionProductEntry, ETagProperties = new[] { new KeyValuePair<string, object>("Name", "Value") }, KeyProperties = this.containedSinlgeKeyCollection, ActualEntityTypeName = EntityTypeName, SelectedBindableOperations = new IEdmOperation[0], SelectedNavigationProperties = new IEdmNavigationProperty[0], SelectedStreamProperties = new Dictionary<string, IEdmStructuralProperty>() }; this.containedProductConventionalEntityMetadataBuilder = new ODataConventionalEntityMetadataBuilder(containedProductEntryMetadataContext, this.metadataContext, this.uriBuilder); this.containedProductEntry.MetadataBuilder = this.containedProductConventionalEntityMetadataBuilder; this.containedProductEntry.MetadataBuilder.ParentMetadataBuilder = this.productConventionalEntityMetadataBuilder; #endregion }
static AutoComputePayloadMetadataInJsonIntegrationTests() { EntityType = new EdmEntityType("Namespace", "EntityType", null, false, false, true); EntityType.AddKeys(EntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); EntityType.AddStructuralProperty("StreamProp1", EdmPrimitiveTypeKind.Stream); EntityType.AddStructuralProperty("StreamProp2", EdmPrimitiveTypeKind.Stream); EntityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed); DerivedType = new EdmEntityType("Namespace", "DerivedType", EntityType, false, true); AnotherEntityType = new EdmEntityType("Namespace", "AnotherEntityType", null, false, false, true); AnotherEntityType.AddKeys(AnotherEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); AnotherEntityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed); var deferredNavLinkProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "DeferredNavLink" }); var expandedNavLinkProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "ExpandedNavLink" }); var navLinkDeclaredOnlyInModelProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavLinkDeclaredOnlyInModel" }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "ContainedNavProp", ContainsTarget = true }); DerivedType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "DerivedContainedNavProp", ContainsTarget = true }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.One, Name = "ContainedNonCollectionNavProp", ContainsTarget = true }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = AnotherEntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "AnotherContainedNavProp", ContainsTarget = true }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = AnotherEntityType, TargetMultiplicity = EdmMultiplicity.One, Name = "AnotherContainedNonCollectionNavProp", ContainsTarget = true }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.One, Name = "UnknownNonCollectionNavProp", ContainsTarget = false }); EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "UnknownCollectionNavProp", ContainsTarget = false }); var container = new EdmEntityContainer("Namespace", "Container"); EntitySet = container.AddEntitySet("EntitySet", EntityType); EntitySet.AddNavigationTarget(deferredNavLinkProp, EntitySet); EntitySet.AddNavigationTarget(expandedNavLinkProp, EntitySet); EntitySet.AddNavigationTarget(navLinkDeclaredOnlyInModelProp, EntitySet); Model = new EdmModel(); Model.AddElement(EntityType); Model.AddElement(DerivedType); Model.AddElement(AnotherEntityType); Model.AddElement(container); var alwaysBindableAction1 = new EdmAction("Namespace", "AlwaysBindableAction1", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); alwaysBindableAction1.AddParameter(new EdmOperationParameter(alwaysBindableAction1, "p", new EdmEntityTypeReference(EntityType, isNullable: true))); Model.AddElement(alwaysBindableAction1); var alwaysBindableActionImport1 = new EdmActionImport(container, "AlwaysBindableAction1", alwaysBindableAction1); container.AddElement(alwaysBindableActionImport1); var alwaysBindableAction2 = new EdmAction("Namespace", "AlwaysBindableAction2", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); alwaysBindableAction2.AddParameter(new EdmOperationParameter(alwaysBindableAction2, "p", new EdmEntityTypeReference(EntityType, isNullable: true))); Model.AddElement(alwaysBindableAction2); var alwaysBindableActionImport2 = new EdmActionImport(container, "AlwaysBindableAction2", alwaysBindableAction2); container.AddElement(alwaysBindableActionImport2); var action1 = new EdmAction("Namespace", "Action1", null /*returnType*/, false /*isBound*/, null /*entitySetPath*/); action1.AddParameter(new EdmOperationParameter(action1, "p", new EdmEntityTypeReference(EntityType, isNullable: true))); Model.AddElement(action1); var actionImport1 = new EdmActionImport(container, "Action1", action1); container.AddElement(actionImport1); var action2 = new EdmAction("Namespace", "Action1", null /*returnType*/, false /*isBound*/, null /*entitySetPath*/); action2.AddParameter(new EdmOperationParameter(action2, "p", new EdmEntityTypeReference(EntityType, isNullable: true))); Model.AddElement(action2); var actionImport2 = new EdmActionImport(container, "Action1", action2); container.AddElement(actionImport2); var alwaysBindableFunction1 = new EdmFunction("Namespace", "AlwaysBindableFunction1", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, false /*iscomposable*/); alwaysBindableFunction1.AddParameter("p", new EdmEntityTypeReference(EntityType, isNullable: true)); Model.AddElement(alwaysBindableFunction1); var alwaysBindableFunctionImport1 = new EdmFunctionImport(container, "AlwaysBindableFunction1", alwaysBindableFunction1); container.AddElement(alwaysBindableFunctionImport1); var alwaysBindableFunction2 = new EdmFunction("Namespace", "AlwaysBindableFunction2", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, false /*iscomposable*/); alwaysBindableFunction2.AddParameter("p", new EdmEntityTypeReference(EntityType, isNullable: true)); Model.AddElement(alwaysBindableFunction2); var alwaysBindableFunctionImport2 = new EdmFunctionImport(container, "AlwaysBindableFunction2", alwaysBindableFunction2); container.AddElement(alwaysBindableFunctionImport2); var function1 = new EdmFunction("Namespace", "Function1", EdmCoreModel.Instance.GetString(isNullable: true), false /*isBound*/, null /*entitySetPath*/, false /*iscomposable*/); function1.AddParameter("p", new EdmEntityTypeReference(EntityType, isNullable: true)); Model.AddElement(function1); var functionImport1 = new EdmFunctionImport(container, "Function1", function1); container.AddElement(functionImport1); var function2 = new EdmFunction("Namespace", "Function1", EdmCoreModel.Instance.GetString(isNullable: true), false /*isBound*/, null /*entitySetPath*/, false /*iscomposable*/); function2.AddParameter("p", new EdmEntityTypeReference(EntityType, isNullable: true)); Model.AddElement(function2); var functionImport2 = new EdmFunctionImport(container, "Function1", function2); container.AddElement(functionImport2); var function3 = new EdmFunction("Namespace", "Function3", new EdmEntityTypeReference(EntityType, false), true /*isBound*/, new EdmPathExpression("p/ContainedNonCollectionNavProp"), false /*iscomposable*/); function3.AddParameter("p", new EdmEntityTypeReference(EntityType, isNullable: true)); Model.AddElement(function3); }
public void VerifyTwoIdenticalNamedActionImportsWithSameEntitySetOnlyWrittenOnce() { var actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmEntitySetReferenceExpression(new EdmEntitySet(defaultContainer, "Set", new EdmEntityType("foo", "type")))); var actionImport2 = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmEntitySetReferenceExpression(new EdmEntitySet(defaultContainer, "Set", new EdmEntityType("foo", "type")))); VisitAndVerifyXml( (visitor) => { visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { actionImport, actionImport2 }); }, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""Set"" />"); }
public void ValidateIncorrectEdmExpressionThrows() { EdmActionImport actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmIntegerConstant(EdmCoreModel.Instance.GetInt32(true), 1)); Action errorTest = () => CreateEdmModelCsdlSchemaWriterForErrorTest().WriteActionImportElementHeader(actionImport); errorTest.ShouldThrow<InvalidOperationException>().WithMessage(Strings.EdmModel_Validator_Semantic_OperationImportEntitySetExpressionIsInvalid(actionImport.Name)); }
/// <summary> /// Initializes a new <see cref="IEdmActionImport"/> instance. /// </summary> /// <param name="name">name of the service operation.</param> /// <param name="action">Action that the action import is importing into the container.</param> /// <param name="resultSet">EntitySet of the result expected from this operation.</param> /// <returns>An ActionImport</returns> public EdmActionImport AddActionImport(string name, IEdmAction action, IEdmEntitySet resultSet) { EdmActionImport actionImport = new EdmActionImport(this, name, action, resultSet == null ? null : new EdmEntitySetReferenceExpression(resultSet)); this.AddOperationImport(name, actionImport); return actionImport; }
public static EdmModel OperationImportParameterWithAnnotationModel() { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false)); EdmOperationParameter simpleOperationName = new EdmOperationParameter(simpleOperationAction, "Name", EdmCoreModel.Instance.GetString(true)); simpleOperationAction.AddParameter(simpleOperationName); model.AddElement(simpleOperationAction); EdmOperationImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction); container.AddElement(simpleOperation); model.AddElement(container); var annotationElement = new XElement("{http://foo}Annotation", 1); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleOperationName, "http://foo", "Annotation", annotation); return model; }
/// <summary> /// Creates and adds an action import to this entity container. /// </summary> /// <param name="name">Name of the action import.</param> /// <param name="action">Action that the action import is importing to the container.</param> /// <returns>Created action import.</returns> public virtual EdmActionImport AddActionImport(string name, IEdmAction action) { EdmActionImport actionImport = new EdmActionImport(this, name, action, null); this.AddElement(actionImport); return actionImport; }
public static EdmModel ComplexNamespaceOverlappingModel() { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(simpleOperationAction); EdmActionImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction); container.AddElement(simpleOperation); model.AddElement(container); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo}Child", new XElement("{http://foo1}GrandChild", new XElement("{http://foo}GreatGrandChild", "1" ) ) ), new XElement("{http://foo1}Child", new XElement("{http://foo}GrandChild", "1" ) ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleOperation, "http://foo", "Annotation", annotation); return model; }
public void VerifyIdenticalNamedActionImportsWithDifferentEntitySetPropertiesAreWritten() { var actionImportOnSet = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmEntitySetReferenceExpression(new EdmEntitySet(defaultContainer, "Set", new EdmEntityType("foo", "type")))); var actionImportOnSet2 = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmEntitySetReferenceExpression(new EdmEntitySet(defaultContainer, "Set2", new EdmEntityType("foo", "type")))); var actionImportWithNoEntitySet = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, null); var actionImportWithUniqueEdmPath = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmPathExpression("path1", "path2")); VisitAndVerifyXml( (visitor) => { visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { actionImportOnSet, actionImportOnSet2, actionImportWithNoEntitySet, actionImportWithUniqueEdmPath }); }, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""Set"" /><ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""Set2"" /><ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" /><ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""path1/path2"" />"); }
public void VerifyTwoIdenticalNamedActionImportsWithSameEdmPathOnlyWrittenOnce() { var actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmPathExpression("path1", "path2")); var actionImport2 = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmPathExpression("path1", "path2")); VisitAndVerifyXml( (visitor) => { visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { actionImport, actionImport2 }); }, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""path1/path2"" />"); }
public void ValidateCorrectActionImportNameAndActionAttributeValueWrittenCorrectly() { EdmActionImport actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, null); TestWriteActionImportElementHeaderMethod(actionImport, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"""); }
public void VerifyActionImportWrittenCorrectly() { var actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, null); VisitAndVerifyXml( (visitor) => visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[]{ actionImport}), @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" />"); }
public void ValidateEntitySetAtttributeCorrectlyWritesOutEntitySet() { EdmActionImport actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, new EdmEntitySetReferenceExpression(new EdmEntitySet(defaultContainer, "Customers", new EdmEntityType("DefaultNamespace", "Customer")))); TestWriteActionImportElementHeaderMethod(actionImport, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" EntitySet=""Customers"""); }
public void ConstructibleModelODataTestModelAnnotationTestWithAnnotations() { EdmModel model = new EdmModel(); EdmComplexType address = new EdmComplexType("TestModel", "Address"); EdmStructuralProperty addressStreet = address.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true)); EdmStructuralProperty addressZip = address.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(false)); model.SetAnnotationValue(addressZip, "http://docs.oasis-open.org/odata/ns/metadata", "MimeType", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "text/plain")); model.AddElement(address); EdmEntityType person = new EdmEntityType("TestModel", "PersonType"); EdmStructuralProperty personName = person.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.SetAnnotationValue(personName, "http://docs.oasis-open.org/odata/ns/metadata", "MimeType", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "text/plain")); EdmStructuralProperty personAddress = person.AddStructuralProperty("Address", new EdmComplexTypeReference(address, false)); EdmStructuralProperty personPicture = person.AddStructuralProperty("Picture", EdmCoreModel.Instance.GetStream(false)); EdmStructuralProperty personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); person.AddKeys(personId); model.AddElement(person); EdmEntityContainer container = new EdmEntityContainer("TestModel", "DefaultContainer"); EdmEntitySet personSet = container.AddEntitySet("PersonType", person); EdmEntitySet peopleSet = container.AddEntitySet("People", person); EdmAction serviceOperationAction = new EdmAction("TestModel", "ServiceOperation1", EdmCoreModel.Instance.GetInt32(false)); EdmOperationParameter a = new EdmOperationParameter(serviceOperationAction, "a", EdmCoreModel.Instance.GetInt32(true)); EdmOperationParameter b = new EdmOperationParameter(serviceOperationAction, "b", EdmCoreModel.Instance.GetString(true)); serviceOperationAction.AddParameter(a); serviceOperationAction.AddParameter(b); model.AddElement(serviceOperationAction); EdmOperationImport serviceOperation = new EdmActionImport(container, "ServiceOperation1", serviceOperationAction); model.SetAnnotationValue(serviceOperation, "http://docs.oasis-open.org/odata/ns/metadata", "MimeType", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "img/jpeg")); container.AddElement(serviceOperation); model.AddElement(container); this.BasicConstructibleModelTestSerializingStockModel(ODataTestModelBuilder.ODataTestModelAnnotationTestWithAnnotations, model); }
/// <summary> /// Creates and adds an action import to this entity container. /// </summary> /// <param name="name">Name of the action import.</param> /// <param name="action">Action that the action import is importing to the container.</param> /// <param name="entitySet">An entity set containing entities returned by this action import. /// The two expression kinds supported are <see cref="IEdmEntitySetReferenceExpression"/> and <see cref="IEdmPathExpression"/>.</param> /// <returns>Created action import.</returns> public virtual EdmActionImport AddActionImport(string name, IEdmAction action, IEdmExpression entitySet) { EdmActionImport actionImport = new EdmActionImport(this, name, action, entitySet); this.AddElement(actionImport); return actionImport; }
public void VerifyTwoIdenticalNamedActionImportsWithNoEntitySetPropertyOnlyWrittenOnce() { var actionImport = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, null); var actionImport2 = new EdmActionImport(defaultContainer, "Checkout", defaultCheckoutAction, null); VisitAndVerifyXml( (visitor) => { visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { actionImport, actionImport2 }); }, @"<ActionImport Name=""Checkout"" Action=""Default.NameSpace2.CheckOut"" />"); }