Пример #1
0
        public void ContextInitializerDoesNotOverrideMachineName()
        {
            var source           = new DomainNameRoleInstanceTelemetryInitializer();
            var requestTelemetry = new RequestTelemetry();

            requestTelemetry.Context.Cloud.RoleInstance = "Test";
            source.Initialize(requestTelemetry);
            Assert.Equal("Test", requestTelemetry.Context.Cloud.RoleInstance);
        }
Пример #2
0
        public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable()
        {
            var ac = new HttpContextAccessor()
            {
                HttpContext = new DefaultHttpContext()
            };

            var initializer = new DomainNameRoleInstanceTelemetryInitializer(ac);

            initializer.Initialize(new RequestTelemetry());
        }
        public void ContextInitializerDoesNotOverrideMachineName()
        {
            var contextAccessor  = HttpContextAccessorHelper.CreateHttpContextAccessor(new RequestTelemetry(), null);
            var source           = new DomainNameRoleInstanceTelemetryInitializer(contextAccessor);
            var requestTelemetry = new RequestTelemetry();

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

            source.Initialize(requestTelemetry);

            Assert.Equal("Test", requestTelemetry.Context.Cloud.RoleInstance);
        }
Пример #4
0
        public void RoleInstanceNameIsSetToDomainAndHost()
        {
            var source           = new DomainNameRoleInstanceTelemetryInitializer();
            var requestTelemetry = new RequestTelemetry();

            source.Initialize(requestTelemetry);

            string hostName = Dns.GetHostName();

#if NET451 || NET46
            string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName;
            if (hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase) == false)
            {
                hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName);
            }
#endif

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