public bool ComplexCollectionFunction(int key, [FromODataUri] EdmComplexObjectCollection addresses)
        {
            Assert.NotNull(addresses);
            IList <IEdmComplexObject> results = addresses.ToList();

            Assert.Equal(2, results.Count);

            // #1
            EdmComplexObject complex = results[0] as EdmComplexObject;

            Assert.Equal("NS.Address", complex.GetEdmType().FullName());

            dynamic address = results[0];

            Assert.NotNull(address);
            Assert.Equal("NE 24th St.", address.Street);
            Assert.Equal("Redmond", address.City);

            // #2
            complex = results[1] as EdmComplexObject;
            Assert.Equal("NS.SubAddress", complex.GetEdmType().FullName());

            address = results[1];
            Assert.NotNull(address);
            Assert.Equal("LianHua Rd.", address.Street);
            Assert.Equal("Shanghai", address.City);
            Assert.Equal(9.9, address.Code);
            return(true);
        }
        public void EdmComplexObject_IsDeltaFeed_ReturnsFalseForNonDeltaObject()
        {
            IEdmComplexType  _type      = new EdmComplexType("NS", "Entity");
            EdmComplexObject _edmObject = new EdmComplexObject(_type);

            Assert.False(_edmObject.IsDeltaResource());
        }
        public bool EntityFunction(int key, [FromODataUri] EdmEntityObject customer)
        {
            Assert.NotNull(customer);
            dynamic result = customer;

            Assert.Equal("NS.Customer", customer.GetEdmType().FullName());

            // entity call
            if (key == 9)
            {
                Assert.Equal(91, result.Id);
                Assert.Equal("John", result.Name);

                dynamic          address    = result.Location;
                EdmComplexObject addressObj = Assert.IsType <EdmComplexObject>(address);
                Assert.Equal("NS.Address", addressObj.GetEdmType().FullName());
                Assert.Equal("NE 24th St.", address.Street);
                Assert.Equal("Redmond", address.City);
            }
            else
            {
                // entity reference call
                Assert.Equal(8, result.Id);
                Assert.Equal("Id", String.Join(",", customer.GetChangedPropertyNames()));

                Assert.Equal("Name,Location", String.Join(",", customer.GetUnchangedPropertyNames()));
            }

            return(true);
        }
Beispiel #4
0
        /// <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
            });
        }
Beispiel #5
0
        IEdmComplexObject Map(IEdmModel model, ComplexPoly p)
        {
            var type = (IEdmComplexType)GetType(model, p.GetType());

            var co = new EdmComplexObject(type);

            co.TrySetPropertyValue("Name", p.Name);

            var b = p as ComplexPolyB;

            if (b != null)
            {
                co.TrySetPropertyValue("Prop1", b.Prop1);
                co.TrySetPropertyValue("Prop2", b.Prop2);
                co.TrySetPropertyValue("Prop3", b.Prop3);
                co.TrySetPropertyValue("Prop4", b.Prop4);
            }

            var c = p as ComplexPolyC;

            if (c != null)
            {
                co.TrySetPropertyValue("Taste", c.Taste);
            }

            return(co);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        private static void ParseComponent(EdmEntityObject entity, ComponentHelpClass item, object value)
        {
            int i = 0;

            EdmStructuredObject actualEntity = entity;

            for (i = 0; i < item.Depth - 1; i++)
            {
                var    componentName = item.SplitedComponents[i];
                object local         = null;
                actualEntity.TryGetPropertyValue(componentName, out local);
                if (local == null)
                {
                    var declaredProperty = actualEntity.ActualEdmType.DeclaredProperties.FirstOrDefault(w => w.Name == componentName);
                    var edmComplexObject = new EdmComplexObject(declaredProperty.Type.AsComplex());

                    actualEntity.TrySetPropertyValue(componentName, edmComplexObject);
                    actualEntity = edmComplexObject;
                }
                else
                {
                    actualEntity = (EdmStructuredObject)local;
                }
            }

            var propertyName = item.SplitedComponents[item.Depth - 1];

            actualEntity.TrySetPropertyValue(propertyName, value);
        }
        public bool ComplexFunction(int key, [FromODataUri] EdmComplexObject address)
        {
            Assert.NotNull(address);
            dynamic result = address;

            Assert.Equal("NS.Address", address.GetEdmType().FullName());
            Assert.Equal("NE 24th St.", result.Street);
            Assert.Equal("Redmond", result.City);
            return(true);
        }
 private dynamic CreateAddress(int j)
 {
     dynamic address = new EdmComplexObject(AddressType);
     address.FirstLine = "First line " + j;
     address.SecondLine = "Second line " + j;
     address.ZipCode = j;
     address.City = "City " + j;
     address.State = "State " + j;
     return address;
 }
 private dynamic CreateAddresses(int i)
 {
     EdmComplexObject[] addresses = new EdmComplexObject[i];
     for (int j = 0; j < i; j++)
     {
         dynamic complexObject = CreateAddress(j);
         addresses[j] = complexObject;
     }
     var collection = new EdmComplexObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(AddressType, false))), addresses);
     return collection;
 }
