public void ReadInline_ThrowsArgumentNull_ForInputParameters() { // Arrange Mock <IODataDeserializerProvider> deserializerProvider = new Mock <IODataDeserializerProvider>(); ODataDeltaResourceSetDeserializer deserializer = new ODataDeltaResourceSetDeserializer(deserializerProvider.Object); // Arrange & Act & Assert Assert.Null(deserializer.ReadInline(null, null, null)); // Arrange & Act & Assert ExceptionAssert.ThrowsArgumentNull(() => deserializer.ReadInline(5, null, null), "edmType"); // Arrange & Act & Assert IEdmTypeReference typeReference = new Mock <IEdmTypeReference>().Object; ExceptionAssert.ThrowsArgumentNull(() => deserializer.ReadInline(5, typeReference, null), "readContext"); // Arrange & Act & Assert ODataDeserializerContext context = new ODataDeserializerContext(); IEdmPrimitiveTypeReference intType = EdmCoreModel.Instance.GetString(false); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(intType)); ExceptionAssert.ThrowsArgument(() => deserializer.ReadInline(4, collectionType, context), "edmType", "'Collection(Edm.String)' is not a resource set type. Only resource set are supported."); // Arrange & Act & Assert EdmEntityType entityType = new EdmEntityType("NS", "Customer"); collectionType = new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false))); ExceptionAssert.ThrowsArgument(() => deserializer.ReadInline(4, collectionType, context), "item", "The argument must be of type 'ODataDeltaResourceSetWrapper'."); }
protected IEnumerable <IEdmEntityObject> GetFilteredResult(IEnumerable <Dictionary <string, object> > group, string query, ParseContext parseContext) { // Create collection from group var collectionEntityTypeKey = parseContext.LatestStateDictionary .Keys.FirstOrDefault(p => p.Contains("collectionentitytype")); var entityRef = (EdmEntityTypeReference)parseContext.LatestStateDictionary[collectionEntityTypeKey]; var collectionRef = new EdmCollectionTypeReference(new EdmCollectionType(entityRef)); var collection = new EdmEntityObjectCollection(collectionRef); foreach (var entity in group) { var obj = new EdmEntityObject(entityRef); foreach (var kvp in entity) { obj.TrySetPropertyValue(kvp.Key, kvp.Value); } collection.Add(obj); } // Create filter query using the entity supplied in the lateststatedictionary var serviceRoot = new Uri(RequestFilterConstants.ODataServiceRoot); var resource = entityRef.Definition.FullTypeName().Split(".").Last(); var filterQuery = "/" + resource + "?$filter=" + Uri.EscapeDataString(query.Substring(1, query.Length - 2).Replace("''", "'")); var oDataUriParser = new ODataUriParser(parseContext.Model, new Uri(filterQuery, UriKind.Relative)); // Parse filterquery var filter = oDataUriParser.ParseFilter(); var odataFilter = new ODataFilterPredicateParser(); var filteredResult = odataFilter.ApplyFilter(parseContext.EdmEntityTypeSettings.FirstOrDefault(), collection, filter.Expression); return(filteredResult); }
public static IEdmModel GetModelWithOperationOverloadsWithSameName() { EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable", null, true, false); IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)); vegetableType.AddKeys(id); EdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(vegetableType, false))); EdmEntityContainer container = new EdmEntityContainer("Test", "Container"); var action1 = new EdmAction("Test", "Action", new EdmEntityTypeReference(vegetableType, true), true /*isBound*/, null /*entitySetPath*/); action1.AddParameter("p1", collectionTypeReference); var action2 = new EdmAction("Test", "Action", new EdmEntityTypeReference(vegetableType, true), true /*isBound*/, null /*entitySetPath*/); action2.AddParameter("p2", new EdmEntityTypeReference(vegetableType, true)); EdmModel model = new EdmModel(); model.AddElement(container); model.AddElement(vegetableType); model.AddElement(action1); model.AddElement(action2); return(model); }
/// <summary> /// Gets a List for all entities of a group. /// </summary> /// <param name="group"></param> /// <param name="edmComplexType"></param> /// <returns></returns> protected SubCollectionContext GetList(IEnumerable <Dictionary <string, object> > group, EdmComplexType edmComplexType, int limit = 0) { var queryable = new List <Dictionary <string, object> >(); var collectionTypeReference = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(edmComplexType, true))); var subCollection = new EdmComplexObjectCollection(collectionTypeReference); int count = 0; foreach (var entity in group) { var dict = new Dictionary <string, object>(); var edmComplexObject = new EdmComplexObject(edmComplexType); foreach (var propertyKvp in entity) { edmComplexObject.TrySetPropertyValue(propertyKvp.Key, propertyKvp.Value); dict.Add(propertyKvp.Key, propertyKvp.Value); } subCollection.Add(edmComplexObject); queryable.Add(dict); if (limit >= 1 && ++count == limit) { break; } } return(new SubCollectionContext { Result = subCollection, QueryAbleResult = queryable }); }
public void CreateResourceSet_SetsODataOperations() { // Arrange IEdmModel model = GetEdmModelWithOperations(out IEdmEntityType customerType, out IEdmEntitySet customers); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(customerType.AsReference())); Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(serializerProvider.Object); var request = RequestFactory.Create(method: "get", uri: "http://IgnoreMetadataPath", opt => opt.AddModel(model)); ODataSerializerContext context = new ODataSerializerContext { NavigationSource = customers, Request = request, Model = model, MetadataLevel = ODataMetadataLevel.Full, }; var result = new object[0]; // Act ODataResourceSet resourceSet = serializer.CreateResourceSet(result, customersType, context); // Assert Assert.Single(resourceSet.Actions); Assert.Equal(3, resourceSet.Functions.Count()); }
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference()), isNullable: false); ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true); IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First(); EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = new ODataSerializerContext { EntitySet = model.Customers, Model = model.Model } }; ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, ordersProperty); TruncatedCollection <Order> orders = new TruncatedCollection <Order>(new[] { new Order(), new Order() }, pageSize: 1); Mock <EntitySetLinkBuilderAnnotation> linkBuilder = new Mock <EntitySetLinkBuilderAnnotation>(); linkBuilder.Setup(l => l.BuildNavigationLink(entity, ordersProperty, ODataMetadataLevel.Default)).Returns(new Uri("http://navigation-link/")); model.Model.SetEntitySetLinkBuilder(model.Customers, linkBuilder.Object); model.Model.SetEntitySetLinkBuilder(model.Orders, new EntitySetLinkBuilderAnnotation()); // Act ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext); // Assert Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri); }
internal static Uri GenerateFunctionLink(this ResourceSetContext feedContext, string bindingParameterType, string functionName, IEnumerable <string> parameterNames) { Contract.Assert(feedContext != null); if (feedContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } if (feedContext.EdmModel == null) { return(null); } IEdmModel model = feedContext.EdmModel; string elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType, isNested: false); Contract.Assert(elementType != null); IEdmTypeReference typeReference = model.FindDeclaredType(elementType).ToEdmTypeReference(true); IEdmTypeReference collection = new EdmCollectionTypeReference(new EdmCollectionType(typeReference)); IEdmOperation operation = model.FindDeclaredOperations(functionName).First(); return(feedContext.GenerateFunctionLink(collection, operation, parameterNames)); }
public void CreateResourceSet_SetsODataOperations() { // Arrange var config = RoutingConfigurationFactory.CreateWithRootContainer("OData"); var request = RequestFactory.Create(config, "OData"); CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(_serializerProvider); ODataSerializerContext context = new ODataSerializerContext { NavigationSource = model.Customers, Request = request, Model = model.Model, MetadataLevel = ODataMetadataLevel.FullMetadata, Url = CreateMetadataLinkFactory("http://IgnoreMetadataPath", request) }; var result = new object[0]; // Act ODataResourceSet resourceSet = serializer.CreateResourceSet(result, customersType, context); // Assert Assert.Single(resourceSet.Actions); Assert.Equal(3, resourceSet.Functions.Count()); }
public void CreateEdmTypeSchemaReturnSchemaForNullableCollectionComplexType() { // Arrange IEdmModel model = EdmModelHelper.TripServiceModel; IEdmComplexType complex = model.SchemaElements.OfType <IEdmComplexType>().First(c => c.Name == "AirportLocation"); ODataContext context = new ODataContext(model); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference( new EdmCollectionType(new EdmComplexTypeReference(complex, true))); // Act var schema = context.CreateEdmTypeSchema(collectionType); Assert.NotNull(schema); string json = schema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); // & Assert Assert.Equal(@"{ ""type"": ""array"", ""items"": { ""anyOf"": [ { ""$ref"": ""#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.AirportLocation"" } ], ""nullable"": true } }".ChangeLineBreaks(), json); }
private static EdmEntityObjectCollection GetCustomers() { if (_untypedSimpleOpenCustormers != null) { return(_untypedSimpleOpenCustormers); } IEdmModel edmModel = OpenEntityTypeTests.GetUntypedEdmModel(); IEdmEntityType customerType = edmModel.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "UntypedSimpleOpenCustomer"); EdmEntityObject customer = new EdmEntityObject(customerType); customer.TrySetPropertyValue("CustomerId", 1); //Add Numbers primitive collection property customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 }); //Add Color, Colors enum(collection) property IEdmEnumType colorType = edmModel.SchemaElements.OfType <IEdmEnumType>().First(c => c.Name == "Color"); EdmEnumObject color = new EdmEnumObject(colorType, "Red"); EdmEnumObject color2 = new EdmEnumObject(colorType, "0"); EdmEnumObject color3 = new EdmEnumObject(colorType, "Red"); customer.TrySetPropertyValue("Color", color); List <IEdmEnumObject> colorList = new List <IEdmEnumObject>(); colorList.Add(color); colorList.Add(color2); colorList.Add(color3); IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false))); EdmEnumObjectCollection colors = new EdmEnumObjectCollection(enumCollectionType, colorList); customer.TrySetPropertyValue("Colors", colors); customer.TrySetPropertyValue("DeclaredColors", colors); //Add Addresses complex(collection) property EdmComplexType addressType = edmModel.SchemaElements.OfType <IEdmComplexType>().First(c => c.Name == "Address") as EdmComplexType; EdmComplexObject address = new EdmComplexObject(addressType); address.TrySetPropertyValue("Street", "No1"); EdmComplexObject address2 = new EdmComplexObject(addressType); address2.TrySetPropertyValue("Street", "No2"); List <IEdmComplexObject> addressList = new List <IEdmComplexObject>(); addressList.Add(address); addressList.Add(address2); IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false))); EdmComplexObjectCollection addresses = new EdmComplexObjectCollection(complexCollectionType, addressList); customer.TrySetPropertyValue("DeclaredAddresses", addresses); EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false)))); customers.Add(customer); _untypedSimpleOpenCustormers = customers; return(_untypedSimpleOpenCustormers); }
public void WriteObjectInline_Can_WriteCollectionOfIEdmObjects() { // Arrange IEdmTypeReference edmType = new EdmEntityTypeReference(new EdmEntityType("NS", "Name"), isNullable: false); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(edmType)); Mock <IEdmObject> edmObject = new Mock <IEdmObject>(); edmObject.Setup(e => e.GetEdmType()).Returns(edmType); var mockWriter = new Mock <ODataWriter>(); Mock <ODataEdmTypeSerializer> customSerializer = new Mock <ODataEdmTypeSerializer>(ODataPayloadKind.Resource); customSerializer.Setup(s => s.WriteObjectInline(edmObject.Object, edmType, mockWriter.Object, _writeContext)).Verifiable(); Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); serializerProvider.Setup(s => s.GetEdmTypeSerializer(edmType)).Returns(customSerializer.Object); ODataResourceSetSerializer serializer = new ODataResourceSetSerializer(serializerProvider.Object); // Act serializer.WriteObjectInline(new[] { edmObject.Object }, collectionType, mockWriter.Object, _writeContext); // Assert customSerializer.Verify(); }
public void CreateODataCollectionValue_CanSerialize_IEdmObjects() { // Arrange Mock <IEdmComplexObject> edmComplexObject = new Mock <IEdmComplexObject>(); IEdmComplexObject[] collection = new IEdmComplexObject[] { edmComplexObject.Object }; ODataSerializerContext serializerContext = new ODataSerializerContext(); IEdmComplexTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "ComplexType"), isNullable: true); edmComplexObject.Setup(s => s.GetEdmType()).Returns(elementType); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType)); Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); Mock <ODataComplexTypeSerializer> elementSerializer = new Mock <ODataComplexTypeSerializer>(MockBehavior.Strict, serializerProvider.Object); serializerProvider.Setup(s => s.GetEdmTypeSerializer(elementType)).Returns(elementSerializer.Object); elementSerializer.Setup(s => s.CreateODataComplexValue(collection[0], elementType, serializerContext)).Returns(new ODataComplexValue()).Verifiable(); ODataCollectionSerializer serializer = new ODataCollectionSerializer(serializerProvider.Object); // Act var result = serializer.CreateODataCollectionValue(collection, elementType, serializerContext); // Assert elementSerializer.Verify(); }
private static void BuildOrderss(IEdmModel model) { IEdmEntityType orderType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Order"); Guid[] guids = { new Guid("196B3584-EF3D-41FD-90B4-76D59F9B929C"), new Guid("6CED5600-28BA-40EE-A2DF-E80AFADBE6C7"), new Guid("75036B94-C836-4946-8CC8-054CF54060EC"), new Guid("B3FF5460-6E77-4678-B959-DCC1C4937FA7"), new Guid("ED773C85-4E3C-4FC4-A3E9-9F1DA0A626DA") }; IEdmEntityObject[] untypedOrders = new IEdmEntityObject[5]; for (int i = 0; i < 5; i++) { dynamic untypedOrder = new EdmEntityObject(orderType); untypedOrder.OrderId = i; untypedOrder.Name = string.Format("Order-{0}", i); untypedOrder.Token = guids[i]; untypedOrder.Amount = 10 + i; untypedOrders[i] = untypedOrder; } IEdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference( new EdmCollectionType( new EdmEntityTypeReference(orderType, isNullable: false))); Orders = new EdmEntityObjectCollection(entityCollectionType, untypedOrders.ToList()); }
private static void BuildCustomers(IEdmModel model) { IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "Customer"); IEdmEntityObject[] untypedCustomers = new IEdmEntityObject[6]; for (int i = 1; i <= 5; i++) { dynamic untypedCustomer = new EdmEntityObject(customerType); untypedCustomer.ID = i; untypedCustomer.Name = string.Format("Name {0}", i); untypedCustomer.SSN = "SSN-" + i + "-" + (100 + i); untypedCustomers[i - 1] = untypedCustomer; } // create a special customer for "PATCH" dynamic customer = new EdmEntityObject(customerType); customer.ID = 6; customer.Name = "Name 6"; customer.SSN = "SSN-6-T-006"; untypedCustomers[5] = customer; IEdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference( new EdmCollectionType( new EdmEntityTypeReference(customerType, isNullable: false))); Customers = new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList()); }
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true); IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First(); EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = new ODataSerializerContext { NavigationSource = model.Customers, Model = model.Model } }; ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, ordersProperty); TruncatedCollection <Order> orders = new TruncatedCollection <Order>(new[] { new Order(), new Order() }, pageSize: 1); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(); linkBuilder.AddNavigationPropertyLinkBuilder(ordersProperty, new NavigationLinkBuilder((entityContext, navigationProperty) => new Uri("http://navigation-link/"), false)); model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder); model.Model.SetNavigationSourceLinkBuilder(model.Orders, new NavigationSourceLinkBuilderAnnotation()); // Act ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext); // Assert Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri); }
private EdmFunction BuildFunction(OeOperationConfiguration operationConfiguration, Dictionary <Type, EntityTypeInfo> entityTypeInfos) { IEdmTypeReference edmTypeReference; Type itemType = Parsers.OeExpressionHelper.GetCollectionItemTypeOrNull(operationConfiguration.ReturnType); if (itemType == null) { edmTypeReference = GetEdmTypeReference(operationConfiguration.ReturnType, entityTypeInfos); } else { edmTypeReference = new EdmCollectionTypeReference(new EdmCollectionType(GetEdmTypeReference(itemType, entityTypeInfos))); } var edmFunction = new EdmFunction(operationConfiguration.NamespaceName, operationConfiguration.Name, edmTypeReference, operationConfiguration.IsBound, null, false); foreach (OeOperationParameterConfiguration parameterConfiguration in operationConfiguration.Parameters) { edmTypeReference = GetEdmTypeReference(parameterConfiguration.ClrType, entityTypeInfos); edmFunction.AddParameter(parameterConfiguration.Name, edmTypeReference); } return(edmFunction); }
public IActionResult Get() { IEdmCollectionType collectionType; ODataPath oDataPath = Request.ODataFeature().Path; IEdmType edmType = oDataPath.Segments.First().EdmType; IEdmEntityType entityType; if (edmType is IEdmCollectionType ct) { collectionType = ct; entityType = collectionType.ElementType.Definition as IEdmEntityType; } else { throw new Exception($"Unexpected EDM type '{edmType?.GetType()}'."); } IEnumerable <IEdmEntityObject> entityObjects = this.GetData(entityType); IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType); StreamingEdmEntityObjectCollection collection = new StreamingEdmEntityObjectCollection (collectionTypeReference , entityObjects ); // // Return a collection type. // return(Ok(collection)); }
public void ApplyNavigationProperty_Calls_ReadInlineOnFeed() { // Arrange IEdmCollectionTypeReference productsType = new EdmCollectionTypeReference(new EdmCollectionType(_productEdmType)); Mock <ODataEdmTypeDeserializer> productsDeserializer = new Mock <ODataEdmTypeDeserializer>(ODataPayloadKind.Feed); Mock <ODataDeserializerProvider> deserializerProvider = new Mock <ODataDeserializerProvider>(); var deserializer = new ODataEntityDeserializer(deserializerProvider.Object); ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" }); navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed())); Supplier supplier = new Supplier(); IEnumerable products = new[] { new Product { ID = 42 } }; deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny <IEdmTypeReference>())).Returns(productsDeserializer.Object); productsDeserializer .Setup(d => d.ReadInline(navigationLink.NestedItems[0], _supplierEdmType.FindNavigationProperty("Products").Type, _readContext)) .Returns(products).Verifiable(); // Act deserializer.ApplyNavigationProperty(supplier, navigationLink, _supplierEdmType, _readContext); // Assert productsDeserializer.Verify(); Assert.Equal(1, supplier.Products.Count()); Assert.Equal(42, supplier.Products.First().ID); }
public void CreateEdmTypeSchemaReturnSchemaForNullableCollectionPrimitiveType() { // Arrange IEdmModel model = EdmCoreModel.Instance; ODataContext context = new ODataContext(model); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference( new EdmCollectionType(EdmCoreModel.Instance.GetInt32(true))); // Act var schema = context.CreateEdmTypeSchema(collectionType); Assert.NotNull(schema); string json = schema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); // & Assert Assert.Equal(@"{ ""type"": ""array"", ""items"": { ""maximum"": 2147483647, ""minimum"": -2147483648, ""type"": ""integer"", ""format"": ""int32"", ""nullable"": true } }".ChangeLineBreaks(), json); }
public object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { ODataMessageReaderSettings oDataReaderSettings = Request.GetReaderSettings(); ODataPath path = Request.ODataProperties().Path; IEdmModel edmModel = Request.GetModel(); ODataDeserializerContext readContext = new ODataDeserializerContext { Path = path, Model = edmModel, Request = this.Request, ResourceType = type, // ResourceEdmType = edmTypeReference, }; var edmType = edmModel.SchemaElements.OfType <IEdmEntityType>().FirstOrDefault(c => c.Name == "Like"); var edmTypeReference = new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(edmType, false))); IODataRequestMessage oDataRequestMessage = new ODataMessageWrapper(readStream, null); using ( ODataMessageReader oDataMessageReader = new ODataMessageReader(oDataRequestMessage, oDataReaderSettings, readContext.Model)) { return(ConvertResourceSet(oDataMessageReader, edmTypeReference, readContext, this.Request)); } }
public void AsCollectionOrNullForNonCollectionOfEntityShouldBeNull() { IEdmTypeReference typeReference = new EdmCollectionTypeReference(new EdmCollectionType(productTypeReference)); IEdmCollectionTypeReference collectionTypeReference = typeReference.AsCollectionOrNull(); collectionTypeReference.Should().BeNull(); }
public async Task WriteObjectInlineAsync_Can_WriteCollectionOfIEdmChangedObjects() { // Arrange IEdmTypeReference edmType = new EdmEntityTypeReference(new EdmEntityType("NS", "Name"), isNullable: false); IEdmCollectionTypeReference feedType = new EdmCollectionTypeReference(new EdmCollectionType(edmType)); Mock <IEdmChangedObject> edmObject = new Mock <IEdmChangedObject>(); edmObject.Setup(e => e.GetEdmType()).Returns(edmType); var mockWriter = new Mock <ODataWriter>(); Mock <ODataSerializerProvider> provider = new Mock <ODataSerializerProvider>(); Mock <ODataResourceSerializer> customerSerializer = new Mock <ODataResourceSerializer>(provider.Object); customerSerializer.Setup(s => s.WriteDeltaObjectInlineAsync(edmObject.Object, edmType, mockWriter.Object, _writeContext)).Verifiable(); Mock <ODataSerializerProvider> serializerProvider = new Mock <ODataSerializerProvider>(); serializerProvider.Setup(s => s.GetEdmTypeSerializer(edmType)).Returns(customerSerializer.Object); ODataDeltaResourceSetSerializer serializer = new ODataDeltaResourceSetSerializer(serializerProvider.Object); // Act await serializer.WriteObjectInlineAsync(new[] { edmObject.Object }, feedType, mockWriter.Object, _writeContext); // Assert customerSerializer.Verify(); }
public IHttpActionResult Get(int key) { EdmEntityType customerType = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true); customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32)); EdmEntityObject customer = new EdmEntityObject(customerType); customer.TrySetPropertyValue("CustomerId", 1); EdmEnumType colorType = new EdmEnumType("NS", "Color"); colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(0))); EdmEnumObject color = new EdmEnumObject(colorType, "Red"); EdmEnumObject color2 = new EdmEnumObject(colorType, "0"); customer.TrySetPropertyValue("Color", color); List <IEdmEnumObject> colorList = new List <IEdmEnumObject>(); colorList.Add(color); colorList.Add(color2); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false))); EdmEnumObjectCollection colors = new EdmEnumObjectCollection(collectionType, colorList); customer.TrySetPropertyValue("Colors", colors); return(Ok(customer)); }
private static object ConvertCollectionValue(ODataCollectionValue collection, ref IEdmTypeReference propertyType, IODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext) { IEdmCollectionTypeReference collectionType; if (propertyType == null) { // dynamic collection property Contract.Assert(!String.IsNullOrEmpty(collection.TypeName), "ODataLib should have verified that dynamic collection value has a type name " + "since we provided metadata."); string elementTypeName = GetCollectionElementTypeName(collection.TypeName, isNested: false); IEdmModel model = readContext.Model; IEdmSchemaType elementType = model.FindType(elementTypeName); Contract.Assert(elementType != null); collectionType = new EdmCollectionTypeReference( new EdmCollectionType(elementType.ToEdmTypeReference(isNullable: false))); propertyType = collectionType; } else { collectionType = propertyType as IEdmCollectionTypeReference; Contract.Assert(collectionType != null, "The type for collection must be a IEdmCollectionType."); } IODataEdmTypeDeserializer deserializer = deserializerProvider.GetEdmTypeDeserializer(collectionType); return(deserializer.ReadInline(collection, collectionType, readContext)); }
public NonPrimitiveTypeRoundtripAtomTests() { this.model = new EdmModel(); EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo"); personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16); personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String); personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String); personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid); EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject"); subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16); EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable: true))); EdmEntityType studentInfo = new EdmEntityType(MyNameSpace, "Student"); studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false)); studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection)); EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))); studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection)); model.AddElement(studentInfo); model.AddElement(personalInfo); model.AddElement(subjectInfo); }
public void CollectionType_IsDeltaFeed_ReturnsFalseForNonDeltaCollectionType() { IEdmEntityType _entityType = new EdmEntityType("NS", "Entity"); EdmCollectionType _edmType = new EdmCollectionType(new EdmEntityTypeReference(_entityType, isNullable: true)); IEdmCollectionTypeReference _edmTypeReference = new EdmCollectionTypeReference(_edmType); Assert.False(_edmTypeReference.Definition.IsDeltaFeed()); }
public LocalizedTextDataType(IODataObjectFactory oDataObjectFactory) { this.oDataObjectFactory = oDataObjectFactory; this.cultureValueTypeReference = CreateCultureValueTypeReference(); this.cultureValuesCollectionTypeReference = CreateCultureValuesCollectionTypeReference(this.cultureValueTypeReference); this.edmComplexType = CreateComplexType(this.cultureValuesCollectionTypeReference); }
public void Ctor_ThrowsArgument_UnexpectedElementType() { IEdmTypeReference elementType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType)); ExceptionAssert.ThrowsArgument(() => new EdmComplexObjectCollection(collectionType), "edmType", "The element type '[Edm.Int32 Nullable=True]' of the given collection type '[Collection([Edm.Int32 Nullable=True]) Nullable=True]' " + "is not of the type 'IEdmComplexType'."); }
public void GetEdmType_Returns_EdmTypeInitializedByCtor() { IEdmTypeReference elementType = new EdmComplexTypeReference(new EdmComplexType("NS", "Complex"), isNullable: false); IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType)); var edmObject = new EdmComplexObjectCollection(collectionType); Assert.Same(collectionType, edmObject.GetEdmType()); }
private static EdmComplexType CreateComplexType(EdmCollectionTypeReference valuesCollectionTypeReference) { var type = new EdmComplexType("facton", "LocalizedText"); type.AddStructuralProperty("InvariantValue", EdmPrimitiveTypeKind.String, true); type.AddStructuralProperty("CultureValues", valuesCollectionTypeReference); return(type); }