private static EdmModel CreateCustomerProductsModel() { var model = new EdmModel(); var container = new EdmEntityContainer("defaultNamespace", "DefaultContainer"); model.AddElement(container); var productType = new EdmEntityType("defaultNamespace", "Product"); model.AddElement(productType); var customerType = new EdmEntityType("defaultNamespace", "Customer"); customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customers", Target = customerType, TargetMultiplicity = EdmMultiplicity.Many }); model.AddElement(customerType); var productSet = new EdmEntitySet( container, "Products", productType); container.AddElement(productSet); var customerSet = new EdmEntitySet( container, "Customers", customerType); var productsNavProp = customerType.NavigationProperties().Single(np => np.Name == "Products"); customerSet.AddNavigationTarget(productsNavProp, productSet); container.AddElement(customerSet); return model; }
private EdmEntityType ConvertToEdmEntityType(JSchema schema, EdmModel model, string name) { var type = new EdmEntityType("namespace", name); foreach (var property in schema.Properties) { if (property.Value.Type == null) throw new Exception("Type specyfication missing."); var structuralType = MapPropertyToStructuralType(property, schema, model); if (structuralType != null) { type.AddStructuralProperty(property.Key, structuralType); } else { type.AddStructuralProperty(property.Key, ToEdmPrimitiveType(property.Value.Type.Value)); } } model.AddElement(type); return type; }
public void Property_ExpectedEdmType() { EdmEntityType edmBaseType = new EdmEntityType("NS", "Base"); EdmEntityType edmDerivedType = new EdmEntityType("NS", "Derived", edmBaseType); TestEdmStructuredObject edmObject = new TestEdmStructuredObject(edmDerivedType); Assert.Reflection.Property(edmObject, o => o.ExpectedEdmType, edmDerivedType, allowNull: false, roundTripTestValue: edmBaseType); }
public void GetEntitySetLinkBuilder_ReturnsDefaultEntitySetBuilder_IfNotSet() { IEdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType); Assert.NotNull(model.GetEntitySetLinkBuilder(entitySet)); }
public void Property_ExpectedEdmType_CanBeSameAs_ActualEdmType() { EdmEntityType edmType = new EdmEntityType("NS", "Entity"); TestEdmStructuredObject edmObject = new TestEdmStructuredObject(edmType); edmObject.ExpectedEdmType = edmType; Assert.Same(edmType, edmObject.ExpectedEdmType); }
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 }); 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); EntitySetLinkBuilderAnnotation linkAnnotation = new MockEntitySetLinkBuilderAnnotation(); model.SetEntitySetLinkBuilder(customerSet, linkAnnotation); model.SetEntitySetLinkBuilder(orderSet, linkAnnotation); model.AddElement(container); return model; }
public void Property_ActualEdmType_ThrowsDeltaEntityTypeNotAssignable() { EdmEntityType edmType1 = new EdmEntityType("NS", "Entity1"); EdmEntityType edmType2 = new EdmEntityType("NS", "Entity2"); TestEdmStructuredObject edmObject = new TestEdmStructuredObject(edmType1); Assert.Throws<InvalidOperationException>( () => { edmObject.ActualEdmType = edmType2; }, "The actual entity type 'NS.Entity2' is not assignable to the expected type 'NS.Entity1'."); }
/// <summary> /// Initializes a new instance of the <see cref="TableStorageModel"/> class. /// </summary> public TableStorageModel(string accountName) { // Add the special table type. this.accountName = accountName; this.tableType = new EdmEntityType(this.accountName, Constants.EntitySetName); this.tableType.AddKeys(this.tableType.AddStructuralProperty(Constants.DefaultTableName, EdmPrimitiveTypeKind.String)); this.AddElement(this.tableType); // Add the default entity container - the name and namespace should not matter since we look for default entity container. TableStorageEntityContainer entityContainer = new TableStorageEntityContainer(this); this.AddElement(entityContainer); this.SetIsDefaultEntityContainer(entityContainer, true); }
static TableStorageQueryIndexInspector() { EdmModel = new EdmModel(); TableServiceEntity = new EdmEntityType("Glimpse.WindowsAzure.Storage", "TableServiceEntity"); TableServiceEntity.AddStructuralProperty("PartitionKey", EdmPrimitiveTypeKind.String); TableServiceEntity.AddStructuralProperty("RowKey", EdmPrimitiveTypeKind.String); TableServiceEntity.AddStructuralProperty("Timestamp", EdmPrimitiveTypeKind.DateTime); EdmModel.AddElement(TableServiceEntity); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); container.AddEntitySet("Entities", TableServiceEntity); EdmModel.AddElement(container); }
public void GetEntitySetLinkBuilder_After_SetEntitySetLinkBuilder() { // Arrange IEdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType); EntitySetLinkBuilderAnnotation entitySetLinkBuilder = new EntitySetLinkBuilderAnnotation(); // Act model.SetEntitySetLinkBuilder(entitySet, entitySetLinkBuilder); var result = model.GetEntitySetLinkBuilder(entitySet); // Assert Assert.Same(entitySetLinkBuilder, result); }
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 : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.Partner != null ? property.Partner.Multiplicity() : property.Type.TypeKind() == EdmTypeKind.Collection ? EdmMultiplicity.Many : property.Type.TypeKind() == EdmTypeKind.Entity ? EdmMultiplicity.ZeroOrOne : EdmMultiplicity.Unknown, }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
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); model.AddElement(customerType); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); orderType.AddStructuralProperty("Name", 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 }); 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); Mock<IEntitySetLinkBuilder> linkAnnotation = new Mock<IEntitySetLinkBuilder>(); model.SetEntitySetLinkBuilderAnnotation(customerSet, linkAnnotation.Object); model.SetEntitySetLinkBuilderAnnotation(orderSet, linkAnnotation.Object); model.AddElement(container); 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)); 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; }
public void CreateTypeNameExpression_ReturnsConditionalExpression_IfTypeHasDerivedTypes() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); IEdmEntityType typeA = new EdmEntityType("NS", "A", baseType); IEdmEntityType typeB = new EdmEntityType("NS", "B", baseType); IEdmEntityType typeAA = new EdmEntityType("NS", "AA", typeA); IEdmEntityType typeAAA = new EdmEntityType("NS", "AAA", typeAA); IEdmEntityType[] types = new[] { baseType, typeA, typeAAA, typeB, typeAA }; EdmModel model = new EdmModel(); foreach (var type in types) { model.AddElement(type); model.SetAnnotationValue(type, new ClrTypeAnnotation(new MockType(type.Name, @namespace: type.Namespace))); } Expression source = Expression.Constant(42); // Act Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model); // Assert Assert.Equal( result.ToString(), @"IIF((42 Is AAA), ""NS.AAA"", IIF((42 Is AA), ""NS.AA"", IIF((42 Is B), ""NS.B"", IIF((42 Is A), ""NS.A"", ""NS.BaseType""))))"); }
public void GetEntityKeyValue_DerivedType() { // Arrange var entityInstance = new { Key = "key" }; EdmEntityType baseEntityType = new EdmEntityType("NS", "Name"); baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key", EdmPrimitiveTypeKind.String)); EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, derivedEntityType.AsReference(), entityInstance); // Act var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext); // Assert Assert.Equal("'key'", keyValue); }
public void CreateTypeNameExpression_ReturnsNull_IfTypeHasNoDerivedTypes() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); EdmModel model = new EdmModel(); model.AddElement(baseType); Expression source = Expression.Constant(42); // Act Expression result = SelectExpandBinder.CreateTypeNameExpression(source, baseType, model); // Assert Assert.Null(result); }
public void CreateTypeNameExpression_ThrowsODataException_IfTypeHasNoMapping() { // Arrange IEdmEntityType baseType = new EdmEntityType("NS", "BaseType"); IEdmEntityType derivedType = new EdmEntityType("NS", "DerivedType", baseType); EdmModel model = new EdmModel(); model.AddElement(baseType); model.AddElement(derivedType); Expression source = Expression.Constant(42); // Act & Assert Assert.Throws<ODataException>( () => SelectExpandBinder.CreateTypeNameExpression(source, baseType, model), "The provided mapping doesn't contain an entry for the entity type 'NS.DerivedType'."); }
EdmEntityTypeWrapper AddTable(EdmModel model, TableData dataBuilder) { var propertyMap = new Dictionary<Field, EdmStructuralProperty>(); var table = new EdmEntityType("sitecore.com", dataBuilder.Name); foreach (var field in dataBuilder.Schema.Fields) { var prop = table.AddStructuralProperty(field.Name, GetEdmType(field.ValueType), IsNullable(field.ValueType)); if (field.FieldType == FieldType.Key) { table.AddKeys(prop); } propertyMap.Add(field, prop); } model.AddElement(table); return new EdmEntityTypeWrapper {Type = table, Properties = propertyMap}; }
private static IEdmModel BuildModel(JObject viewObject, out IList<string> fieldsToIgnore) { var model = new EdmModel(); fieldsToIgnore = new List<string>(); var name = viewObject.PrimitivePropertyValue<string>("name"); name = name.Replace(' ', '_'); var entityType = new EdmEntityType(false, false, null, "OData4Socrata", name, Enumerable.Empty<IEdmStructuralProperty>()); var entitySet = new EdmEntitySet(name, entityType); EdmComplexType phoneComplex = null; EdmComplexType locationComplex = null; EdmComplexType urlComplex = null; foreach (var column in viewObject.ArrayPropertyValue<JObject>("columns")) { var fieldName = column.PrimitivePropertyValue<string>("name"); var sodaType = column.PrimitivePropertyValue<string>("dataTypeName"); IEdmTypeReference typeReference; switch (sodaType) { case "meta_data": fieldsToIgnore.Add(fieldName); continue; case "text": typeReference = EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)); break; case "url": if (urlComplex == null) { urlComplex = new EdmComplexType(false, false, null, entityType.Namespace, "url"); new EdmStructuralProperty(urlComplex, "url", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); model.AddElement(urlComplex); } typeReference = new EdmComplexTypeReference(urlComplex, false); break; case "phone": if (phoneComplex == null) { phoneComplex = new EdmComplexType(false, false, null, entityType.Namespace, "phone"); new EdmStructuralProperty(phoneComplex, "phone_number", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); new EdmStructuralProperty(phoneComplex, "phone_type", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); model.AddElement(phoneComplex); } typeReference = new EdmComplexTypeReference(phoneComplex, false); break; case "location": if (locationComplex == null) { locationComplex = new EdmComplexType(false, false, null, entityType.Namespace, "location"); new EdmStructuralProperty(locationComplex, "human_address", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); new EdmStructuralProperty(locationComplex, "latitude", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); new EdmStructuralProperty(locationComplex, "longitude", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); new EdmStructuralProperty(locationComplex, "machine_address", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (string)), null, EdmConcurrencyMode.None); new EdmStructuralProperty(locationComplex, "needs_recoding", EdmLibraryExtensions.GetPrimitiveTypeReference(typeof (bool)), null, EdmConcurrencyMode.None); model.AddElement(locationComplex); } typeReference = new EdmComplexTypeReference(locationComplex, false); break; default: throw new Exception(); } new EdmStructuralProperty(entityType, fieldName, typeReference, null, EdmConcurrencyMode.None); } model.AddElement(entityType); var entityContainer = new EdmEntityContainer(); model.AddEntityContainer(entityContainer); entityContainer.AddElement(entitySet); return model; }
public void ProcessRequest(HttpContext context) { if (!HttpContext.Current.Request.IsAuthenticated) { HttpContext.Current.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = HttpContext.Current.Request.FilePath }, "OAuth2Bearer"); return; } MSRAHttpResponseMessage message = new MSRAHttpResponseMessage(this.ContextBase.Response); message.StatusCode = 200; message.SetHeader(ODataConstants.ContentTypeHeader, "application/json"); // create the writer, indent for readability ODataMessageWriterSettings messageWriterSettings = new ODataMessageWriterSettings() { Indent = true, CheckCharacters = false, BaseUri = context.Request.Url }; messageWriterSettings.SetContentType(ODataFormat.Json); messageWriterSettings.SetMetadataDocumentUri(new Uri("http://localhost:31435/odata/MSRAQuery/$metadata")); if (string.IsNullOrEmpty(QueryId)) { AzureTestDBEntities db = new AzureTestDBEntities(); var queries = db.MsrRecurringQueries.ToList().Take(1); ODataWorkspace workSpace = new ODataWorkspace(); var collections = new List<ODataResourceCollectionInfo>(); foreach (MsrRecurringQuery recurringQuery in queries) { ODataResourceCollectionInfo collectionInfo = new ODataResourceCollectionInfo() { Name = "MsrRecurringQueries", Url = new Uri(context.Request.Url+"data/" + recurringQuery.RecurringQueryID.ToString(), UriKind.Absolute) }; collectionInfo.SetAnnotation<AtomResourceCollectionMetadata>(new AtomResourceCollectionMetadata() { Title = new AtomTextConstruct() { Text = "MsrRecurringQueries"//recurringQuery.RecurringQueryName }, }); collections.Add(collectionInfo); } workSpace.Collections = collections.AsEnumerable<ODataResourceCollectionInfo>(); using (ODataMessageWriter messageWriter = new ODataMessageWriter(message, messageWriterSettings)) { messageWriter.WriteServiceDocumentAsync(workSpace); } } else { EdmModel mainModel =(EdmModel) QueryMetadataHttpHandler.BuildODataModel(); using (ODataMessageWriter messageWriter = new ODataMessageWriter(message, messageWriterSettings, mainModel)) { var msrRecurringQueryResultType = new EdmEntityType("mainNS", "MsrRecurringQuery", null); IEdmPrimitiveType edmPrimitiveType1 = new MSRAEdmPrimitiveType("Int32", "Edm", EdmPrimitiveTypeKind.Int32, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); IEdmPrimitiveType edmPrimitiveType2 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); IEdmPrimitiveType edmPrimitiveType3 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); IEdmPrimitiveType edmPrimitiveType4 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); IEdmPrimitiveType edmPrimitiveType5 = new MSRAEdmPrimitiveType("String", "Edm", EdmPrimitiveTypeKind.String, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); IEdmPrimitiveType edmPrimitiveType6 = new MSRAEdmPrimitiveType("Decimal", "Edm", EdmPrimitiveTypeKind.Decimal, EdmSchemaElementKind.TypeDefinition, EdmTypeKind.Primitive); msrRecurringQueryResultType.AddKeys(new EdmStructuralProperty(msrRecurringQueryResultType, "RowId", new EdmPrimitiveTypeReference(edmPrimitiveType1, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "RowId", new EdmPrimitiveTypeReference(edmPrimitiveType1, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Pricing_Level", new EdmPrimitiveTypeReference(edmPrimitiveType2, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Business_Summary", new EdmPrimitiveTypeReference(edmPrimitiveType3, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Future_Flag", new EdmPrimitiveTypeReference(edmPrimitiveType4, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "Fiscal_Month", new EdmPrimitiveTypeReference(edmPrimitiveType5, false))); msrRecurringQueryResultType.AddProperty(new EdmStructuralProperty(msrRecurringQueryResultType, "MS_Sales_Amount_Const", new EdmPrimitiveTypeReference(edmPrimitiveType6, false))); ODataWriter feedWriter = messageWriter.CreateODataFeedWriter( mainModel.EntityContainers().Select(c => c.EntitySets().First()).First(), msrRecurringQueryResultType); ODataFeed feed = new ODataFeed() { Id = "MsrRecurringQueries", }; feedWriter.WriteStart(feed); AzureTestDBEntities db = new AzureTestDBEntities(); var queries = db.T_annooli_231161891 ; foreach (var recurringQuery in queries) { ODataEntry entry = this.GetODataEntry(recurringQuery); feedWriter.WriteStart(entry); feedWriter.WriteEnd(); } feedWriter.WriteEnd(); } } }
public void GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys() { // Arrange var entityInstance = new { Key1 = "abc", Key2 = "def", Key3 = (string)null }; EdmEntityType entityType = new EdmEntityType("NS", "Name"); entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String)); entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32)); entityType.AddKeys(entityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean)); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance); // Act & Assert Assert.Throws<InvalidOperationException>( () => ConventionsHelpers.GetEntityKeyValue(entityInstanceContext), "Key property 'Key3' of type 'NS.Name' is null. Key properties cannot have null values."); }
public void Property_EntityInstance_CanBeBuiltFromIEdmObject() { // Arrange EdmEntityType edmType = new EdmEntityType("NS", "Name"); edmType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.Int32); EdmModel model = new EdmModel(); model.AddElement(edmType); model.SetAnnotationValue<ClrTypeAnnotation>(edmType, new ClrTypeAnnotation(typeof(TestEntity))); Mock<IEdmEntityObject> edmObject = new Mock<IEdmEntityObject>(); object propertyValue = 42; edmObject.Setup(e => e.TryGetPropertyValue("Property", out propertyValue)).Returns(true); edmObject.Setup(e => e.GetEdmType()).Returns(new EdmEntityTypeReference(edmType, isNullable: false)); EntityInstanceContext entityContext = new EntityInstanceContext { EdmModel = model, EdmObject = edmObject.Object, EntityType = edmType }; // Act object resource = entityContext.EntityInstance; // Assert TestEntity testEntity = Assert.IsType<TestEntity>(resource); Assert.Equal(42, testEntity.Property); }
public void Property_EntityInstance_EdmObjectHasCollectionProperty() { // Arrange EdmEntityType edmType = new EdmEntityType("NS", "Name"); edmType.AddStructuralProperty( "CollectionProperty", new EdmCollectionTypeReference( new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false)), isNullable: false)); EdmModel model = new EdmModel(); model.AddElement(edmType); model.SetAnnotationValue<ClrTypeAnnotation>(edmType, new ClrTypeAnnotation(typeof(TestEntity))); Mock<IEdmStructuredObject> edmObject = new Mock<IEdmStructuredObject>(); object propertyValue = new List<int> { 42 }; edmObject.Setup(e => e.TryGetValue("CollectionProperty", out propertyValue)).Returns(true); edmObject.Setup(e => e.GetEdmType()).Returns(new EdmEntityTypeReference(edmType, isNullable: false)); EntityInstanceContext entityContext = new EntityInstanceContext { EdmModel = model, EdmObject = edmObject.Object, EntityType = edmType }; // Act object resource = entityContext.EntityInstance; // Assert TestEntity testEntity = Assert.IsType<TestEntity>(resource); Assert.Equal(new[] { 42 }, testEntity.CollectionProperty); }
private static IEdmModel CreateModel() { var model = new EdmModel(); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(orderType); var customerType = new EdmEntityType("Default", "Customer"); customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(customerType); // Add navigations orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); var container = new EdmEntityContainer("Default", "Container"); var orderSet = container.AddEntitySet("Orders", orderType); var customerSet = container.AddEntitySet("Customers", customerType); container.AddFunctionImport("GetId", new EdmPrimitiveTypeReference( EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true)); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); model.AddElement(container); return model; }
private void CreateEntityTypeBody(EdmEntityType type, IEntityTypeConfiguration config) { CreateStructuralTypeBody(type, config); IEdmStructuralProperty[] keys = config.Keys.Select(p => type.DeclaredProperties.OfType<IEdmStructuralProperty>().First(dp => dp.Name == p.PropertyInfo.Name)).ToArray(); type.AddKeys(keys); 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; //TODO: If target end has a multiplity of 1 this assumes the source end is 0..1. // I think a better default multiplicity is * type.AddUnidirectionalNavigation(info); } }
public void GetEntityKeyValue_MultipleKeys_DerivedType() { // Arrange var entityInstance = new { Key1 = "key1", Key2 = 2, Key3 = true }; EdmEntityType baseEntityType = new EdmEntityType("NS", "Name"); baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String)); baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32)); baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean)); EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType); EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, derivedEntityType.AsReference(), entityInstance); // Act var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext); // Assert Assert.Equal("Key1='key1',Key2=2,Key3=true", keyValue); }
public void CreateSelectExpandNode_ReturnsDifferentSelectExpandNode_IfEntityTypeIsDifferent() { // Arrange IEdmEntityType customerType = _customerSet.ElementType; IEdmEntityType derivedCustomerType = new EdmEntityType("NS", "DerivedCustomer", customerType); EntityInstanceContext entity1 = new EntityInstanceContext(_writeContext, customerType.AsReference(), new Customer()); EntityInstanceContext entity2 = new EntityInstanceContext(_writeContext, derivedCustomerType.AsReference(), new Customer()); // Act var selectExpandNode1 = _serializer.CreateSelectExpandNode(entity1); var selectExpandNode2 = _serializer.CreateSelectExpandNode(entity2); // Assert Assert.NotSame(selectExpandNode1, selectExpandNode2); }
public void GetEntityKeyValue_SingleKey_DifferentDataTypes(object value, object expectedValue) { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "Name"); entityType.AddKeys(entityType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.String)); var entityInstance = new { Property = value }; EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance); // Act var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext); // Assert Assert.Equal(expectedValue, keyValue); }
public void ToDictionary_ContainsAllStructuralProperties_IfInstanceIsNotNull() { // Arrange EdmModel model = new EdmModel(); EdmEntityType entityType = new EdmEntityType("NS", "Name"); model.AddElement(entityType); model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity))); entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32); IEdmTypeReference edmType = new EdmEntityTypeReference(entityType, isNullable: false); SelectExpandWrapper<TestEntity> testWrapper = new SelectExpandWrapper<TestEntity> { Instance = new TestEntity { SampleProperty = 42 }, ModelID = ModelContainer.GetModelID(model) }; // Act var result = testWrapper.ToDictionary(); // Assert Assert.Equal(42, result["SampleProperty"]); }
public void Property_EntityInstance_ThrowsInvalidOp_EntityTypeDoesNotHaveAMapping() { EdmEntityType entityType = new EdmEntityType("NS", "Name"); EdmModel model = new EdmModel(); IEdmEntityObject instance = new Mock<IEdmEntityObject>().Object; EntityInstanceContext entityContext = new EntityInstanceContext { EntityType = entityType, EdmModel = model, EdmObject = instance }; Assert.Throws<InvalidOperationException>( () => entityContext.EntityInstance, "The provided mapping doesn't contain an entry for the entity type 'NS.Name'."); }