public void TestCountTelemetry_DetectsUniqueDifference()
        {
            // arrange
            TelemetryItemBuffer sut = new TelemetryItemBuffer("");

            EventTelemetry item1 = new EventTelemetry("event1");

            item1.Properties["key1"] = "value1";
            item1.Properties["key2"] = "value2";
            item1.Properties["key3"] = "value3";
            item1.Properties["key4"] = "value4";

            EventTelemetry item2 = new EventTelemetry("event1");

            item2.Properties["key2"] = "value2";
            item2.Properties["key4"] = "value4";
            item2.Properties["key3"] = "value3";
            item2.Properties["key5"] = "value1";

            bool expected = true;

            // act
            sut.CountTelemetry(item1);
            bool actual = sut.CountTelemetry(item2);

            // assert
            Assert.AreEqual(expected, actual);
        }
        private void EnsureBuffers(string instrumentationKey)
        {
            if (!_telemetryBuffers.ContainsKey(instrumentationKey))
            {
                _telemetryBuffers[instrumentationKey] = new ConcurrentDictionary <Type, TelemetryItemBuffer>();

                foreach (Type telemetryType in _typesToTrack)
                {
                    if (!_telemetryBuffers[instrumentationKey].ContainsKey(telemetryType))
                    {
                        _telemetryBuffers[instrumentationKey][telemetryType] = new TelemetryItemBuffer(instrumentationKey)
                        {
                            PrefixMetricsWithType = this.PrefixMetricsWithType
                        };
                    }
                }
            }
        }
        public void TestCountTelemetry_CountsEventsRightWithPrefix()
        {
            using (ShimsContext.Create())
            {
                // arrange
                TelemetryItemBuffer sut = new TelemetryItemBuffer("");
                sut.PrefixMetricsWithType = true;

                EventTelemetry item1 = new EventTelemetry("event1");
                item1.Properties["key1"] = "value1";
                item1.Properties["key2"] = "value2";
                item1.Properties["key3"] = "value3";
                item1.Properties["key4"] = "value4";

                EventTelemetry item2 = new EventTelemetry("event1");
                item2.Properties["key2"] = "value2";
                item2.Properties["key4"] = "value4";
                item2.Properties["key3"] = "value3";
                item2.Properties["key5"] = "value1";

                double expected = 100;
                double actual   = 0;
                ShimTelemetryClient.AllInstances.TrackMetricStringDoubleIDictionaryOfStringString = (client, name, value, dict) =>
                {
                    if (string.Equals("Event.event1", name))
                    {
                        actual = value;
                    }
                };

                // act
                for (int i = 0; i < 50; ++i)
                {
                    sut.CountTelemetry(item1);
                    sut.CountTelemetry(item2);
                }
                sut.SendMetrics();

                // assert
                Assert.AreEqual(expected, actual);
            }
        }