public void GetTemplatesWorksForODataPathWithDollarRefOnCollectionNavigation() { // Arrange EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); var entitySet = container.AddEntitySet("Customers", customer); var navigation = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { TargetMultiplicity = EdmMultiplicity.Many, Name = "SubCustomers", Target = customer }); KeyValuePair <string, object>[] keys = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Id", "{nextKey}") }; KeySegment keySegment = new KeySegment(keys, customer, entitySet); ODataPathTemplate template = new ODataPathTemplate( new EntitySetSegmentTemplate(entitySet), new KeySegmentTemplate(customer, entitySet), new NavigationPropertyLinkSegmentTemplate(new NavigationPropertyLinkSegment(navigation, entitySet)), new KeySegmentTemplate(keySegment)); // Act IEnumerable <string> actual = template.GetTemplates(); // Assert Assert.Equal(4, actual.Count()); Assert.Equal(new[] { "Customers({key})/SubCustomers({nextKey})/$ref", "Customers({key})/SubCustomers/{nextKey}/$ref", "Customers/{key}/SubCustomers({nextKey})/$ref", "Customers/{key}/SubCustomers/{nextKey}/$ref" }, actual); }
public void ODataPathSegmentHandler_Handles_NavigationPropertyLinkSegment() { // Arrange ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); EdmEntityType customer = new EdmEntityType("NS", "customer"); EdmEntityType order = new EdmEntityType("NS", "order"); IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many }); NavigationPropertyLinkSegment segment = new NavigationPropertyLinkSegment(ordersNavProperty, null); // Act handler.Handle(segment); // Assert Assert.Equal("Orders/$ref", handler.PathLiteral); Assert.Null(handler.NavigationSource); }
private static void EdmWriteAnnotationDemo() { Console.WriteLine("EdmWriteAnnotationDemo"); var model = new EdmModel(); var mail = new EdmEntityType("ns", "Mail"); model.AddElement(mail); mail.AddKeys(mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var person = new EdmEntityType("ns", "Person"); model.AddElement(person); person.AddKeys(person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var mails = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Mails", TargetMultiplicity = EdmMultiplicity.Many, Target = mail, }); var ann1 = new EdmAnnotation(mails, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test1")); ann1.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.AddVocabularyAnnotation(ann1); var container = new EdmEntityContainer("ns", "container"); model.AddElement(container); var people = container.AddEntitySet("People", person); var ann2 = new EdmAnnotation(people, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test2")); model.AddVocabularyAnnotation(ann2); ShowModel(model); }
public void ODataPathSegmentHandler_Handles_KeySegment_AfterNavigationProperty() { // Arrange ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); EdmEntityType order = new EdmEntityType("NS", "order"); order.AddKeys(order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many }); NavigationPropertyLinkSegment segment1 = new NavigationPropertyLinkSegment(ordersNavProperty, null); EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default"); EdmEntitySet orders = entityContainer.AddEntitySet("Orders", order); IDictionary <string, object> keys = new Dictionary <string, object> { { "Id", 42 } }; KeySegment segment2 = new KeySegment(keys, order, orders); // Act handler.Handle(segment1); handler.Handle(segment2); // Assert Assert.Equal("Orders(42)/$ref", handler.PathLiteral); Assert.Same(orders, handler.NavigationSource); }
public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm() { var namespaces = new string[] { "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first", "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second" }; var model = new EdmModel(); foreach (var namespaceName in namespaces) { var entityType1 = new EdmEntityType(namespaceName, "validEntityType1"); entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2"); entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3"); entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many }); var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1"); complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false)); model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType }); var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false)); var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false)); model.AddElements(new IEdmSchemaElement[] { function1, function2, function3 }); } return(model); }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable <string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) { _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode); } } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties, Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : null, TargetMultiplicity = property.Partner != null ? property.Partner.Multiplicity() : property.Type.TypeKind() == EdmTypeKind.Collection ? EdmMultiplicity.Many : EdmMultiplicity.Unknown, }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
public TypeResolverTests() { this.serverModel = new EdmModel(); this.clientModel = new ClientEdmModel(ODataProtocolVersion.V4); this.clientEntityType = (IEdmEntityType)this.clientModel.GetOrCreateEdmType(typeof(TestClientEntityType)); this.clientIdProperty = new EdmStructuralProperty(this.clientEntityType, "Id", EdmCoreModel.Instance.GetInt32(false)); var serverType = new EdmEntityType("FQ.NS", "TestServerType"); this.serverModel.AddElement(serverType); var serverContainer = new EdmEntityContainer("FQ.NS", "Container"); this.serverModel.AddElement(serverContainer); serverContainer.AddEntitySet("Entities", serverType); var serverType2 = new EdmEntityType("FQ.NS", "TestServerType2"); this.serverModel.AddElement(serverType2); serverType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Navigation", Target = serverType2, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); }
public void ODataPathSegmentToTemplateHandler_Handles_NavigationPropertyLink() { // Arrange ODataPathSegmentToTemplateHandler handler = new ODataPathSegmentToTemplateHandler(null); EdmEntityType customer = new EdmEntityType("NS", "customer"); EdmEntityType order = new EdmEntityType("NS", "order"); IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many }); NavigationPropertyLinkSegment segment = new NavigationPropertyLinkSegment(ordersNavProperty, null); // Act handler.Handle(segment); // Assert ODataSegmentTemplate segmentTemplate = Assert.Single(handler.Templates); Assert.IsType <NavigationLinkSegmentTemplate>(segmentTemplate); }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, ICollection <string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name, null, entityType.IsAbstract, entityType.IsOpen, entityType.HasStream); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) { _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString); } } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties(), PrincipalProperties = property.PrincipalProperties(), Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.TargetMultiplicity(), }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
public void EdmNavigationPropertyPrincipalPropertiesShouldReturnPrincipalProperties() { EdmEntityType type = new EdmEntityType("ns", "type"); var key = type.AddStructuralProperty("Id1", EdmCoreModel.Instance.GetInt32(false)); var notKey = type.AddStructuralProperty("Id2", EdmCoreModel.Instance.GetString(false)); var p1 = type.AddStructuralProperty("p1", EdmCoreModel.Instance.GetInt32(false)); var p2 = type.AddStructuralProperty("p1", EdmCoreModel.Instance.GetString(false)); type.AddKeys(key); var navInfo1 = new EdmNavigationPropertyInfo() { Name = "nav", Target = type, TargetMultiplicity = EdmMultiplicity.Many, DependentProperties = new[] { p1, p2 }, PrincipalProperties = new[] { key, notKey } }; EdmNavigationProperty navProp = type.AddUnidirectionalNavigation(navInfo1); navProp.PrincipalProperties().Should().NotBeNull(); navProp.PrincipalProperties().ShouldAllBeEquivalentTo(new[] { key, notKey }); }
public CraftModel() { model = new EdmModel(); var address = new EdmComplexType("NS", "Address"); model.AddElement(address); var mail = new EdmEntityType("NS", "Mail"); var mailId = mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); mail.AddKeys(mailId); model.AddElement(mail); var person = new EdmEntityType("NS", "Person"); model.AddElement(person); var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); person.AddKeys(personId); person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, /*Nullable*/ false)); MailBox = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Mails", TargetMultiplicity = EdmMultiplicity.Many, Target = mail, }); var container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); MyLogin = container.AddSingleton("MyLogin", person); }
private void CreateNavigationProperty(EntityTypeConfiguration config) { Contract.Assert(config != null); EdmEntityType entityType = (EdmEntityType)(_types[config.ClrType]); foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties) { EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo(); info.Name = navProp.Name; info.TargetMultiplicity = navProp.Multiplicity; info.Target = _types[navProp.RelatedClrType] as IEdmEntityType; info.OnDelete = navProp.OnDeleteAction; if (navProp.ReferentialConstraint.Any()) { info.DependentProperties = ReorderDependentProperties(navProp); } //TODO: If target end has a multiplity of 1 this assumes the source end is 0..1. // I think a better default multiplicity is * entityType.AddUnidirectionalNavigation(info); } }
public void TranslateNavigationSegmentTemplate_ReturnsODataNavigationSegment() { // Arrange EdmEntityType employee = new EdmEntityType("NS", "Employee"); IEdmNavigationProperty navigation = employee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DirectReports", Target = employee, TargetMultiplicity = EdmMultiplicity.Many }); NavigationSegmentTemplate navigationSegment = new NavigationSegmentTemplate(navigation, null); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext(); // Act ODataPathSegment actual = navigationSegment.Translate(context); // Assert Assert.NotNull(actual); NavigationPropertySegment navSegment = Assert.IsType <NavigationPropertySegment>(actual); Assert.Same(navigation, navSegment.NavigationProperty); Assert.Null(navSegment.NavigationSource); }
private IEdmModel GetModel() { if (myModel == null) { myModel = new EdmModel(); EdmComplexType shippingAddress = new EdmComplexType("MyNS", "ShippingAddress"); shippingAddress.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); shippingAddress.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); shippingAddress.AddStructuralProperty("Region", EdmPrimitiveTypeKind.String); shippingAddress.AddStructuralProperty("PostalCode", EdmPrimitiveTypeKind.String); myModel.AddElement(shippingAddress); EdmComplexTypeReference shippingAddressReference = new EdmComplexTypeReference(shippingAddress, true); EdmEntityType orderType = new EdmEntityType("MyNS", "Order"); orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); orderType.AddStructuralProperty("ShippingAddress", shippingAddressReference); myModel.AddElement(orderType); EdmEntityType customer = new EdmEntityType("MyNS", "Customer"); customer.AddStructuralProperty("ContactName", EdmPrimitiveTypeKind.String); var customerId = customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); customer.AddKeys(customerId); customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, }); myModel.AddElement(customer); var productType = new EdmEntityType("MyNS", "Product"); var productId = productType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); productType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); productType.AddKeys(productId); myModel.AddElement(productType); var physicalProductType = new EdmEntityType("MyNS", "PhysicalProduct", productType); physicalProductType.AddStructuralProperty("Material", EdmPrimitiveTypeKind.String); myModel.AddElement(physicalProductType); var productDetailType = new EdmEntityType("MyNS", "ProductDetail"); var productDetailId = productDetailType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); productDetailType.AddStructuralProperty("Detail", EdmPrimitiveTypeKind.String); productDetailType.AddKeys(productDetailId); myModel.AddElement(productDetailType); var productDetailItemType = new EdmEntityType("MyNS", "ProductDetailItem"); var productDetailItemId = productDetailItemType.AddStructuralProperty("ItemId", EdmPrimitiveTypeKind.Int32); productDetailItemType.AddStructuralProperty("Description", EdmPrimitiveTypeKind.String); productDetailItemType.AddKeys(productDetailItemId); myModel.AddElement(productDetailItemType); productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Details", Target = productDetailType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true, }); productDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Items", Target = productDetailItemType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true, }); var favouriteProducts = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "FavouriteProducts", Target = productType, TargetMultiplicity = EdmMultiplicity.Many, }); var productBeingViewed = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ProductBeingViewed", Target = productType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); EdmEntityContainer container = new EdmEntityContainer("MyNS", "Example30"); var products = container.AddEntitySet("Products", productType); var customers = container.AddEntitySet("Customers", customer); customers.AddNavigationTarget(favouriteProducts, products); customers.AddNavigationTarget(productBeingViewed, products); container.AddEntitySet("Orders", orderType); myModel.AddElement(container); } return(myModel); }
private static IEdmModel GetModel() { var model = new EdmModel(); var entityType = new EdmEntityType("NS", "EntityType"); var id = entityType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); entityType.AddKeys(id); var derivedEntityType = new EdmEntityType("NS", "DerivedEntityType", entityType); var containedEntityType = new EdmEntityType("NS", "ContainedEntityType"); var containedId = containedEntityType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); containedEntityType.AddKeys(containedId); var containedNav1 = entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "ContainedNav1", Target = containedEntityType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }); var containedNav2 = entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "ContainedNav2", Target = containedEntityType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }); var navEntityType = new EdmEntityType("NS", "NavEntityType"); var navEntityId = navEntityType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); navEntityType.AddKeys(navEntityId); var nestedNavEntityType = new EdmEntityType("NS", "NestedNavEntityType"); var nestedId = nestedNavEntityType.AddStructuralProperty("NestedId", EdmCoreModel.Instance.GetString(false)); nestedNavEntityType.AddKeys(nestedId); var nestNav = navEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "NavNested", Target = nestedNavEntityType, TargetMultiplicity = EdmMultiplicity.One }); var complex = new EdmComplexType("NS", "ComplexType"); complex.AddStructuralProperty("Prop1", EdmCoreModel.Instance.GetString(false)); complex.AddStructuralProperty("CollectionComplexProp", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(complex, false)))); var derivedComplex = new EdmComplexType("NS", "DerivedComplexType", complex); derivedComplex.AddStructuralProperty("DerivedProp", EdmCoreModel.Instance.GetString(false)); var derivedNav = derivedEntityType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "NavOnDerived", Target = navEntityType, TargetMultiplicity = EdmMultiplicity.One, }); var complxNavP = complex.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "CollectionOfNavOnComplex", Target = navEntityType, TargetMultiplicity = EdmMultiplicity.Many, }); entityType.AddStructuralProperty("complexProp1", new EdmComplexTypeReference(complex, false)); entityType.AddStructuralProperty("complexProp2", new EdmComplexTypeReference(complex, false)); entityType.AddStructuralProperty("collectionComplex", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(complex, false)))); var navOnContained = containedEntityType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "NavOnContained", Target = navEntityType, TargetMultiplicity = EdmMultiplicity.One, }); var manyNavOnContained = containedEntityType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "ManyNavOnContained", Target = navEntityType, TargetMultiplicity = EdmMultiplicity.Many, }); model.AddElement(entityType); model.AddElement(derivedEntityType); model.AddElement(containedEntityType); model.AddElement(navEntityType); model.AddElement(nestedNavEntityType); model.AddElement(complex); model.AddElement(derivedComplex); var entityContainer = new EdmEntityContainer("NS", "Container"); model.AddElement(entityContainer); var entitySet = new EdmEntitySet(entityContainer, "EntitySet", entityType); var navEntitySet1 = new EdmEntitySet(entityContainer, "NavEntitySet1", navEntityType); var navEntitySet2 = new EdmEntitySet(entityContainer, "NavEntitySet2", navEntityType); var nestNavEntitySet = new EdmEntitySet(entityContainer, "NestedEntitySet", nestedNavEntityType); navEntitySet1.AddNavigationTarget(nestNav, nestNavEntitySet); navEntitySet2.AddNavigationTarget(nestNav, nestNavEntitySet); entitySet.AddNavigationTarget(derivedNav, navEntitySet1, new EdmPathExpression("NS.DerivedEntityType/NavOnDerived")); entitySet.AddNavigationTarget(complxNavP, navEntitySet1, new EdmPathExpression("complexProp1/CollectionOfNavOnComplex")); entitySet.AddNavigationTarget(complxNavP, navEntitySet2, new EdmPathExpression("complexProp2/CollectionOfNavOnComplex")); entitySet.AddNavigationTarget(navOnContained, navEntitySet1, new EdmPathExpression("ContainedNav1/NavOnContained")); entitySet.AddNavigationTarget(navOnContained, navEntitySet2, new EdmPathExpression("ContainedNav2/NavOnContained")); entitySet.AddNavigationTarget(manyNavOnContained, navEntitySet1, new EdmPathExpression("ContainedNav1/ManyNavOnContained")); entitySet.AddNavigationTarget(manyNavOnContained, navEntitySet2, new EdmPathExpression("ContainedNav2/ManyNavOnContained")); entitySet.AddNavigationTarget(complxNavP, navEntitySet2, new EdmPathExpression("collectionComplex/CollectionOfNavOnComplex")); entitySet.AddNavigationTarget(complxNavP, navEntitySet1, new EdmPathExpression("collectionComplex/CollectionComplexProp/CollectionOfNavOnComplex")); entityContainer.AddElement(entitySet); entityContainer.AddElement(navEntitySet1); entityContainer.AddElement(navEntitySet2); entityContainer.AddElement(nestNavEntitySet); return(model); }
public static TestModel Initialize() { EdmModel model = new EdmModel(); var result = new TestModel(model); var productType = new EdmEntityType("TestModel", "Product"); result.ProductType = productType; EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(idProperty); productType.AddKeys(idProperty); productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(productType); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default"); result.Container = defaultContainer; result.ProductsSet = defaultContainer.AddEntitySet("Products", productType); model.AddElement(defaultContainer); var derivedProductType = new EdmEntityType("TestModel", "DerivedProduct", productType); result.DerivedProductType = derivedProductType; EdmEntityType multipleKeyType = new EdmEntityType("TestModel", "MultipleKeyType"); result.MultipleKeyType = multipleKeyType; EdmStructuralProperty keyAProperty = new EdmStructuralProperty(multipleKeyType, "KeyA", EdmCoreModel.Instance.GetString(false)); EdmStructuralProperty keyBProperty = new EdmStructuralProperty(multipleKeyType, "KeyB", EdmCoreModel.Instance.GetInt32(false)); multipleKeyType.AddProperty(keyAProperty); multipleKeyType.AddProperty(keyBProperty); multipleKeyType.AddKeys(keyAProperty, keyBProperty); model.AddElement(multipleKeyType); result.MultipleKeysSet = defaultContainer.AddEntitySet("MultipleKeySet", multipleKeyType); EdmEntityType productTypeWithNavProps = new EdmEntityType("TestModel", "ProductWithNavProps", productType); result.ProductWithNavPropsType = productTypeWithNavProps; productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "RelatedProducts", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "RelatedDerivedProduct", Target = derivedProductType, TargetMultiplicity = EdmMultiplicity.One }); model.AddElement(productTypeWithNavProps); EdmAction action = new EdmAction("TestModel", "SimpleAction", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); model.AddElement(action); defaultContainer.AddActionImport("SimpleAction", action); EdmAction action1 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null); action1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddActionImport("SimpleFunctionWithOverload", action1); EdmAction action2 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null); action2.AddParameter("p1", EdmCoreModel.Instance.GetString(false)); defaultContainer.AddActionImport("SimpleFunctionWithOverload", action2); result.OneProductValue = BuildDefaultProductValue(productType); result.OneDerivedProductValue = BuildDefaultProductValue(derivedProductType); result.OneMultipleKeyValue = BuildDefaultMultipleKeyValue(model); result.OneProductWithNavPropsValue = BuildDefaultProductValue(productTypeWithNavProps); return(result); }
public void SetNavigationPropertyPartnerTypeHierarchyTest() { var model = new EdmModel(); var entityTypeA1 = new EdmEntityType("NS", "EntityTypeA1"); var entityTypeA2 = new EdmEntityType("NS", "EntityTypeA2", entityTypeA1); var entityTypeA3 = new EdmEntityType("NS", "EntityTypeA3", entityTypeA2); var entityTypeB = new EdmEntityType("NS", "EntityTypeB"); model.AddElements(new IEdmSchemaElement[] { entityTypeA1, entityTypeA2, entityTypeA3, entityTypeB }); entityTypeA1.AddKeys(entityTypeA1.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var a1Nav = entityTypeA1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "A1Nav", Target = entityTypeB, TargetMultiplicity = EdmMultiplicity.One }); var a3Nav = entityTypeA3.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "A3Nav", Target = entityTypeB, TargetMultiplicity = EdmMultiplicity.One }); entityTypeB.AddKeys(entityTypeB.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var bNav1 = entityTypeB.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BNav1", Target = entityTypeA2, TargetMultiplicity = EdmMultiplicity.One }); var bNav2 = entityTypeB.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BNav2", Target = entityTypeA3, TargetMultiplicity = EdmMultiplicity.One }); entityTypeA2.SetNavigationPropertyPartner(a1Nav, new EdmPathExpression("A1Nav"), bNav1, new EdmPathExpression("BNav1")); entityTypeA2.SetNavigationPropertyPartner(a3Nav, new EdmPathExpression("NS.EntityTypeA3/A3Nav"), bNav2, new EdmPathExpression("BNav2")); var str = GetCsdl(model, CsdlTarget.OData); Assert.Equal( "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" + "<edmx:DataServices>" + "<Schema Namespace=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" + "<EntityType Name=\"EntityTypeA1\">" + "<Key><PropertyRef Name=\"ID\" /></Key>" + "<Property Name=\"ID\" Type=\"Edm.Int32\" />" + "<NavigationProperty Name=\"A1Nav\" Type=\"NS.EntityTypeB\" Nullable=\"false\" Partner=\"BNav1\" />" + "</EntityType>" + "<EntityType Name=\"EntityTypeA2\" BaseType=\"NS.EntityTypeA1\" />" + "<EntityType Name=\"EntityTypeA3\" BaseType=\"NS.EntityTypeA2\">" + "<NavigationProperty Name=\"A3Nav\" Type=\"NS.EntityTypeB\" Nullable=\"false\" Partner=\"BNav2\" />" + "</EntityType>" + "<EntityType Name=\"EntityTypeB\">" + "<Key><PropertyRef Name=\"ID\" /></Key>" + "<Property Name=\"ID\" Type=\"Edm.Int32\" />" + "<NavigationProperty Name=\"BNav1\" Type=\"NS.EntityTypeA2\" Nullable=\"false\" Partner=\"A1Nav\" />" + "<NavigationProperty Name=\"BNav2\" Type=\"NS.EntityTypeA3\" Nullable=\"false\" Partner=\"NS.EntityTypeA3/A3Nav\" />" + "</EntityType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>", str); }
public void SetNavigationPropertyPartnerTest() { // build model var model = new EdmModel(); var entityType1 = new EdmEntityType("NS", "EntityType1"); var entityType2 = new EdmEntityType("NS", "EntityType2"); var entityType3 = new EdmEntityType("NS", "EntityType3", entityType2); var complexType1 = new EdmComplexType("NS", "ComplexType1"); var complexType2 = new EdmComplexType("NS", "ComplexType2"); model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType1, complexType2 }); entityType1.AddKeys(entityType1.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); entityType2.AddKeys(entityType2.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var outerNav1A = entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OuterNavA", Target = entityType2, TargetMultiplicity = EdmMultiplicity.One }); var outerNav2A = entityType2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OuterNavA", Target = entityType1, TargetMultiplicity = EdmMultiplicity.One }); entityType1.SetNavigationPropertyPartner( outerNav1A, new EdmPathExpression("OuterNavA"), outerNav2A, new EdmPathExpression("OuterNavA")); entityType1.AddStructuralProperty( "ComplexProp", new EdmCollectionTypeReference( new EdmCollectionType( new EdmComplexTypeReference(complexType1, false)))); entityType2.AddStructuralProperty("ComplexProp", new EdmComplexTypeReference(complexType2, false)); var innerNav1 = complexType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "InnerNav", Target = entityType2, TargetMultiplicity = EdmMultiplicity.One }); var innerNav2 = complexType2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "InnerNav", Target = entityType1, TargetMultiplicity = EdmMultiplicity.One }); var outerNav2B = entityType2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OuterNavB", Target = entityType1, TargetMultiplicity = EdmMultiplicity.One }); entityType2.SetNavigationPropertyPartner( outerNav2B, new EdmPathExpression("OuterNavB"), innerNav1, new EdmPathExpression("ComplexProp/InnerNav")); var outerNav2C = entityType3.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OuterNavC", Target = entityType1, TargetMultiplicity = EdmMultiplicity.Many }); var outerNav1B = entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OuterNavB", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many }); entityType1.SetNavigationPropertyPartner( outerNav1B, new EdmPathExpression("OuterNavB"), outerNav2C, new EdmPathExpression("NS.EntityType3/OuterNavC")); var str = GetCsdl(model, CsdlTarget.OData); Assert.Equal( "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + "<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">" + "<edmx:DataServices>" + "<Schema Namespace=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" + "<EntityType Name=\"EntityType1\">" + "<Key><PropertyRef Name=\"ID\" /></Key>" + "<Property Name=\"ID\" Type=\"Edm.Int32\" />" + "<Property Name=\"ComplexProp\" Type=\"Collection(NS.ComplexType1)\" Nullable=\"false\" />" + "<NavigationProperty Name=\"OuterNavA\" Type=\"NS.EntityType2\" Nullable=\"false\" Partner=\"OuterNavA\" />" + "<NavigationProperty Name=\"OuterNavB\" Type=\"Collection(NS.EntityType2)\" Partner=\"NS.EntityType3/OuterNavC\" />" + "</EntityType>" + "<EntityType Name=\"EntityType2\">" + "<Key><PropertyRef Name=\"ID\" /></Key>" + "<Property Name=\"ID\" Type=\"Edm.Int32\" />" + "<Property Name=\"ComplexProp\" Type=\"NS.ComplexType2\" Nullable=\"false\" />" + "<NavigationProperty Name=\"OuterNavA\" Type=\"NS.EntityType1\" Nullable=\"false\" Partner=\"OuterNavA\" />" + "<NavigationProperty Name=\"OuterNavB\" Type=\"NS.EntityType1\" Nullable=\"false\" Partner=\"ComplexProp/InnerNav\" />" + "</EntityType>" + "<EntityType Name=\"EntityType3\" BaseType=\"NS.EntityType2\">" + "<NavigationProperty Name=\"OuterNavC\" Type=\"Collection(NS.EntityType1)\" Partner=\"OuterNavB\" />" + "</EntityType>" + "<ComplexType Name=\"ComplexType1\">" + "<NavigationProperty Name=\"InnerNav\" Type=\"NS.EntityType2\" Nullable=\"false\" />" + "</ComplexType>" + "<ComplexType Name=\"ComplexType2\">" + "<NavigationProperty Name=\"InnerNav\" Type=\"NS.EntityType1\" Nullable=\"false\" />" + "</ComplexType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>", str); }
public void ContainedUnderComplexTest() { var model = new EdmModel(); var entity = new EdmEntityType("NS", "EntityType"); var entityId = entity.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); entity.AddKeys(entityId); var containedEntity = new EdmEntityType("NS", "ContainedEntityType"); var containedEntityId = containedEntity.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); containedEntity.AddKeys(containedEntityId); var complex = new EdmComplexType("NS", "ComplexType"); complex.AddStructuralProperty("Prop1", EdmCoreModel.Instance.GetInt32(false)); var containedUnderComplex = complex.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "ContainedUnderComplex", Target = containedEntity, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var navUnderContained = containedEntity.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "NavUnderContained", Target = entity, TargetMultiplicity = EdmMultiplicity.Many }); entity.AddStructuralProperty("Complex", new EdmComplexTypeReference(complex, false)); model.AddElement(entity); model.AddElement(containedEntity); model.AddElement(complex); var entityContainer = new EdmEntityContainer("NS", "Container"); model.AddElement(entityContainer); EdmEntitySet entites1 = new EdmEntitySet(entityContainer, "Entities1", entity); EdmEntitySet entites2 = new EdmEntitySet(entityContainer, "Entities2", entity); entites1.AddNavigationTarget(navUnderContained, entites2, new EdmPathExpression("Complex/ContainedUnderComplex/NavUnderContained")); entityContainer.AddElement(entites1); entityContainer.AddElement(entites2); string actual = GetCsdl(model, CsdlTarget.OData); var entitySet1 = model.EntityContainer.FindEntitySet("Entities1"); var entitySet2 = model.EntityContainer.FindEntitySet("Entities2"); var containedEntitySet = entitySet1.FindNavigationTarget(containedUnderComplex); Assert.Equal(containedEntitySet.Name, "ContainedUnderComplex"); var entitySetUnderContained = containedEntitySet.FindNavigationTarget(navUnderContained, new EdmPathExpression("Complex/ContainedUnderComplex/NavUnderContained")); Assert.Equal(entitySetUnderContained, entitySet2); }
private static EdmModel BuildEdmModel() { var model = new EdmModel(); var numberEntity = new EdmEntityType("NS", "Number"); numberEntity.AddKeys(numberEntity.AddStructuralProperty("RowId", EdmCoreModel.Instance.GetInt32(false))); numberEntity.AddStructuralProperty("RowParity", EdmCoreModel.Instance.GetString(false)); numberEntity.AddStructuralProperty("RowCategory", EdmCoreModel.Instance.GetString(false)); numberEntity.AddStructuralProperty("IntProp", EdmCoreModel.Instance.GetInt32(false)); numberEntity.AddStructuralProperty("NullableIntProp", EdmCoreModel.Instance.GetInt32(true)); numberEntity.AddStructuralProperty("DoubleProp", EdmCoreModel.Instance.GetDouble(false)); numberEntity.AddStructuralProperty("NullableDoubleProp", EdmCoreModel.Instance.GetDouble(true)); numberEntity.AddStructuralProperty("DecimalProp", EdmCoreModel.Instance.GetDecimal(false)); numberEntity.AddStructuralProperty("NullableDecimalProp", EdmCoreModel.Instance.GetDecimal(true)); numberEntity.AddStructuralProperty("LongProp", EdmCoreModel.Instance.GetInt64(false)); numberEntity.AddStructuralProperty("NullableLongProp", EdmCoreModel.Instance.GetInt64(true)); numberEntity.AddStructuralProperty("SingleProp", EdmCoreModel.Instance.GetSingle(false)); numberEntity.AddStructuralProperty("NullableSingleProp", EdmCoreModel.Instance.GetSingle(true)); var saleEntity = new EdmEntityType("NS", "Sale"); saleEntity.AddKeys(saleEntity.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false))); saleEntity.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetString(false)); saleEntity.AddStructuralProperty("Date", EdmCoreModel.Instance.GetString(false)); saleEntity.AddStructuralProperty("ProductId", EdmCoreModel.Instance.GetString(false)); saleEntity.AddStructuralProperty("CurrencyCode", EdmCoreModel.Instance.GetString(false)); saleEntity.AddStructuralProperty("Amount", EdmCoreModel.Instance.GetDecimal(false)); var productEntity = new EdmEntityType("NS", "Product"); productEntity.AddKeys(productEntity.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false))); productEntity.AddStructuralProperty("CategoryId", EdmCoreModel.Instance.GetString(false)); productEntity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); productEntity.AddStructuralProperty("Color", EdmCoreModel.Instance.GetString(false)); productEntity.AddStructuralProperty("TaxRate", EdmCoreModel.Instance.GetDecimal(false)); var customerEntity = new EdmEntityType("NS", "Customer"); customerEntity.AddKeys(customerEntity.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(false))); customerEntity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); customerEntity.AddStructuralProperty("Country", EdmCoreModel.Instance.GetString(false)); var categoryEntity = new EdmEntityType("NS", "Category"); categoryEntity.AddKeys(categoryEntity.AddStructuralProperty("Id", EdmCoreModel.Instance.GetString(false))); categoryEntity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); var currencyEntity = new EdmEntityType("NS", "Currency"); currencyEntity.AddKeys(currencyEntity.AddStructuralProperty("Code", EdmCoreModel.Instance.GetString(false))); currencyEntity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); // Associations saleEntity.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Customer", Target = customerEntity, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo { Name = "Sales", Target = saleEntity, TargetMultiplicity = EdmMultiplicity.Many }); saleEntity.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Product", Target = productEntity, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo { Name = "Sales", Target = saleEntity, TargetMultiplicity = EdmMultiplicity.Many }); saleEntity.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Currency", Target = currencyEntity, TargetMultiplicity = EdmMultiplicity.One }); productEntity.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Category", Target = categoryEntity, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo { Name = "Products", Target = productEntity, TargetMultiplicity = EdmMultiplicity.Many }); var entityContainer = new EdmEntityContainer("NS", "Container"); model.AddElement(numberEntity); model.AddElement(saleEntity); model.AddElement(productEntity); model.AddElement(customerEntity); model.AddElement(categoryEntity); model.AddElement(currencyEntity); model.AddElement(entityContainer); entityContainer.AddEntitySet(numbersEntitySetName, numberEntity); entityContainer.AddEntitySet(salesEntitySetName, saleEntity); entityContainer.AddEntitySet(productsEntitySetName, productEntity); return(model); }
private IEdmModel GetModel() { if (_model != null) { return(_model); } var model = new EdmModel(); // EntityContainer: Service var container = new EdmEntityContainer("ns", "Service"); model.AddElement(container); // EntityType: Address var address = new EdmEntityType("ns", "Address"); var addressId = address.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); address.AddKeys(addressId); model.AddElement(address); // EntitySet: Addresses var addresses = container.AddEntitySet("Addresses", address); // EntityType: PaymentInstrument var paymentInstrument = new EdmEntityType("ns", "PaymentInstrument"); var paymentInstrumentId = paymentInstrument.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); paymentInstrument.AddKeys(paymentInstrumentId); var billingAddresses = paymentInstrument.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BillingAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many }); paymentInstrument.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedBillingAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(paymentInstrument); // EntityType: Account var account = new EdmEntityType("ns", "Account"); var accountId = account.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); account.AddKeys(accountId); var myPaymentInstruments = account.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPaymentInstruments", Target = paymentInstrument, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(account); // EntitySet: Accounts var accounts = container.AddEntitySet("Accounts", account); var paymentInstruments = accounts.FindNavigationTarget(myPaymentInstruments) as EdmNavigationSource; Assert.NotNull(paymentInstruments); paymentInstruments.AddNavigationTarget(billingAddresses, addresses); // EntityType: Person var person = new EdmEntityType("ns", "Person"); var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); person.AddKeys(personId); var myAccounts = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyAccounts", Target = account, TargetMultiplicity = EdmMultiplicity.Many }); var myPermanentAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPermanentAccount", Target = account, TargetMultiplicity = EdmMultiplicity.One }); var myLatestAccount = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyLatestAccount", Target = account, TargetMultiplicity = EdmMultiplicity.One }); person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyAddresses", Target = address, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(person); // EntityType: Benefit var benefit = new EdmEntityType("ns", "Benefit"); var benefitId = benefit.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); benefit.AddKeys(benefitId); model.AddElement(benefit); // EntityType: SpecialPerson var specialPerson = new EdmEntityType("ns", "SpecialPerson", person); specialPerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Benefits", Target = benefit, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(specialPerson); // EntityType: VIP var vip = new EdmEntityType("ns", "VIP", specialPerson); vip.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyBenefits", Target = benefit, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(vip); // EntitySet: People var people = container.AddEntitySet("People", person); people.AddNavigationTarget(myAccounts, accounts); people.AddNavigationTarget(myLatestAccount, accounts); // EntityType: Club var club = new EdmEntityType("ns", "Club"); var clubId = club.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); club.AddKeys(clubId); var members = club.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Members", Target = person, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); // EntityType: SeniorClub var seniorClub = new EdmEntityType("ns", "SeniorClub", club); model.AddElement(seniorClub); // EntitySet: Clubs var clubs = container.AddEntitySet("Clubs", club); var membersInClub = clubs.FindNavigationTarget(members) as EdmNavigationSource; membersInClub.AddNavigationTarget(myAccounts, accounts); // Singleton: PermanentAccount var permanentAccount = container.AddSingleton("PermanentAccount", account); people.AddNavigationTarget(myPermanentAccount, permanentAccount); _model = model; return(_model); }
/// <summary> /// Build a test model shared across several tests. /// </summary> /// <returns>Returns the test model.</returns> public static EdmModel BuildTestModel() { // The metadata model var model = new EdmModel(); var addressType = new EdmComplexType(DefaultNamespaceName, "Address"); addressType.AddStructuralProperty("Street", StringNullableTypeRef); addressType.AddStructuralProperty("Zip", Int32TypeRef); addressType.AddStructuralProperty("SubAddress", new EdmComplexTypeReference(addressType, isNullable: false)); model.AddElement(addressType); var officeType = new EdmEntityType(DefaultNamespaceName, "OfficeType"); officeType.AddKeys(officeType.AddStructuralProperty("Id", Int32TypeRef)); officeType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, isNullable: false)); model.AddElement(officeType); var officeWithNumberType = new EdmEntityType(DefaultNamespaceName, "OfficeWithNumberType", officeType); officeWithNumberType.AddStructuralProperty("Number", Int32TypeRef); model.AddElement(officeWithNumberType); var cityType = new EdmEntityType(DefaultNamespaceName, "CityType"); cityType.AddKeys(cityType.AddStructuralProperty("Id", Int32TypeRef)); cityType.AddStructuralProperty("Name", StringNullableTypeRef); cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CityHall", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many }); cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DOL", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many }); cityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "PoliceStation", Target = officeType, TargetMultiplicity = EdmMultiplicity.One }); cityType.AddStructuralProperty("Skyline", EdmPrimitiveTypeKind.Stream, isNullable: false); cityType.AddStructuralProperty("MetroLanes", EdmCoreModel.GetCollection(StringNullableTypeRef)); model.AddElement(cityType); var metropolitanCityType = new EdmEntityType(DefaultNamespaceName, "MetropolitanCityType", cityType); metropolitanCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedOffice", Target = officeType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); officeType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ContainedCity", Target = metropolitanCityType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }); model.AddElement(metropolitanCityType); var cityWithMapType = new EdmEntityType(DefaultNamespaceName, "CityWithMapType", cityType, false, false, true); model.AddElement(cityWithMapType); var cityOpenType = new EdmEntityType(DefaultNamespaceName, "CityOpenType", cityType, isAbstract: false, isOpen: true); model.AddElement(cityOpenType); var personType = new EdmEntityType(DefaultNamespaceName, "Person"); personType.AddKeys(personType.AddStructuralProperty("Id", Int32TypeRef)); personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Friend", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(personType); var employeeType = new EdmEntityType(DefaultNamespaceName, "Employee", personType); employeeType.AddStructuralProperty("CompanyName", StringNullableTypeRef); model.AddElement(employeeType); var managerType = new EdmEntityType(DefaultNamespaceName, "Manager", employeeType); managerType.AddStructuralProperty("Level", Int32TypeRef); model.AddElement(managerType); var container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer"); model.AddElement(container); container.AddEntitySet("Offices", officeType); container.AddEntitySet("Cities", cityType); container.AddEntitySet("MetropolitanCities", metropolitanCityType); container.AddEntitySet("Persons", personType); container.AddEntitySet("Employee", employeeType); container.AddEntitySet("Manager", managerType); container.AddSingleton("Boss", personType); // Fixup will set DefaultContainer\TopLevelEntitySet\AssociationSet model.Fixup(); // NOTE: Function import parameters and return types must be nullable as per current CSDL spec var serviceOp = container.AddFunctionAndFunctionImport(model, "ServiceOperation1", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); serviceOp.Function.AsEdmFunction().AddParameter("a", Int32NullableTypeRef); serviceOp.Function.AsEdmFunction().AddParameter("b", StringNullableTypeRef); container.AddFunctionAndFunctionImport(model, "PrimitiveResultOperation", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); container.AddFunctionAndFunctionImport(model, "ComplexResultOperation", new EdmComplexTypeReference(addressType, isNullable: true), null, false /*isComposable*/, false /*isBound*/); container.AddFunctionAndFunctionImport(model, "PrimitiveCollectionResultOperation", EdmCoreModel.GetCollection(Int32NullableTypeRef), null, false /*isComposable*/, false /*isBound*/); container.AddFunctionAndFunctionImport(model, "ComplexCollectionResultOperation", EdmCoreModel.GetCollection(new EdmComplexTypeReference(addressType, isNullable: true)), null, false /*isComposable*/, false /*isBound*/); // Overload with 0 Param container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); // Overload with 1 Param var overloadWithOneParam = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); overloadWithOneParam.Function.AsEdmFunction().AddParameter("p1", new EdmEntityTypeReference(cityWithMapType, isNullable: true)); // Overload with 2 Params var overloadWithTwoParams = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); overloadWithTwoParams.Function.AsEdmFunction().AddParameter("p1", new EdmEntityTypeReference(cityType, isNullable: true)); overloadWithTwoParams.Function.AsEdmFunction().AddParameter("p2", StringNullableTypeRef); // Overload with 5 Params var overloadWithFiveParams = container.AddFunctionAndFunctionImport(model, "FunctionImportWithOverload", Int32NullableTypeRef, null, false /*isComposable*/, false /*isBound*/); overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p1", EdmCoreModel.GetCollection(new EdmEntityTypeReference(cityType, isNullable: true))); overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p2", EdmCoreModel.GetCollection(StringNullableTypeRef)); overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p3", StringNullableTypeRef); overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p4", new EdmComplexTypeReference(addressType, isNullable: true)); overloadWithFiveParams.Function.AsEdmFunction().AddParameter("p5", EdmCoreModel.GetCollection(new EdmComplexTypeReference(addressType, isNullable: true))); return(model); }
public static IEdmModel SimpleCustomerOrderModel() { var model = new EdmModel(); var customerType = new EdmEntityType("Default", "Customer"); customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); customerType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String); customerType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( EdmPrimitiveTypeKind.String, isNullable: true); customerType.AddStructuralProperty( "City", primitiveTypeReference, defaultValue: null, concurrencyMode: EdmConcurrencyMode.Fixed); model.AddElement(customerType); var specialCustomerType = new EdmEntityType("Default", "SpecialCustomer", customerType); model.AddElement(specialCustomerType); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); orderType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); orderType.AddStructuralProperty("Shipment", EdmPrimitiveTypeKind.String); model.AddElement(orderType); var specialOrderType = new EdmEntityType("Default", "SpecialOrder", orderType); model.AddElement(specialOrderType); var addressType = new EdmComplexType("Default", "Address"); addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); addressType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); model.AddElement(addressType); // Add navigations customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many }); orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); specialCustomerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "SpecialOrders", Target = specialOrderType, TargetMultiplicity = EdmMultiplicity.Many }); orderType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "SpecialCustomer", Target = specialCustomerType, TargetMultiplicity = EdmMultiplicity.One }); // Add Entity set var container = new EdmEntityContainer("Default", "Container"); var customerSet = container.AddEntitySet("Customers", customerType); var orderSet = container.AddEntitySet("Orders", orderType); customerSet.AddNavigationTarget(customerType.NavigationProperties().Single(np => np.Name == "Orders"), orderSet); customerSet.AddNavigationTarget( specialCustomerType.NavigationProperties().Single(np => np.Name == "SpecialOrders"), orderSet); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); orderSet.AddNavigationTarget( specialOrderType.NavigationProperties().Single(np => np.Name == "SpecialCustomer"), customerSet); NavigationSourceLinkBuilderAnnotation linkAnnotation = new MockNavigationSourceLinkBuilderAnnotation(); model.SetNavigationSourceLinkBuilder(customerSet, linkAnnotation); model.SetNavigationSourceLinkBuilder(orderSet, linkAnnotation); model.AddElement(container); return(model); }
private IEdmModel CreateEdmModel() { var model = new EdmModel(); EdmComplexType simpleComplexType = new EdmComplexType(DefaultNamespaceName, "SimplexComplexType"); simpleComplexType.AddProperty(new EdmStructuralProperty(simpleComplexType, "Name", StringTypeRef)); model.AddElement(simpleComplexType); EdmComplexType simpleComplexType2 = new EdmComplexType(DefaultNamespaceName, "SimplexComplexType2"); simpleComplexType2.AddProperty(new EdmStructuralProperty(simpleComplexType2, "Value", Int32NullableTypeRef)); model.AddElement(simpleComplexType2); EdmComplexType nestedComplexType = new EdmComplexType(DefaultNamespaceName, "NestedComplexType"); nestedComplexType.AddProperty(new EdmStructuralProperty(nestedComplexType, "InnerComplexProperty", new EdmComplexTypeReference(simpleComplexType2, isNullable: false))); model.AddElement(nestedComplexType); EdmComplexType ratingComplexType = new EdmComplexType(DefaultNamespaceName, "RatingComplexType"); ratingComplexType.AddProperty(new EdmStructuralProperty(ratingComplexType, "Rating", Int32NullableTypeRef)); model.AddElement(ratingComplexType); EdmEntityType entityType = new EdmEntityType(DefaultNamespaceName, "EntityType"); EdmEntityType expandedEntryType = new EdmEntityType(DefaultNamespaceName, "ExpandedEntryType"); expandedEntryType.AddKeys(expandedEntryType.AddStructuralProperty("Id", Int32TypeRef)); expandedEntryType.AddStructuralProperty("ExpandedEntryName", StringTypeRef); expandedEntryType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ExpandedEntry_DeferredNavigation", Target = entityType, TargetMultiplicity = EdmMultiplicity.One }); expandedEntryType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ExpandedEntry_ExpandedFeed", Target = entityType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(expandedEntryType); entityType.AddKeys(entityType.AddStructuralProperty("Id", Int32TypeRef)); entityType.AddStructuralProperty("StringProperty", StringTypeRef); entityType.AddStructuralProperty("NumberProperty", Int32TypeRef); entityType.AddStructuralProperty("SimpleComplexProperty", new EdmComplexTypeReference(simpleComplexType, isNullable: false)); entityType.AddStructuralProperty("DeepComplexProperty", new EdmComplexTypeReference(nestedComplexType, isNullable: false)); entityType.AddStructuralProperty("PrimitiveCollection", EdmCoreModel.GetCollection(StringTypeRef)); entityType.AddStructuralProperty("ComplexCollection", EdmCoreModel.GetCollection(new EdmComplexTypeReference(ratingComplexType, isNullable: false))); entityType.AddStructuralProperty("NamedStream", EdmPrimitiveTypeKind.Stream, false); entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DeferredNavigation", Target = entityType, TargetMultiplicity = EdmMultiplicity.One }); entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "AssociationLink", Target = entityType, TargetMultiplicity = EdmMultiplicity.One }); entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ExpandedEntry", Target = expandedEntryType, TargetMultiplicity = EdmMultiplicity.One }); entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ExpandedFeed", Target = entityType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(entityType); EdmEntityType wrappingEntityType = new EdmEntityType(DefaultNamespaceName, "WrappingEntityType"); wrappingEntityType.AddKeys(wrappingEntityType.AddStructuralProperty("Wrapping_ID", Int32TypeRef)); wrappingEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Wrapping_ExpandedEntry", Target = entityType, TargetMultiplicity = EdmMultiplicity.One }); model.AddElement(wrappingEntityType); var container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer"); model.AddElement(container); container.AddEntitySet("EntitySet", entityType); container.AddEntitySet("WrappingEntitySet", wrappingEntityType); return(model); }
public SelectedPropertiesNodeTests() { 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); EdmComplexType airportType = new EdmComplexType("TestModel", "Airport"); airportType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/ false)); airportType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.edmModel.AddElement(airportType); EdmComplexType regionalAirportType = new EdmComplexType("TestModel", "RegionalAirport", airportType); airportType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Region", Target = districtType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.edmModel.AddElement(regionalAirportType); this.metropolisType = new EdmEntityType("TestModel", "Metropolis", this.cityType); this.metropolisType.AddStructuralProperty("MetropolisStream", EdmCoreModel.Instance.GetStream(/*isNullable*/ false)); this.metropolisType.AddStructuralProperty("NearestAirport", new EdmComplexTypeReference(airportType, 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); }
private IEdmNavigationProperty AddToSourceEdmType(EdmEntityType sourceEdmEntityType) { return(sourceEdmEntityType.AddUnidirectionalNavigation(this.CreateNavigationPropertyInfo())); }
public void AssociationLinkTest() { string associationLinkName1 = "AssociationLinkOne"; string linkUrl1 = "http://odata.org/associationlink"; Uri linkUrlUri1 = new Uri(linkUrl1); string associationLinkName2 = "AssociationLinkTwo"; string linkUrl2 = "http://odata.org/associationlink2"; Uri linkUrlUri2 = new Uri(linkUrl2); EdmModel model = new EdmModel(); var edmEntityTypeOrderType = new EdmEntityType("TestModel", "OrderType"); model.AddElement(edmEntityTypeOrderType); var edmEntityTypeCustomerType = new EdmEntityType("TestModel", "CustomerType"); var edmNavigationPropertyAssociationLinkOne = edmEntityTypeCustomerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = associationLinkName1, Target = edmEntityTypeOrderType, TargetMultiplicity = EdmMultiplicity.One }); var edmNavigationPropertyAssociationLinkTwo = edmEntityTypeCustomerType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = associationLinkName2, Target = edmEntityTypeOrderType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(edmEntityTypeCustomerType); var container = new EdmEntityContainer("TestModel", "Default"); model.AddElement(container); var customerSet = container.AddEntitySet("Customers", edmEntityTypeCustomerType); var orderSet = container.AddEntitySet("Orders", edmEntityTypeOrderType); customerSet.AddNavigationTarget(edmNavigationPropertyAssociationLinkOne, orderSet); customerSet.AddNavigationTarget(edmNavigationPropertyAssociationLinkTwo, orderSet); var testCases = new[] { new { NavigationLink = ObjectModelUtils.CreateDefaultNavigationLink(associationLinkName1, linkUrlUri1), Atom = BuildXmlAssociationLink(associationLinkName1, "application/xml", linkUrl1), JsonLight = (string)null, }, new { NavigationLink = ObjectModelUtils.CreateDefaultNavigationLink(associationLinkName2, linkUrlUri2), Atom = BuildXmlAssociationLink(associationLinkName2, "application/xml", linkUrl2), JsonLight = (string)null }, }; var testCasesWithMultipleLinks = testCases.Variations() .Select(tcs => new { NavigationLinks = tcs.Select(tc => tc.NavigationLink), Atom = string.Concat(tcs.Select(tc => tc.Atom)), JsonLight = string.Join(",", tcs.Where(tc => tc.JsonLight != null).Select(tc => tc.JsonLight)) }); var testDescriptors = testCasesWithMultipleLinks.Select(testCase => { ODataResource entry = ObjectModelUtils.CreateDefaultEntry(); entry.TypeName = "TestModel.CustomerType"; List <ODataItem> items = new ODataItem[] { entry }.ToList(); foreach (var navLink in testCase.NavigationLinks) { items.Add(navLink); items.Add(null); } return(new PayloadWriterTestDescriptor <ODataItem>( this.Settings, items, (testConfiguration) => { var firstAssocLink = testCase.NavigationLinks == null ? null : testCase.NavigationLinks.FirstOrDefault(); if (testConfiguration.Format == ODataFormat.Json) { return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings) { Json = string.Join( "$(NL)", "{", testCase.JsonLight, "}"), FragmentExtractor = (result) => { var associationLinks = result.Object().GetAnnotationsWithName("@" + JsonLightConstants.ODataAssociationLinkUrlAnnotationName).ToList(); var jsonResult = new JsonObject(); associationLinks.ForEach(l => { // NOTE we remove all annoatations here and in particular the text annotations to be able to easily compare // against the expected results. This however means that we do not distinguish between the indented and non-indented case here. l.RemoveAllAnnotations(true); jsonResult.Add(l); }); return jsonResult; }, }; } else { this.Settings.Assert.Fail("Unknown format '{0}'.", testConfiguration.Format); return null; } }) { Model = model, PayloadEdmElementContainer = customerSet }); }); // With and without model testDescriptors = testDescriptors.SelectMany(td => new[] { td, new PayloadWriterTestDescriptor <ODataItem>(td) { Model = null, PayloadEdmElementContainer = null } }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors.PayloadCases(WriterPayloads.EntryPayloads), this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); if (testDescriptor.Model == null && testConfiguration.Format == ODataFormat.Json) { return; } if (testDescriptor.IsGeneratedPayload && testDescriptor.Model != null) { return; } TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
private static IEdmModel CreateMultipleInheritanceEdmModel() { var model = new EdmModel(); // enum type var colorEnumType = new EdmEnumType("NS", "Color"); colorEnumType.AddMember("Blue", new EdmEnumMemberValue(0)); colorEnumType.AddMember("While", new EdmEnumMemberValue(1)); colorEnumType.AddMember("Red", new EdmEnumMemberValue(2)); colorEnumType.AddMember("Yellow", new EdmEnumMemberValue(3)); model.AddElement(colorEnumType); var oceanEnumType = new EdmEnumType("NS", "Ocean"); oceanEnumType.AddMember("Atlantic", new EdmEnumMemberValue(0)); oceanEnumType.AddMember("Pacific", new EdmEnumMemberValue(1)); oceanEnumType.AddMember("India", new EdmEnumMemberValue(2)); oceanEnumType.AddMember("Arctic", new EdmEnumMemberValue(3)); model.AddElement(oceanEnumType); var continentEnumType = new EdmEnumType("NS", "Continent"); continentEnumType.AddMember("Asia", new EdmEnumMemberValue(0)); continentEnumType.AddMember("Europe", new EdmEnumMemberValue(1)); continentEnumType.AddMember("Antarctica", new EdmEnumMemberValue(2)); model.AddElement(continentEnumType); // top level entity type var zoo = new EdmEntityType("NS", "Zoo"); var zooId = zoo.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); zoo.AddKeys(zooId); model.AddElement(zoo); // abstract entity type "Creature" var creature = new EdmEntityType("NS", "Creature", null, true, true); creature.AddKeys(creature.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(creature); var animal = new EdmEntityType("NS", "Animal", creature, true, true); animal.AddStructuralProperty("Age", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(animal); var human = new EdmEntityType("NS", "Human", animal, false, true); human.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.AddElement(human); var horse = new EdmEntityType("NS", "Horse", animal, false, true); horse.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDecimal(false)); model.AddElement(horse); EdmNavigationPropertyInfo navInfo = new EdmNavigationPropertyInfo { Name = "Creatures", Target = creature, TargetMultiplicity = EdmMultiplicity.Many, }; zoo.AddUnidirectionalNavigation(navInfo); // complex type var plant = new EdmComplexType("NS", "Plant", null, true, true); plant.AddStructuralProperty("Color", new EdmEnumTypeReference(colorEnumType, isNullable: false)); model.AddElement(plant); // ocean plant var oceanPlant = new EdmComplexType("NS", "OceanPlant", plant, true, true); oceanPlant.AddStructuralProperty("Ocean", new EdmEnumTypeReference(oceanEnumType, isNullable: false)); model.AddElement(oceanPlant); var kelp = new EdmComplexType("NS", "Kelp", oceanPlant, false, true); kelp.AddStructuralProperty("Length", EdmCoreModel.Instance.GetDouble(false)); model.AddElement(kelp); // land plant var landPlant = new EdmComplexType("NS", "LandPlant", plant, true, true); landPlant.AddStructuralProperty("Continent", new EdmEnumTypeReference(continentEnumType, isNullable: false)); landPlant.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false)); model.AddElement(landPlant); var tree = new EdmComplexType("NS", "Tree", landPlant, false, true); tree.AddStructuralProperty("Price", EdmCoreModel.Instance.GetDecimal(false)); model.AddElement(tree); var flower = new EdmComplexType("NS", "Flower", landPlant, false, true); flower.AddStructuralProperty("Height", EdmCoreModel.Instance.GetDouble(false)); model.AddElement(flower); // address var address = new EdmComplexType("NS", "Address"); address.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true)); address.AddStructuralProperty("City", EdmCoreModel.Instance.GetString(true)); model.AddElement(address); var coreDescription = CoreVocabularyModel.DescriptionTerm; var annotation = new EdmVocabularyAnnotation(address, coreDescription, new EdmStringConstant("Complex type 'Address' description.")); model.AddVocabularyAnnotation(annotation); annotation = new EdmVocabularyAnnotation(tree, coreDescription, new EdmStringConstant("Complex type 'Tree' description.")); model.AddVocabularyAnnotation(annotation); annotation = new EdmVocabularyAnnotation(zoo, coreDescription, new EdmStringConstant("Entity type 'Zoo' description.")); model.AddVocabularyAnnotation(annotation); annotation = new EdmVocabularyAnnotation(human, coreDescription, new EdmStringConstant("Entity type 'Human' description.")); model.AddVocabularyAnnotation(annotation); return(model); }
public CustomersModelWithInheritance() { EdmModel model = new EdmModel(); // complex type address EdmComplexType address = new EdmComplexType("NS", "Address"); address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("State", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); model.AddElement(address); // entity type customer EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true)); customer.AddStructuralProperty("City", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, true), defaultValue: null, concurrencyMode: EdmConcurrencyMode.Fixed); model.AddElement(customer); // derived entity type special customer EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer); specialCustomer.AddStructuralProperty("SpecialCustomerProperty", EdmPrimitiveTypeKind.Guid); model.AddElement(specialCustomer); // entity type order EdmEntityType order = new EdmEntityType("NS", "Order"); order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32); model.AddElement(order); // derived entity type special order EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order); specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid); model.AddElement(specialOrder); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance"); model.AddElement(container); EdmEntitySet customers = container.AddEntitySet("Customers", customer); EdmEntitySet orders = container.AddEntitySet("Orders", order); // actions EdmFunctionImport upgradeCustomer = container.AddFunctionImport( "upgrade", returnType: null, entitySet: new EdmEntitySetReferenceExpression(customers), sideEffecting: true, composable: false, bindable: true); upgradeCustomer.AddParameter("entity", new EdmEntityTypeReference(customer, false)); EdmFunctionImport upgradeSpecialCustomer = container.AddFunctionImport( "specialUpgrade", returnType: null, entitySet: new EdmEntitySetReferenceExpression(customers), sideEffecting: true, composable: false, bindable: true); upgradeSpecialCustomer.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false)); // navigation properties customers.AddNavigationTarget( customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }), orders); orders.AddNavigationTarget( order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = customer }), customers); // navigation properties on derived types. customers.AddNavigationTarget( specialCustomer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "SpecialOrders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }), orders); orders.AddNavigationTarget( specialOrder.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "SpecialCustomer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = customer }), customers); model.SetAnnotationValue <BindableProcedureFinder>(model, new BindableProcedureFinder(model)); // set properties Model = model; Container = container; Customer = customer; Order = order; Address = address; SpecialCustomer = specialCustomer; SpecialOrder = specialOrder; Orders = orders; Customers = customers; UpgradeCustomer = upgradeCustomer; UpgradeSpecialCustomer = upgradeSpecialCustomer; }
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 ODataResource(); entry1.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, }; var entry2 = new ODataResource(); 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.CreateResourceSetWriter("feed"); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry1); entryWriter.WriteStart(new ODataNestedResourceInfo() { Name = "Property1", IsCollection = true }); entryWriter.WriteStart(new ODataResourceSet()); 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); }