Beispiel #11
0
        private static IList <IEdmComplexObject> BuildAddrsses(IEdmModel model)
        {
            IEdmComplexType addressType = model.SchemaElements.OfType <IEdmComplexType>().First(e => e.Name == "Address");

            return(Enumerable.Range(1, 5).Select(e =>
            {
                dynamic address = new EdmComplexObject(addressType);
                address.Street = new[] { "Fuxing Rd", "Zixing Rd", "Xiaoxiang Rd", "Kehua Rd", "Taoyuan Rd" }[e - 1];
                address.City = new[] { "Beijing", "Shanghai", "Guangzhou", "Chengdu", "Wuhan" }[e - 1];
                return address as IEdmComplexObject;
            }).ToList());
        }
        public void CtorEdmComplexObject_SetProperties(bool isNullable)
        {
            // Arrange
            EdmComplexType           complexType = new EdmComplexType("NS", "Complex");
            IEdmComplexTypeReference complex     = new EdmComplexTypeReference(complexType, isNullable);

            // Act
            EdmComplexObject edmObject = new EdmComplexObject(complex);

            // Assert
            Assert.Same(complexType, edmObject.ExpectedEdmType);
            Assert.Same(complexType, edmObject.ActualEdmType);
            Assert.Equal(isNullable, edmObject.IsNullable);
        }
Beispiel #13
0
        public void CreateResource_CreatesEdmComplexObject_UnTypedMode()
        {
            // Arrange
            ODataDeserializerContext context = new ODataDeserializerContext {
                ResourceType = typeof(IEdmObject)
            };

            // Act
            var resource = ODataComplexTypeDeserializer.CreateResource(_addressEdmType, context);

            // Assert
            EdmComplexObject complexObject = Assert.IsType <EdmComplexObject>(resource);

            Assert.Equal(_addressEdmType, complexObject.GetEdmType(), new EdmTypeReferenceEqualityComparer());
        }
        public void CreateResourceInstance_CreatesEdmComplexObject_IfTypeLessMode()
        {
            // Arrange
            var deserializer = new ODataResourceDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model        = _readContext.Model,
                ResourceType = typeof(IEdmObject)
            };

            // Act
            var result = deserializer.CreateResourceInstance(_addressEdmType, readContext);

            // Assert
            EdmComplexObject resource = Assert.IsType <EdmComplexObject>(result);

            Assert.Equal(_addressEdmType, resource.GetEdmType(), new EdmTypeReferenceEqualityComparer());
        }
        public ODataDeltaResourceSetSerializerTests()
        {
            _model       = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _path      = new ODataPath(new EntitySetSegment(_customerSet));
            _customers = new[] {
                new Customer()
                {
                    FirstName   = "Foo",
                    LastName    = "Bar",
                    ID          = 10,
                    HomeAddress = new Address()
                    {
                        Street  = "Street",
                        ZipCode = null,
                    }
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName  = "Bar",
                    ID        = 42,
                }
            };

            _deltaResourceSetCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
            EdmDeltaResourceObject newCustomer = new EdmDeltaResourceObject(_customerSet.EntityType());

            newCustomer.TrySetPropertyValue("ID", 10);
            newCustomer.TrySetPropertyValue("FirstName", "Foo");
            EdmComplexObject newCustomerAddress = new EdmComplexObject(_model.FindType("Default.Address") as IEdmComplexType);

            newCustomerAddress.TrySetPropertyValue("Street", "Street");
            newCustomerAddress.TrySetPropertyValue("ZipCode", null);
            newCustomer.TrySetPropertyValue("HomeAddress", newCustomerAddress);
            _deltaResourceSetCustomers.Add(newCustomer);

            _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();
            _writeContext  = new ODataSerializerContext()
            {
                NavigationSource = _customerSet, Model = _model, Path = _path
            };
        }
