Пример #1
0
        public void EdmComplexObject_IsDeltaFeed_ReturnsFalseForNonDeltaObject()
        {
            IEdmComplexType  _type      = new EdmComplexType("NS", "Entity");
            EdmComplexObject _edmObject = new EdmComplexObject(_type);

            Assert.False(_edmObject.IsDeltaResource());
        }
Пример #2
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return(_untypedSimpleOpenCustormers);
            }

            IEdmModel       edmModel     = OpenEntityTypeTest.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);
        }
Пример #3
0
        public IHttpActionResult 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);

            return(Ok(customer));
        }
Пример #4
0
 IEdmObject InvokeTVF(IEdmFunction func, JObject parameterValues, ODataQueryOptions queryOptions = null)
 {
     IEdmType edmType = func.ReturnType.Definition;
     IEdmType elementType = (edmType as IEdmCollectionType).ElementType.Definition;
     EdmComplexObjectCollection collection = new EdmComplexObjectCollection(new EdmCollectionTypeReference(edmType as IEdmCollectionType));
     var target = BuildTVFTarget(func, parameterValues);
     var cmd = BuildSqlQueryCmd(queryOptions, target);
     using (DbAccess db = new DbAccess(this.ConnectionString))
     {
         db.ExecuteReader(cmd, (reader) =>
         {
             EdmComplexObject entity = new EdmComplexObject(elementType as IEdmComplexType);
             for (int i = 0; i < reader.FieldCount; i++)
             {
                 reader.SetEntityPropertyValue(i, entity);
             }
             collection.Add(entity);
         }, null, CommandType.Text);
     }
     return collection;
 }
Пример #5
0
        IEdmObject InvokeFuncComplex(IEdmFunction func, JObject parameterValues, ODataQueryOptions queryOptions = null)
        {
            IEdmType edmType = func.ReturnType.Definition;
            IEdmType elementType = null;
            var rtv = new EdmComplexObject(edmType as IEdmComplexType);
            object obj;
            rtv.TryGetPropertyValue("$Results", out obj);
            EdmComplexObjectCollection collection = obj as EdmComplexObjectCollection;
            var colltype = (edmType as IEdmComplexType).FindProperty("$Results").Type.Definition;
            elementType = (colltype as IEdmCollectionType).ElementType.Definition;
            using (DbAccess db = new DbAccess(this.ConnectionString))
            {
                var par = db.ExecuteReader(func.Name, (reader) =>
                  {
                      EdmComplexObject entity = new EdmComplexObject(elementType as IEdmComplexType);
                      for (int i = 0; i < reader.FieldCount; i++)
                      {
                          reader.SetEntityPropertyValue(i, entity);
                      }
                      collection.Add(entity);
                  }, (pars) =>
                  {
                      SetParameter(func, parameterValues, edmType, pars);
                      var d1 = this.ParameterInfos[func.Name];
                      foreach (var p in (edmType as IEdmComplexType).Properties())
                      {
                          if (p.Name == "$Results")
                              continue;
                          var pp = d1[p.Name];
                          pars.Add(new SqlParameter(p.Name, pp.SqlDbType, pp.Length)
                          {
                              Direction = ParameterDirection.Output
                          });
                      }

                  });
                foreach (var outp in (edmType as IEdmComplexType).Properties())
                {
                    if (outp.Name == "$Results")
                        continue;
                    var v = par[outp.Name].Value;
                    if (DBNull.Value != v)
                        rtv.TrySetPropertyValue(outp.Name, v);
                }
            }
            return rtv;
        }
Пример #6
0
 IEdmObject InvokeFuncCollection(IEdmFunction func, JObject parameterValues, ODataQueryOptions queryOptions = null)
 {
     IEdmType edmType = func.ReturnType.Definition;
     IEdmType elementType = (edmType as IEdmCollectionType).ElementType.Definition;
     EdmComplexObjectCollection collection = new EdmComplexObjectCollection(new EdmCollectionTypeReference(edmType as IEdmCollectionType));
     using (DbAccess db = new DbAccess(this.ConnectionString))
     {
         db.ExecuteReader(func.Name, (reader) =>
         {
             EdmComplexObject entity = new EdmComplexObject(elementType as IEdmComplexType);
             for (int i = 0; i < reader.FieldCount; i++)
             {
                 reader.SetEntityPropertyValue(i, entity);
             }
             collection.Add(entity);
         }, (pars) =>
         {
             SetParameter(func, parameterValues, edmType, pars);
         });
     }
     return collection;
 }
        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();
        }
 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;
 }
Пример #10
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return(_untypedSimpleOpenCustormers);
            }
            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);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            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");
            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 = new EdmComplexType("NS", "Address", null, false, true);

            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);

            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);
        }
Пример #11
0
        private static EdmEntityObjectCollection GetCustomers()
        {
            if (_untypedSimpleOpenCustormers != null)
            {
                return _untypedSimpleOpenCustormers;
            }
            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);

            //Add Numbers primitive collection property
            customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });

            //Add Color, Colors enum(collection) property
            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");
            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 = new EdmComplexType("NS", "Address", null, false, true);
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);

            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;
        }