public void TestGetTrendedAttributes()
        {
            var response = @"{
            ""total"": 1,           
            ""items"": [" + Attribute + @"],
            ""self"": ""https://hostname/api/v2/objects/" + mockid + @"/trendedAttributes""
            ";

            httpTest.RespondWith(response);
            httpTest.RespondWith(AttributeDetail);
            var trendedAttributes = client.Trends.GetTrendedAttributes(mockid);

            httpTest.ShouldHaveCalled($"https://hostname/api/v2/objects/{mockid}/trendedAttributes")
            .WithVerb(HttpMethod.Get)
            .Times(1);
            httpTest.ShouldHaveCalled($"https://hostname/api/v2/enumSets/509/members/85")
            .WithVerb(HttpMethod.Get)
            .Times(1);
            // SDK Object matching the responsee
            var attribute = new MetasysAttribute
            {
                Id          = 85,
                Description = "Present Value"
            };

            Assert.AreEqual(attribute, trendedAttributes.ElementAt(0));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <List <MetasysAttribute> > GetTrendedAttributesAsync(Guid id)
        {
            List <MetasysAttribute> objectAttributes = new List <MetasysAttribute>();
            // Perform a generic call using objects resource valid for Network Devices as well
            JToken attributes = (await GetRequestAsync("objects", null, id, "trendedAttributes").ConfigureAwait(false));

            // Read full attribute from url
            if (!(attributes["items"] is JArray))
            {
                // This structure applies since v3-pre release
                if (attributes["items"]["item"] != null)
                {
                    attributes["items"] = attributes["items"]["item"];
                }
            }
            foreach (var a in attributes["items"])
            {
                try
                {
                    MetasysAttribute metasysAttribute = new MetasysAttribute();
                    if (Version < ApiVersion.v3)
                    {
                        var attributeUrl = a["attributeUrl"].Value <string>();
                        var attribute    = await GetWithFullUrl(attributeUrl).ConfigureAwait(false);

                        metasysAttribute.Id          = attribute["id"].Value <int>();
                        metasysAttribute.Description = attribute["description"].Value <string>();
                    }
                    else
                    {
                        // Since Api v3 the schema has changed and contains the enum fully qualified name instead of the URL
                        metasysAttribute.Description = a["attribute"].Value <string>();
                        // Take the attribute ID from the samples url
                        var samplesUrl = a["samplesUrl"].Value <string>();
                        var attrId     = samplesUrl.Split('/').Reverse().Skip(1).FirstOrDefault();
                        metasysAttribute.Id = int.Parse(attrId);
                    }
                    objectAttributes.Add(metasysAttribute);
                }
                catch (ArgumentNullException e)
                {
                    // Something went wrong on object parsing
                    throw new MetasysObjectException(e);
                }
            }
            return(objectAttributes);
        }