public void HeartbeatPayloadContainsOnlyAllowedDefaultPayloadFields()
        {
            var assemblyDefFields = new BaseDefaultHeartbeatPropertyProvider();

            var allDefaultFields = assemblyDefFields.DefaultFields;

            using (var hbeat = new HeartbeatProvider())
            {
                List <string> disableHbProps = new List <string>();

                for (int i = 0; i < allDefaultFields.Count(); ++i)
                {
                    if (i % 2 == 0)
                    {
                        disableHbProps.Add(allDefaultFields[i]);
                        hbeat.ExcludedHeartbeatProperties.Add(allDefaultFields[i]);
                    }
                }

                hbeat.Initialize(configuration: null);

                var sentHeartBeat = (MetricTelemetry)hbeat.GatherData();

                Assert.IsNotNull(sentHeartBeat);

                foreach (var kvp in sentHeartBeat.Properties)
                {
                    Assert.IsFalse(disableHbProps.Contains(kvp.Key),
                                   string.Format(CultureInfo.CurrentCulture, "Dissallowed field '{0}' found in payload", kvp.Key));
                }
            }
        }
        public void EnsureAllTargetFrameworksRepresented()
        {
            BaseDefaultHeartbeatPropertyProvider bp = new BaseDefaultHeartbeatPropertyProvider();
            var noAwaiterForTests = bp.SetDefaultPayload(new string[] { }, new HeartbeatProviderMock()).ConfigureAwait(false);

            Assert.IsTrue(noAwaiterForTests.GetAwaiter().GetResult());
            // this is enough to ensure we've hit all of our target framework paths (unless a new one has been added, the purpose of this test)
        }
 public void CanOverrideDefaultHeartbeatValuesInternally()
 {
     using (var hbeat = (IHeartbeatProvider) new HeartbeatProvider())
     {
         var baseProps        = new BaseDefaultHeartbeatPropertyProvider();
         var defaultFieldName = baseProps.DefaultFields[0];
         Assert.IsTrue(hbeat.AddHeartbeatProperty(defaultFieldName, true, "test", true));
         Assert.IsFalse(hbeat.AddHeartbeatProperty(defaultFieldName, true, "test", true));
         Assert.IsTrue(hbeat.SetHeartbeatProperty(defaultFieldName, true, "test-1", false));
         Assert.IsFalse(hbeat.SetHeartbeatProperty(defaultFieldName, false, "test-2", false));
     }
 }
        public void CannotAddPayloadItemNamedOfDefaultPayloadProperties()
        {
            using (var hbeat = new HeartbeatProvider())
            {
                hbeat.Initialize(configuration: null);
                BaseDefaultHeartbeatPropertyProvider defFields = new BaseDefaultHeartbeatPropertyProvider();

                foreach (string key in defFields.DefaultFields)
                {
                    Assert.IsFalse(hbeat.AddHeartbeatProperty(key, "test", true));
                }
            }
        }
        public void HandleUnknownDefaultProperty()
        {
            var    defProps = new BaseDefaultHeartbeatPropertyProvider();
            string testKey  = "TestProp";

            defProps.DefaultFields.Add(testKey);
            using (var hbeat = new HeartbeatProvider())
            {
                var waitForProps = defProps.SetDefaultPayload(new string[] { }, hbeat).ConfigureAwait(false);
                Assert.IsTrue(waitForProps.GetAwaiter().GetResult());
                var heartbeat = (MetricTelemetry)hbeat.GatherData();
                Assert.IsTrue(heartbeat.Properties.ContainsKey(testKey));
                Assert.IsFalse(string.IsNullOrEmpty(heartbeat.Properties[testKey]));
            }
        }
        public void SentHeartbeatContainsExpectedDefaultFields()
        {
            using (var hbeatMock = new HeartbeatProviderMock())
            {
                var baseHbeatProps = new BaseDefaultHeartbeatPropertyProvider().DefaultFields;

                var taskWaiter = HeartbeatDefaultPayload.PopulateDefaultPayload(new string[] { }, new string[] { }, hbeatMock).ConfigureAwait(false);
                Assert.IsTrue(taskWaiter.GetAwaiter().GetResult()); // no await for tests

                foreach (string fieldName in baseHbeatProps)
                {
                    Assert.IsTrue(hbeatMock.HeartbeatProperties.ContainsKey(fieldName));
                }
            }
        }