Beispiel #16
0
        private EdmEntityObjectCollection GetCustomers()
        {
            IEdmModel edmModel = Request.ODataProperties().Model;

            IEdmEntityType  customerType = edmModel.SchemaElements.OfType <IEdmEntityType>().Single(e => e.Name == "Customer");
            IEdmEnumType    colorType    = edmModel.SchemaElements.OfType <IEdmEnumType>().Single(e => e.Name == "Color");
            IEdmComplexType addressType  = edmModel.SchemaElements.OfType <IEdmComplexType>().Single(e => e.Name == "Address");

            // an enum object
            EdmEnumObject color = new EdmEnumObject(colorType, "Red");

            // a complex object
            EdmComplexObject address1 = new EdmComplexObject(addressType);

            address1.TrySetPropertyValue("Street", "ZiXing Rd");                                            // Declared property
            address1.TrySetPropertyValue("StringProperty", "CN");                                           // a string dynamic property
            address1.TrySetPropertyValue("GuidProperty", new Guid("181D3A20-B41A-489F-9F15-F91F0F6C9ECA")); // a guid dynamic property

            // another complex object with complex dynamic property
            EdmComplexObject address2 = new EdmComplexObject(addressType);

            address2.TrySetPropertyValue("Street", "ZiXing Rd");       // Declared property
            address2.TrySetPropertyValue("AddressProperty", address1); // a complex dynamic property

            // an entity object
            EdmEntityObject customer = new EdmEntityObject(customerType);

            customer.TrySetPropertyValue("CustomerId", 1);      // Declared property
            customer.TrySetPropertyValue("Name", "Mike");       // Declared property
            customer.TrySetPropertyValue("Color", color);       // an enum dynamic property
            customer.TrySetPropertyValue("Address1", address1); // a complex dynamic property
            customer.TrySetPropertyValue("Address2", address2); // another complex dynamic property

            // a collection with one object
            EdmEntityObjectCollection collection =
                new EdmEntityObjectCollection(
                    new EdmCollectionTypeReference(
                        new EdmCollectionType(new EdmEntityTypeReference(customerType, isNullable: true))));

            collection.Add(customer);

            return(collection);
        }
Beispiel #17
0
        public async Task ReadAsync_ReturnsEdmComplexObjectCollection_TypelessMode()
        {
            // Arrange
            IEdmTypeReference           addressType           = _model.GetEdmTypeReference(typeof(Address)).AsComplex();
            IEdmCollectionTypeReference addressCollectionType =
                new EdmCollectionTypeReference(new EdmCollectionType(addressType));

            HttpContent      content    = new StringContent("{ 'value': [ {'@odata.type':'Microsoft.AspNetCore.OData.Tests.Models.Address', 'City' : 'Redmond' } ] }");
            HeaderDictionary headerDict = new HeaderDictionary
            {
                { "Content-Type", "application/json" }
            };

            IODataRequestMessage request         = ODataMessageWrapperHelper.Create(await content.ReadAsStreamAsync(), headerDict);
            ODataMessageReader   reader          = new ODataMessageReader(request, new ODataMessageReaderSettings(), _model);
            var deserializer                     = new ODataResourceSetDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model           = _model,
                ResourceType    = typeof(IEdmObject),
                ResourceEdmType = addressCollectionType
            };

            // Act
            IEnumerable result = await deserializer.ReadAsync(reader, typeof(IEdmObject), readContext) as IEnumerable;

            // Assert
            var addresses = result.Cast <EdmComplexObject>();

            Assert.NotNull(addresses);

            EdmComplexObject address = Assert.Single(addresses);

            Assert.Equal(new[] { "City" }, address.GetChangedPropertyNames());

            object city;

            Assert.True(address.TryGetPropertyValue("City", out city));
            Assert.Equal("Redmond", city);
        }
