A telemetry context initializer that populates device context role instance name.
Наследование: ITelemetryInitializer
        public void ContextInitializerDoesNotOverrideMachineName()
        {
            var telemetryItem = new EventTelemetry();
            var source = new DomainNameRoleInstanceTelemetryInitializer();
            telemetryItem.Context.Cloud.RoleInstance = "Test";

            source.Initialize(telemetryItem);

            Assert.Equal("Test", telemetryItem.Context.Cloud.RoleInstance);
        }
        public void ContextInitializerDoesNotOverrideMachineName()
        {
            var telemetryItem = new EventTelemetry();
            var source        = new DomainNameRoleInstanceTelemetryInitializer();

            telemetryItem.Context.Cloud.RoleInstance = "Test";

            source.Initialize(telemetryItem);

            Assert.Equal("Test", telemetryItem.Context.Cloud.RoleInstance);
        }
        public void RoleInstanceNameIsSetToDomainAndHost()
        {
            var telemetryItem = new EventTelemetry();
            var source        = new DomainNameRoleInstanceTelemetryInitializer();

            source.Initialize(telemetryItem);

            string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string hostName   = Dns.GetHostName();

            if (hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase) == false)
            {
                hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName);
            }

            Assert.Equal(hostName, telemetryItem.Context.Cloud.RoleInstance);
        }
        public void RoleInstanceNameIsSetToDomainAndHost()
        {
            var telemetryItem = new EventTelemetry();
            var source = new DomainNameRoleInstanceTelemetryInitializer();
            
            source.Initialize(telemetryItem);

            string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string hostName = Dns.GetHostName();

            if (hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase) == false)
            {
                hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName);
            }

            Assert.Equal(hostName, telemetryItem.Context.Cloud.RoleInstance);
        }