public static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); // Create and add product entity type. EdmEntityType product = new EdmEntityType("NS", "Product"); product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double); model.AddElement(product); // Create and add category entity type. EdmEntityType category = new EdmEntityType("NS", "Category"); category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(category); // Set navigation from product to category. EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Category"; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; propertyInfo.Target = category; EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo); // Create and add entity container. EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); // Create and add entity set for product and category. EdmEntitySet products = container.AddEntitySet("Products", product); EdmEntitySet categories = container.AddEntitySet("Categories", category); products.AddNavigationTarget(productCategory, categories); return model; }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType student = new EdmEntityType("ns", "Student"); student.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = student.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); student.AddKeys(key); model.AddElement(student); EdmEntitySet students = container.AddEntitySet("Students", student); EdmEntityType school = new EdmEntityType("ns", "School"); school.AddKeys(school.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); school.AddStructuralProperty("CreatedDay", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(school); EdmEntitySet schools = container.AddEntitySet("Schools", student); EdmNavigationProperty schoolNavProp = student.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "School", TargetMultiplicity = EdmMultiplicity.One, Target = school }); students.AddNavigationTarget(schoolNavProp, schools); _school = school; }
public static IEdmModel GetEdmModel() { if (_edmModel != null) { return _edmModel; } EdmModel model = new EdmModel(); // entity type 'Customer' with single alternate keys EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var ssn = customer.AddStructuralProperty("SSN", EdmPrimitiveTypeKind.String); model.AddAlternateKeyAnnotation(customer, new Dictionary<string, IEdmProperty> { {"SSN", ssn} }); model.AddElement(customer); // entity type 'Order' with multiple alternate keys EdmEntityType order = new EdmEntityType("NS", "Order"); order.AddKeys(order.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32)); var orderName = order.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var orderToken = order.AddStructuralProperty("Token", EdmPrimitiveTypeKind.Guid); order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32); model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty> { {"Name", orderName} }); model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty> { {"Token", orderToken} }); model.AddElement(order); // entity type 'Person' with composed alternate keys EdmEntityType person = new EdmEntityType("NS", "Person"); person.AddKeys(person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var country = person.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); var passport = person.AddStructuralProperty("Passport", EdmPrimitiveTypeKind.String); model.AddAlternateKeyAnnotation(person, new Dictionary<string, IEdmProperty> { {"Country", country}, {"Passport", passport} }); model.AddElement(person); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); model.AddElement(container); container.AddEntitySet("Customers", customer); container.AddEntitySet("Orders", order); container.AddEntitySet("People", person); return _edmModel = model; }
private static EdmModel CreateTestModel() { var objectType = new EdmEntityType("DefaultNamespace", "Object"); var personType = new EdmEntityType("DefaultNamespace", "Person", objectType); var container = new EdmEntityContainer("DefaultNamespace", "Container"); container.AddEntitySet("Objects", objectType); container.AddEntitySet("People", personType); var model = new EdmModel(); model.AddElement(objectType); model.AddElement(personType); model.AddElement(container); return model; }
static ExapndOptionFunctionalTests() { string namespaceA = "NS"; EdmModel edmModel = new EdmModel(); EdmEntityType type1 = new EdmEntityType(namespaceA, "T1"); EdmEntityType type2 = new EdmEntityType(namespaceA, "T2", type1); EdmEntityType type3 = new EdmEntityType(namespaceA, "T3", type2); EdmNavigationProperty nav21 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav21", ContainsTarget = false, Target = type1, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); EdmNavigationProperty nav22 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav22", ContainsTarget = false, Target = type2, TargetMultiplicity = EdmMultiplicity.One, }); EdmNavigationProperty nav23 = type2.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav23", ContainsTarget = false, Target = type3, TargetMultiplicity = EdmMultiplicity.Many, }); edmModel.AddElement(type1); edmModel.AddElement(type2); edmModel.AddElement(type3); EdmEntityContainer container = new EdmEntityContainer(namespaceA, "Con1"); var set1 = container.AddEntitySet(namespaceA, type1); var set2 = container.AddEntitySet(namespaceA, type2); var set3 = container.AddEntitySet(namespaceA, type3); edmModel.AddElement(container); set2.AddNavigationTarget(nav21, set1); set2.AddNavigationTarget(nav22, set2); set2.AddNavigationTarget(nav23, set3); Model = edmModel; T2Type = type2; T3Type = type3; T2Set = set2; T3Set = set3; }
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 orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); orderType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); orderType.AddStructuralProperty("Shipment", EdmPrimitiveTypeKind.String); model.AddElement(orderType); 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 }); // 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); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); NavigationSourceLinkBuilderAnnotation linkAnnotation = new MockNavigationSourceLinkBuilderAnnotation(); model.SetNavigationSourceLinkBuilder(customerSet, linkAnnotation); model.SetNavigationSourceLinkBuilder(orderSet, linkAnnotation); model.AddElement(container); return model; }
public WriterTypeNameEndToEndTests() { var model = new EdmModel(); var type = new EdmEntityType("TestModel", "TestEntity", /* baseType */ null, /* isAbstract */ false, /* isOpen */ true); var keyProperty = type.AddStructuralProperty("DeclaredInt16", EdmPrimitiveTypeKind.Int16); type.AddKeys(new[] { keyProperty }); // Note: DerivedPrimitive is declared as a Geography, but its value below will be set to GeographyPoint, which is derived from Geography. type.AddStructuralProperty("DerivedPrimitive", EdmPrimitiveTypeKind.Geography); var container = new EdmEntityContainer("TestModel", "Container"); var set = container.AddEntitySet("Set", type); model.AddElement(type); model.AddElement(container); var writerStream = new MemoryStream(); this.settings = new ODataMessageWriterSettings(); this.settings.SetServiceDocumentUri(ServiceDocumentUri); // Make the message writer and entry writer lazy so that individual tests can tweak the settings before the message writer is created. this.messageWriter = new Lazy<ODataMessageWriter>(() => new ODataMessageWriter( (IODataResponseMessage)new InMemoryMessage { Stream = writerStream }, this.settings, model)); var entryWriter = new Lazy<ODataWriter>(() => this.messageWriter.Value.CreateODataEntryWriter(set, type)); var valueWithAnnotation = new ODataPrimitiveValue(45); valueWithAnnotation.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = "TypeNameFromSTNA" }); var propertiesToWrite = new List<ODataProperty> { new ODataProperty { Name = "DeclaredInt16", Value = (Int16)42 }, new ODataProperty { Name = "UndeclaredDecimal", Value = (Decimal)4.5 }, new ODataProperty { // Note: value is more derived than the declared type. Name = "DerivedPrimitive", Value = Microsoft.Spatial.GeographyPoint.Create(42, 45) }, new ODataProperty() { Name = "PropertyWithSTNA", Value = valueWithAnnotation } }; this.writerOutput = new Lazy<string>(() => { entryWriter.Value.WriteStart(new ODataEntry { Properties = propertiesToWrite }); entryWriter.Value.WriteEnd(); entryWriter.Value.Flush(); writerStream.Seek(0, SeekOrigin.Begin); return new StreamReader(writerStream).ReadToEnd(); }); }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType product = new EdmEntityType("ns", "Student"); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = product.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); product.AddKeys(key); model.AddElement(product); container.AddEntitySet("Students", product); }
public JsonLightTypeResolverTests() { this.serverModel = new EdmModel(); var serverEntityType = new EdmEntityType("Server.Name.Space", "EntityType"); serverEntityType.AddKeys(serverEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var parentType = new EdmEntityType("Server.Name.Space", "Parent"); this.serverModel.AddElement(serverEntityType); this.serverModel.AddElement(parentType); var serverComplexType = new EdmComplexType("Server.Name.Space", "ComplexType"); serverComplexType.AddStructuralProperty("Number", EdmPrimitiveTypeKind.Int32); this.serverModel.AddElement(serverComplexType); var entityContainer = new EdmEntityContainer("Fake", "Container"); this.serverModel.AddElement(entityContainer); entityContainer.AddEntitySet("Entities", serverEntityType); entityContainer.AddEntitySet("Parents", parentType); parentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverEntityType, TargetMultiplicity = EdmMultiplicity.Many }); }
private void BuildEntitySets(EdmEntityContainer container, IEnumerable<EntityElement> rootElements, TypeBuilder typeBuilder) { foreach (var rootEntity in rootElements) { var entitySetName = rootEntity.EntitySetName ?? rootEntity.ResolveName(); var schemaType = typeBuilder.BuildSchemaType(rootEntity); container.AddEntitySet(entitySetName, (IEdmEntityType)schemaType); } }
static ODataJsonLightReaderIntegrationTests() { EdmModel tmp = new EdmModel(); EntityType = new EdmEntityType("Namespace", "EntityType"); EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub"); EntitySet = edmEntityContainer.AddEntitySet("EntitySet", EntityType); tmp.AddElement(edmEntityContainer); tmp.Fixup(); Model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp); }
public Task<IEdmModel> GetModelAsync(InvocationContext context, CancellationToken cancellationToken) { var model = new EdmModel(); var dummyType = new EdmEntityType("NS", "Dummy"); model.AddElement(dummyType); var container = new EdmEntityContainer("NS", "DefaultContainer"); container.AddEntitySet("Test", dummyType); model.AddElement(container); return Task.FromResult((IEdmModel)model); }
static ODataAtomWriterIntegrationTests() { Model = new EdmModel(); EntityType = new EdmEntityType("Namespace", "EntityType"); Model.AddElement(EntityType); var entityContainer = new EdmEntityContainer("Namespace", "Container"); EntitySet = entityContainer.AddEntitySet("EntitySet", EntityType); Model.AddElement(entityContainer); Model.Fixup(); }
public void Initialize() { EdmModel tmp = new EdmModel(); this.type = new EdmEntityType("Namespace", "Type"); this.type.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = this.type, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp" }); this.type.AddProperty(new EdmStructuralProperty(this.type, "PrimitiveProp", EdmCoreModel.Instance.GetInt32(false))); tmp.AddElement(this.type); EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub"); this.entitySet = edmEntityContainer.AddEntitySet("EntitySet", this.type); tmp.AddElement(edmEntityContainer); this.model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp); }
private IEdmModel CreateTestModel() { EdmModel model = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default"); model.AddElement(defaultContainer); var productType = new EdmEntityType("TestModel", "Product"); 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); var customerType = new EdmEntityType("TestModel", "Customer"); idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false)); customerType.AddProperty(idProperty); customerType.AddKeys(idProperty); customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(productType); defaultContainer.AddEntitySet("Products", productType); defaultContainer.AddEntitySet("Customers", customerType); defaultContainer.AddSingleton("SingleProduct", productType); defaultContainer.AddSingleton("SingleCustomer", customerType); EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/); model.AddElement(action); defaultContainer.AddActionImport("SimpleActionImport", action); EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true); function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1); EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true); function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/); return model; }
private IEdmModel BuildPayloadOrderTestModel() { var model = new EdmModel(); var otherType = new EdmEntityType(DefaultNamespaceName, "OtherType"); otherType.AddKeys(otherType.AddStructuralProperty("ID", Int32TypeRef)); model.AddElement(otherType); var allInType = new EdmEntityType(DefaultNamespaceName, "AllInType", null, false, false, true); allInType.AddKeys(allInType.AddStructuralProperty("ID", Int32TypeRef)); allInType.AddStructuralProperty("Name", StringTypeRef); allInType.AddStructuralProperty("Description", StringTypeRef); allInType.AddStructuralProperty("StreamProperty", EdmPrimitiveTypeKind.Stream, isNullable: false); allInType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "NavProp", Target = otherType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(allInType); var container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer"); container.AddEntitySet("OtherType", otherType); container.AddEntitySet("AllInType", allInType); model.AddElement(container); return model; }
public Task<IEdmModel> GetModelAsync(InvocationContext context, CancellationToken cancellationToken) { var model = new EdmModel(); var entityType = new EdmEntityType( "TestNamespace", "TestName"); var entityContainer = new EdmEntityContainer( "TestNamespace", "Entities"); entityContainer.AddEntitySet("TestEntitySet", entityType); model.AddElement(entityType); model.AddElement(entityContainer); return Task.FromResult<IEdmModel>(model); }
public DisablePrimitiveTypeConversionTests() { this.model = new EdmModel(); this.entityType = new EdmEntityType("FQ.NS", "EntityType", null, false, true); this.entityType.AddStructuralProperty("String", EdmPrimitiveTypeKind.String); this.entityType.AddStructuralProperty("Binary", EdmPrimitiveTypeKind.Binary); this.model.AddElement(this.entityType); var container = new EdmEntityContainer("FQ.NS", "Container"); this.model.AddElement(container); container.AddEntitySet("Entities", this.entityType); this.defaultSettings = new ODataMessageReaderSettings { BaseUri = new Uri("http://serviceRoot/"), EnableAtom = true }; this.settingsWithConversionDisabled = new ODataMessageReaderSettings(this.defaultSettings) { DisablePrimitiveTypeConversion = true, EnableAtom = true }; }
private static IEdmEntityContainer BuildContainer(IEnumerable<EntityElement> entities, TypeBuilder typeBuilder) { var container = new EdmEntityContainer(typeBuilder.NamespaceName, DefaultContainName); foreach (var entityElement in entities) { var entitySetName = entityElement.EntitySetName ?? entityElement.ResolveName(); var entityType = (IEdmEntityType)typeBuilder.ResolveComplexType(entityElement); container.AddEntitySet(entitySetName, entityType); } return container; }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType product = new EdmEntityType("ns", "Product"); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = product.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); product.AddKeys(key); model.AddElement(product); EdmEntitySet products = container.AddEntitySet("Products", product); EdmEntityType detailInfo = new EdmEntityType("ns", "DetailInfo"); detailInfo.AddKeys(detailInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); detailInfo.AddStructuralProperty("Title", EdmPrimitiveTypeKind.String); model.AddElement(detailInfo); EdmEntitySet detailInfos = container.AddEntitySet("DetailInfos", product); EdmNavigationProperty detailInfoNavProp = product.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "DetailInfo", TargetMultiplicity = EdmMultiplicity.One, Target = detailInfo }); products.AddNavigationTarget(detailInfoNavProp, detailInfos); }
private EdmModel GetModel() { EdmModel model = new EdmModel(); EdmEntityType edmEntityType = new EdmEntityType("NS", "Person"); edmEntityType.AddKeys(edmEntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); edmEntityType.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String); edmEntityType.AddStructuralProperty("FA", EdmPrimitiveTypeKind.String); edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyDog", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = edmEntityType }); model.AddElement(edmEntityType); EdmEntityContainer container = new EdmEntityContainer("NS", "EntityContainer"); model.AddElement(container); container.AddEntitySet("People", edmEntityType); return model; }
public ODataAtomReaderEnumIntegrationTests() { this.userModel = new EdmModel(); // enum without flags var enumType = new EdmEnumType("NS", "Color"); var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1)); enumType.AddMember(red); enumType.AddMember("Green", new EdmIntegerConstant(2)); enumType.AddMember("Blue", new EdmIntegerConstant(3)); this.userModel.AddElement(enumType); // enum with flags var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true); enumFlagsType.AddMember("Red", new EdmIntegerConstant(1)); enumFlagsType.AddMember("Green", new EdmIntegerConstant(2)); enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4)); this.userModel.AddElement(enumFlagsType); this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null); EdmStructuralProperty floatId = new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetSingle(false)); this.entityType.AddKeys(floatId); this.entityType.AddProperty(floatId); var enumTypeReference = new EdmEnumTypeReference(enumType, true); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference)); var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference)); // enum in complex type EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType"); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference)); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false))); this.userModel.AddElement(myComplexType); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true))); // enum in collection type EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType))); this.userModel.AddElement(this.entityType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType); defaultContainer.AddEntitySet(this.entitySet.Name, this.entityType); this.userModel.AddElement(defaultContainer); }
private static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); // entity type customer EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); IEdmStructuralProperty customerName = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(customer); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); model.AddElement(container); EdmEntitySet customers = container.AddEntitySet("ETagUntypedCustomers", customer); model.SetOptimisticConcurrencyAnnotation(customers, new[] { customerName }); return model; }
public void Init() { this.clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); this.entityDescriptor = new EntityDescriptor(this.clientEdmModel) { Entity = new Customer() }; var serverType = new EdmEntityType("FQ.NS", "MyServerType"); serverType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.serverTypeName = ((IEdmSchemaElement)serverType).FullName(); var serverContainer = new EdmEntityContainer("FQ.NS", "MyContainer"); this.serverEntitySet = serverContainer.AddEntitySet("MyEntitySet", serverType); var serverModel = new EdmModel(); serverModel.AddElement(serverType); serverModel.AddElement(serverContainer); this.ctx = new DataServiceContext(new Uri("http://temp.org/"), ODataProtocolVersion.V4, this.clientEdmModel); this.ctx.Format.UseJson(serverModel); this.testSubject = new RequestInfo(ctx); }
public void AutoComputeETagWithOptimisticConcurrencyAnnotation() { const string expected = "{" + "\"@odata.context\":\"http://example.com/$metadata#People/$entity\"," + "\"@odata.id\":\"People(123)\"," + "\"@odata.etag\":\"W/\\\"'lucy',12306\\\"\"," + "\"@odata.editLink\":\"People(123)\"," + "\"@odata.mediaEditLink\":\"People(123)/$value\"," + "\"ID\":123," + "\"Name\":\"lucy\"," + "\"Class\":12306," + "\"Alias\":\"lily\"}"; EdmModel model = new EdmModel(); EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true); personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var nameProperty = personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true)); var classProperty = personType.AddStructuralProperty("Class", EdmPrimitiveTypeKind.Int32); personType.AddStructuralProperty("Alias", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed); var container = new EdmEntityContainer("MyNs", "Container"); model.AddElement(personType); container.AddEntitySet("People", personType); model.AddElement(container); IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People"); model.SetOptimisticConcurrencyAnnotation(peopleSet, new[] { nameProperty, classProperty }); ODataEntry entry = new ODataEntry { Properties = new[] { new ODataProperty {Name = "ID", Value = 123}, new ODataProperty {Name = "Name", Value = "lucy"}, new ODataProperty {Name = "Class", Value = 12306}, new ODataProperty {Name = "Alias", Value = "lily"}, } }; string actual = GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType); Assert.Equal(expected, actual); }
public ExpandAndSelectPathExtractingTests() { this.baseType = new EdmEntityType("FQ.NS", "Base"); this.baseType.AddKeys(this.baseType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var baseNavigation1 = this.baseType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation1", Target = this.baseType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var baseNavigation2 = this.baseType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation2", Target = this.baseType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); this.derivedType = new EdmEntityType("FQ.NS", "Derived", this.baseType); this.derivedType.AddStructuralProperty("Derived", EdmPrimitiveTypeKind.Int32); var derivedNavigation = this.derivedType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DerivedNavigation", Target = this.derivedType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var container = new EdmEntityContainer("FQ.NS", "Container"); this.entitySet = container.AddEntitySet("Entities", this.baseType); this.entitySet.AddNavigationTarget(baseNavigation1, this.entitySet); this.entitySet.AddNavigationTarget(baseNavigation2, this.entitySet); this.entitySet.AddNavigationTarget(derivedNavigation, this.entitySet); this.model = new EdmModel(); this.model.AddElement(this.baseType); this.model.AddElement(this.derivedType); this.model.AddElement(container); }
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); }
public void WriterSettingsIntegrationTestWithSelect() { var setting = new ODataMessageWriterSettings(); var edmModel = new EdmModel(); var defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); edmModel.AddElement(defaultContainer); var cityType = new EdmEntityType("TestModel", "City"); var cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); cityType.AddKeys(cityIdProperty); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false)); cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); edmModel.AddElement(cityType); var citySet = defaultContainer.AddEntitySet("Cities", cityType); var result = new ODataQueryOptionParser(edmModel, cityType, citySet, new Dictionary<string, string> { { "$expand", "" }, { "$select", "Id,*" } }).ParseSelectAndExpand(); setting.SetServiceDocumentUri(ServiceDocumentUri); setting.ODataUri = new ODataUri() { SelectAndExpand = result }; setting.MetadataDocumentUri.Should().Equals(ServiceDocumentUri + "/$metadata"); string select, expand; setting.SelectExpandClause.GetSelectExpandPaths(out select, out expand); select.Should().Be("*"); }
public static void Register(HttpConfiguration config) { var model2 = EdmxReader.Parse(XmlReader.Create("http://localhost:9091/odata/$metadata")); var model = new EdmModel(); model.AddReferencedModel(model2); var reference = new EdmReference("http://localhost:9091/odata/$metadata"); reference.AddInclude(new EdmInclude("Model2", "SampleService2.Models")); model.SetEdmReferences(new List<IEdmReference> { reference }); var container = new EdmEntityContainer("NS1", "Default"); var order = model2.FindDeclaredType("SampleService2.Models.Order") as IEdmEntityType; model2.SetAnnotationValue<ClrTypeAnnotation>(order, new ClrTypeAnnotation(typeof(Order))); container.AddEntitySet("Orders", order); model.AddElement(container); var product = new EdmEntityType("NS1", "Product"); product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(product); config.MapODataServiceRoute("odata", "odata", model); }
public void InStreamErrorInEntriesTest() { EdmModel edmModel = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); edmModel.AddElement(defaultContainer); var dummyType = new EdmEntityType("TestModel", "DummyEntryType"); dummyType.AddKeys(dummyType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false))); edmModel.AddElement(dummyType); var dummySet = defaultContainer.AddEntitySet("DummySet", dummyType); var errorCases = new [] { new { Json = "{{ \"{0}\": {{ \"code\": \"my-error-code\" }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { ErrorCode = "my-error-code" }) }, new { Json = "{{ \"{0}\": {{ \"message\": \"my-error-message\" }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { Message = "my-error-message" }) }, new { Json = "{{ \"{0}\": {{ \"code\": \"my-error-code\", \"message\": \"my-error-message\" }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { ErrorCode = "my-error-code", Message = "my-error-message" }) }, new { Json = "{{ \"{0}\": {{ \"code\": \"my-error-code\", \"innererror\": {{ \"message\": \"my-inner-error\" }} }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { ErrorCode = "my-error-code", InnerError = new ODataInnerError { Message = "my-inner-error" }}) }, new { Json = "{{ \"{0}\": {{ \"innererror\": {{ \"message\": \"my-inner-error\" }} }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError {InnerError = new ODataInnerError { Message = "my-inner-error" }}) }, new { Json = "{{ \"{0}\": {{ \"message\": \"my-error-message\", \"innererror\": {{ \"message\": \"my-inner-error\" }} }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { Message = "my-error-message", InnerError = new ODataInnerError { Message = "my-inner-error" }}) }, new { Json = "{{ \"{0}\": {{ \"code\": \"my-error-code\", \"message\": \"my-error-message\", \"innererror\": {{ \"message\": \"my-inner-error\" }} }} }}", ExpectedException = ODataExpectedExceptions.ODataErrorException(new ODataError { ErrorCode = "my-error-code", Message = "my-error-message", InnerError = new ODataInnerError { Message = "my-inner-error" }}) }, }; this.CombinatorialEngineProvider.RunCombinations( errorCases, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations, (errorCase, testConfiguration) => { string errorElementName = JsonLightConstants.ODataErrorPropertyName; var testCase = new JsonPayloadErrorTestCase { Json = PayloadBuilder.Entity("TestModel.DummyEntryType") .JsonRepresentation(string.Format(errorCase.Json, errorElementName)) .ExpectedEntityType(dummyType, dummySet), EdmModel = edmModel, ExpectedExceptionFunc = (tCase, tConfig) => errorCase.ExpectedException, }; var descriptor = testCase.ToEdmPayloadReaderTestDescriptor(this.PayloadTestDescriptorSettings, this.PayloadExpectedResultSettings); // NOTE: payload generation is not supported for JSON Light yet var descriptors = testConfiguration.Format == ODataFormat.Json ? new PayloadReaderTestDescriptor[] { descriptor } : this.PayloadGenerator.GenerateReaderPayloads(descriptor); this.CombinatorialEngineProvider.RunCombinations( descriptors, testDescriptor => testDescriptor.RunTest(testConfiguration)); }); }