Beispiel #18
0
        public void Read_ReturnsEdmComplexObjectCollection_TypelessMode()
        {
            // Arrange
            IEdmTypeReference           addressType           = _model.GetEdmTypeReference(typeof(Address)).AsComplex();
            IEdmCollectionTypeReference addressCollectionType =
                new EdmCollectionTypeReference(new EdmCollectionType(addressType));

            HttpContent content = new StringContent("{ 'value': [ {'@odata.type':'System.Web.OData.TestCommon.Models.Address', 'City' : 'Redmond' } ] }");

            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
            IODataRequestMessage request         = new ODataMessageWrapper(content.ReadAsStreamAsync().Result, content.Headers);
            ODataMessageReader   reader          = new ODataMessageReader(request, new ODataMessageReaderSettings(), _model);
            var deserializer                     = new ODataResourceSetDeserializer(_deserializerProvider);
            ODataDeserializerContext readContext = new ODataDeserializerContext
            {
                Model           = _model,
                ResourceType    = typeof(IEdmObject),
                ResourceEdmType = addressCollectionType
            };

            // Act
            IEnumerable result = deserializer.Read(reader, typeof(IEdmObject), readContext) as IEnumerable;

            // Assert
            var addresses = result.Cast <EdmComplexObject>();

            Assert.NotNull(addresses);

            EdmComplexObject address = Assert.Single(addresses);

            Assert.Equal(new[] { "City" }, address.GetChangedPropertyNames());

            object city;

            Assert.True(address.TryGetPropertyValue("City", out city));
            Assert.Equal("Redmond", city);
        }
