SetUserAndSessionContextForWebRequest() static private method

Populates WebRequest using the user, session initialized in telemetry item.
static private SetUserAndSessionContextForWebRequest ( Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry dependencyTelemetry, WebRequest webRequest ) : void
dependencyTelemetry Microsoft.ApplicationInsights.DataContracts.DependencyTelemetry Dependency telemetry item.
webRequest System.Net.WebRequest Http web request.
return void
コード例 #1
0
        public void SetUserAndSessionContextForWebRequestDoesNothingIfTelemetryItemIsNotInitialized()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry  = new DependencyTelemetry();

            string cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");

            Assert.IsNull(cookieValue);
            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, webRequest);
            cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");
            Assert.IsNull(cookieValue);
        }
コード例 #2
0
        public void SetCorrelationContextForWebRequestDoesNothingIfOperaitonContextEmpty()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry  = new DependencyTelemetry();

            string rootId      = webRequest.Headers[RequestResponseHeaders.StandardRootIdHeader];
            string operationId = webRequest.Headers[RequestResponseHeaders.StandardParentIdHeader];

            Assert.IsNull(rootId);
            Assert.IsNull(operationId);
            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, webRequest);
            rootId      = webRequest.Headers[RequestResponseHeaders.StandardRootIdHeader];
            operationId = webRequest.Headers[RequestResponseHeaders.StandardParentIdHeader];
            Assert.IsNull(rootId);
            Assert.IsNull(operationId);
        }
コード例 #3
0
        public void SetUserAndSessionContextForWebRequestSetsCookiesIfTelemetryItemIsInitialized()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry  = new DependencyTelemetry();

            telemetry.Context.Session.Id = "SessionID";
            telemetry.Context.User.Id    = "UserID";

            string cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");

            Assert.IsNull(cookieValue);
            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, webRequest);
            cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_session");
            Assert.IsNotNull(cookieValue);
            Assert.AreEqual("ai_session=SessionID", cookieValue);

            cookieValue = DependencyCollectorTestHelpers.GetCookieValueFromWebRequest(webRequest as HttpWebRequest, "ai_user");
            Assert.IsNotNull(cookieValue);
            Assert.AreEqual("ai_user=UserID", cookieValue);
        }
コード例 #4
0
        public void SetUserAndSessionContextForWebRequestDoesNotFailWithNullWebRequest()
        {
            var telemetry = new DependencyTelemetry();

            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, null);
        }
コード例 #5
0
        public void SetUserAndSessionContextForWebRequestFailsWithNullTelemetry()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));

            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(null, webRequest);
        }