public void GetMetricName_ReturnsExpected()
        {
            var opts  = new CloudFoundryForwarderOptions();
            var stats = new OpenCensusStats();
            var ep    = new SpringBootMetricWriter(opts, stats);

            IList <ITagKey> keys = new List <ITagKey>()
            {
                TagKey.Create("status"), TagKey.Create("exception"), TagKey.Create("method"), TagKey.Create("uri")
            };
            IList <ITagValue> values = new List <ITagValue>()
            {
                TagValue.Create("200"), TagValue.Create("None"), TagValue.Create("GET"), TagValue.Create("/foo/bar")
            };

            var tagDict = ep.GetTagKeysAndValues(keys, values);

            Assert.Equal("http.server.requests.mean.GET.200.foo.bar", ep.GetMetricName("http.server.requests", "mean", tagDict));
            Assert.Equal("http.server.requests.mean", ep.GetMetricName("http.server.requests", "mean", new Dictionary <string, string>()));

            keys = new List <ITagKey>()
            {
                TagKey.Create("foo"), TagKey.Create("bar")
            };
            values = new List <ITagValue>()
            {
                TagValue.Create("foo"), TagValue.Create("bar")
            };
            tagDict = ep.GetTagKeysAndValues(keys, values);
            Assert.Equal("http.server.requests.bar.foo", ep.GetMetricName("http.server.requests", null, tagDict));
        }
        public void GetTagKeysAndValues_ReturnsExpected()
        {
            var opts  = new CloudFoundryForwarderOptions();
            var stats = new OpenCensusStats();
            var ep    = new SpringBootMetricWriter(opts, stats);

            IList <ITagKey> keys = new List <ITagKey>()
            {
                TagKey.Create("status"), TagKey.Create("exception"), TagKey.Create("method"), TagKey.Create("uri")
            };
            IList <ITagValue> values = new List <ITagValue>()
            {
                TagValue.Create("v1"), TagValue.Create("v2"), TagValue.Create("v3"), TagValue.Create("v4")
            };

            var result = ep.GetTagKeysAndValues(keys, values);

            Assert.Equal("v1", result["status"]);
            Assert.Equal("v2", result["exception"]);
            Assert.Equal("v3", result["method"]);
            Assert.Equal("v4", result["uri"]);

            // Verify sorted
            var sortedKeys = result.Keys.ToList();

            Assert.Equal("exception", sortedKeys[0]);
            Assert.Equal("method", sortedKeys[1]);
            Assert.Equal("status", sortedKeys[2]);
            Assert.Equal("uri", sortedKeys[3]);

            values = new List <ITagValue>()
            {
                TagValue.Create("v1"), null, null, null
            };

            result = ep.GetTagKeysAndValues(keys, values);
            Assert.Equal("v1", result["status"]);
            Assert.Single(result);

            values = new List <ITagValue>()
            {
                null, TagValue.Create("v2"), null, null
            };

            result = ep.GetTagKeysAndValues(keys, values);
            Assert.Equal("v2", result["exception"]);
            Assert.Single(result);

            values = new List <ITagValue>()
            {
                TagValue.Create("v1"),
            };

            result = ep.GetTagKeysAndValues(keys, values);
            Assert.Empty(result);
        }