Beispiel #19
0
 public static IODataComplexObject ToODataComplexObject(this EdmComplexObject edmComplexObject)
 {
     return(new EdmComplexObjectWrapper(edmComplexObject));
 }
        public bool CollectionEntityFunction(int key, [FromODataUri] EdmEntityObjectCollection customers)
        {
            Assert.NotNull(customers);
            IList <IEdmEntityObject> results = customers.ToList();

            Assert.Equal(2, results.Count);

            // entities call
            if (key == 9)
            {
                // #1
                EdmEntityObject entity = results[0] as EdmEntityObject;
                Assert.NotNull(entity);
                Assert.Equal("NS.Customer", entity.GetEdmType().FullName());

                dynamic customer = results[0];
                Assert.Equal(91, customer.Id);
                Assert.Equal("John", customer.Name);

                dynamic          address    = customer.Location;
                EdmComplexObject addressObj = Assert.IsType <EdmComplexObject>(address);
                Assert.Equal("NS.Address", addressObj.GetEdmType().FullName());
                Assert.Equal("NE 24th St.", address.Street);
                Assert.Equal("Redmond", address.City);

                // #2
                entity = results[1] as EdmEntityObject;
                Assert.Equal("NS.SpecialCustomer", entity.GetEdmType().FullName());

                customer = results[1];
                Assert.Equal(92, customer.Id);
                Assert.Equal("Mike", customer.Name);

                address    = customer.Location;
                addressObj = Assert.IsType <EdmComplexObject>(address);
                Assert.Equal("NS.SubAddress", addressObj.GetEdmType().FullName());
                Assert.Equal("LianHua Rd.", address.Street);
                Assert.Equal("Shanghai", address.City);
                Assert.Equal(9.9, address.Code);

                Assert.Equal(new Guid("883F50C5-F554-4C49-98EA-F7CACB41658C"), customer.Title);
            }
            else
            {
                // entity references call
                int id = 81;
                foreach (IEdmEntityObject edmObj in results)
                {
                    EdmEntityObject entity = edmObj as EdmEntityObject;
                    Assert.NotNull(entity);
                    Assert.Equal("NS.Customer", entity.GetEdmType().FullName());

                    dynamic customer = entity;
                    Assert.Equal(id++, customer.Id);
                    Assert.Equal("Id", String.Join(",", customer.GetChangedPropertyNames()));
                    Assert.Equal("Name,Location", String.Join(",", customer.GetUnchangedPropertyNames()));
                }
            }

            return(true);
        }
        protected virtual IEdmEntityObject BuildEdmEntityObject(Entity record, SavedQueryView view, IEnumerable <SavedQueryView.ViewColumn> viewColumns, EdmEntityTypeReference dataEntityTypeReference, EdmComplexTypeReference entityReferenceComplexTypeReference, EdmComplexTypeReference optionSetComplexTypeReference, string entityListIdString, string viewIdString)
        {
            if (record == null)
            {
                return(null);
            }

            var entityObject = new EdmEntityObject(dataEntityTypeReference);

            entityObject.TrySetPropertyValue(view.PrimaryKeyLogicalName, record.Id);

            foreach (var column in viewColumns)
            {
                var value = record.Attributes.Contains(column.LogicalName) ? record.Attributes[column.LogicalName] : null;

                if (value is AliasedValue)
                {
                    var aliasedValue = value as AliasedValue;
                    value = aliasedValue.Value;
                }

                if (column.Metadata == null)
                {
                    continue;
                }

                var propertyName = column.LogicalName;

                if (propertyName.Contains('.'))
                {
                    propertyName = string.Format("{0}-{1}", column.Metadata.EntityLogicalName, column.Metadata.LogicalName);
                }

                switch (column.Metadata.AttributeType)
                {
                case AttributeTypeCode.Money:
                    var     money      = value as Money;
                    decimal moneyValue = 0;
                    if (money != null)
                    {
                        moneyValue = money.Value;
                    }
                    entityObject.TrySetPropertyValue(propertyName, moneyValue);
                    break;

                case AttributeTypeCode.Customer:
                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Owner:
                    var entityReference = value as EntityReference;
                    if (entityReference == null)
                    {
                        continue;
                    }
                    var entityReferenceObject = new EdmComplexObject(entityReferenceComplexTypeReference);
                    entityReferenceObject.TrySetPropertyValue("Name", entityReference.Name);
                    entityReferenceObject.TrySetPropertyValue("Id", entityReference.Id);
                    entityObject.TrySetPropertyValue(propertyName, entityReferenceObject);
                    break;

                case AttributeTypeCode.State:
                    var stateOptionSet = value as OptionSetValue;
                    if (stateOptionSet == null)
                    {
                        continue;
                    }
                    var stateAttributeMetadata = column.Metadata as StateAttributeMetadata;
                    if (stateAttributeMetadata == null)
                    {
                        continue;
                    }
                    var stateOption = stateAttributeMetadata.OptionSet.Options.FirstOrDefault(o => o != null && o.Value != null && o.Value.Value == stateOptionSet.Value);
                    if (stateOption == null)
                    {
                        continue;
                    }
                    var stateLabel      = stateOption.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == LanguageCode) ?? stateOption.Label.GetLocalizedLabel();
                    var stateOptionName = stateLabel == null?stateOption.Label.GetLocalizedLabelString() : stateLabel.Label;

                    var stateOptionSetObject = new EdmComplexObject(optionSetComplexTypeReference);
                    stateOptionSetObject.TrySetPropertyValue("Name", stateOptionName);
                    stateOptionSetObject.TrySetPropertyValue("Value", stateOptionSet.Value);
                    entityObject.TrySetPropertyValue(propertyName, stateOptionSetObject);
                    break;

                case AttributeTypeCode.Picklist:
                    var optionSet = value as OptionSetValue;
                    if (optionSet == null)
                    {
                        continue;
                    }
                    var picklistAttributeMetadata = column.Metadata as PicklistAttributeMetadata;
                    if (picklistAttributeMetadata == null)
                    {
                        continue;
                    }
                    var option = picklistAttributeMetadata.OptionSet.Options.FirstOrDefault(o => o != null && o.Value != null && o.Value.Value == optionSet.Value);
                    if (option == null)
                    {
                        continue;
                    }
                    var label = option.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == LanguageCode) ?? option.Label.GetLocalizedLabel();
                    var name  = label == null?option.Label.GetLocalizedLabelString() : label.Label;

                    var optionSetObject = new EdmComplexObject(optionSetComplexTypeReference);
                    optionSetObject.TrySetPropertyValue("Name", name);
                    optionSetObject.TrySetPropertyValue("Value", optionSet.Value);
                    entityObject.TrySetPropertyValue(propertyName, optionSetObject);
                    break;

                case AttributeTypeCode.Status:
                    var statusOptionSet = value as OptionSetValue;
                    if (statusOptionSet == null)
                    {
                        continue;
                    }
                    var statusAttributeMetadata = column.Metadata as StatusAttributeMetadata;
                    if (statusAttributeMetadata == null)
                    {
                        continue;
                    }
                    var statusOption = statusAttributeMetadata.OptionSet.Options.FirstOrDefault(o => o != null && o.Value != null && o.Value.Value == statusOptionSet.Value);
                    if (statusOption == null)
                    {
                        continue;
                    }
                    var statusLabel      = statusOption.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == LanguageCode) ?? statusOption.Label.GetLocalizedLabel();
                    var statusOptionName = statusLabel == null?statusOption.Label.GetLocalizedLabelString() : statusLabel.Label;

                    var statusOptionSetObject = new EdmComplexObject(optionSetComplexTypeReference);
                    statusOptionSetObject.TrySetPropertyValue("Name", statusOptionName);
                    statusOptionSetObject.TrySetPropertyValue("Value", statusOptionSet.Value);
                    entityObject.TrySetPropertyValue(propertyName, statusOptionSetObject);
                    break;

                default:
                    entityObject.TrySetPropertyValue(propertyName, value);
                    break;
                }
                entityObject.TrySetPropertyValue("list-id", entityListIdString);
                entityObject.TrySetPropertyValue("view-id", viewIdString);
            }
            return(entityObject);
        }
 public bool ComplexFunctionOnAttribute(int key, [FromODataUri] EdmComplexObject address)
 {
     return(ComplexFunction(key, address));
 }
 public IHttpActionResult ComplexFunction(int key, [FromODataUri] EdmComplexObject address, [FromODataUri] EdmComplexObjectCollection addressList)
 {
     return(null);
 }
