Beispiel #1
0
        private async Task <Response <T> > Get <T>(Type get, string id, OdataQuery odata)
        {
            var idString = string.IsNullOrEmpty(id) ? "" : $"({id})";

            var url = $"{_homedoc.GetUrlByEntityName(get.GetString(true))}{idString}";

            url = odata != null?odata.AppendOdataQueryToUrl(url) : url;

            return(await Http.GetJson <T>(url));
        }
Beispiel #2
0
        private async Task <Response <T> > Get <T>(Type get, Type by, string id, OdataQuery odata)
        {
            if (by == null)
            {
                throw new ArgumentNullException(nameof(by));
            }
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("ID is required", nameof(id));
            }
            var url = $"{_homedoc.GetUrlByEntityName(by.GetString(true))}({id})/{get.GetString(by)}";

            url = odata != null?odata.AppendOdataQueryToUrl(url) : url;

            return(await Http.GetJson <T>(url));
        }
Beispiel #3
0
        public void OdataQueryTest()
        {
            // prepare
            var odataQuery1 = new OdataQuery
            {
                QuerySelect = new QuerySelect(new[] { "name" }),
                QueryFilter = new QueryFilter("name eq 'test'")
            };

            var odataQuery2 = new OdataQuery
            {
                QuerySelect = new QuerySelect(new[] { "id", "result" }),
                QueryTop    = new QueryTop(5)
            };

            var odataQuery = new OdataQuery
            {
                QuerySelect  = new QuerySelect(new[] { "id", "name" }),
                QueryTop     = new QueryTop(5),
                QuerySkip    = new QuerySkip(1),
                QueryCount   = new QueryCount(true),
                QueryFilter  = new QueryFilter("name eq 'test'"),
                QueryOrderBy = new QueryOrderBy(new Dictionary <string, OrderType> {
                    { "name", OrderType.Descending }
                }),
                QueryExpand = new QueryExpand(new[]
                {
                    new Expand(new[] { "Datastreams" }, odataQuery1),
                    new Expand(new[] { "Datastreams", "Observations" }, odataQuery2)
                }
                                              )
            };

            Assert.AreEqual(7, odataQuery.GetOdataQueryStrings().Count());
            Assert.AreEqual("http://stserver/v1.0/Things?$expand=Datastreams($select=name;$filter=name eq 'test'),Datastreams/Observations($select=id,result;$top=5)&$select=id,name&$filter=name eq 'test'&$orderby=name desc&$top=5&$skip=1&$count=true", odataQuery.AppendOdataQueryToUrl("http://stserver/v1.0/Things"));
        }