Beispiel #24
0
        public IActionResult PostUntypedSimpleOpenCustomer(EdmEntityObject customer)
        {
            // Verify there is a string dynamic property in OpenEntityType
            object nameValue;

            customer.TryGetPropertyValue("Name", out nameValue);
            Type nameType;

            customer.TryGetPropertyType("Name", out nameType);

            Assert.NotNull(nameValue);
            Assert.Equal(typeof(String), nameType);
            Assert.Equal("FirstName 6", nameValue);

            // Verify there is a collection of double dynamic property in OpenEntityType
            object doubleListValue;

            customer.TryGetPropertyValue("DoubleList", out doubleListValue);
            Type doubleListType;

            customer.TryGetPropertyType("DoubleList", out doubleListType);

            Assert.NotNull(doubleListValue);
            Assert.Equal(typeof(List <Double>), doubleListType);

            // Verify there is a collection of complex type dynamic property in OpenEntityType
            object addressesValue;

            customer.TryGetPropertyValue("Addresses", out addressesValue);

            Assert.NotNull(addressesValue);

            // Verify there is a complex type dynamic property in OpenEntityType
            object addressValue;

            customer.TryGetPropertyValue("Address", out addressValue);

            Type addressType;

            customer.TryGetPropertyType("Address", out addressType);

            Assert.NotNull(addressValue);
            Assert.Equal(typeof(EdmComplexObject), addressType);

            // Verify there is a collection of enum type dynamic property in OpenEntityType
            object favoriteColorsValue;

            customer.TryGetPropertyValue("FavoriteColors", out favoriteColorsValue);
            EdmEnumObjectCollection favoriteColors = favoriteColorsValue as EdmEnumObjectCollection;

            Assert.NotNull(favoriteColorsValue);
            Assert.NotNull(favoriteColors);
            Assert.Equal(typeof(EdmEnumObject), favoriteColors[0].GetType());

            // Verify there is an enum type dynamic property in OpenEntityType
            object favoriteColorValue;

            customer.TryGetPropertyValue("FavoriteColor", out favoriteColorValue);

            Assert.NotNull(favoriteColorValue);
            Assert.Equal("Red", ((EdmEnumObject)favoriteColorValue).Value);

            Type favoriteColorType;

            customer.TryGetPropertyType("FavoriteColor", out favoriteColorType);

            Assert.Equal(typeof(EdmEnumObject), favoriteColorType);

            // Verify there is a string dynamic property in OpenComplexType
            EdmComplexObject address = addressValue as EdmComplexObject;
            object           cityValue;

            address.TryGetPropertyValue("City", out cityValue);
            Type cityType;

            address.TryGetPropertyType("City", out cityType);

            Assert.NotNull(cityValue);
            Assert.Equal(typeof(String), cityType);
            Assert.Equal("City 6", cityValue); // It reads as ODataUntypedValue, and the RawValue is the string with the ""

            return(Ok(customer));
        }