Пример #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 SetCorrelationContextForWebRequestSetsHeaders()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));
            var telemetry  = new DependencyTelemetry();

            telemetry.Id = "Id";
            telemetry.Context.Operation.Id = "RootId";

            WebRequestDependencyTrackingHelpers.SetCorrelationContextForWebRequest(telemetry, webRequest);
            var rootId      = webRequest.Headers[RequestResponseHeaders.StandardRootIdHeader];
            var operationId = webRequest.Headers[RequestResponseHeaders.StandardParentIdHeader];

            Assert.AreEqual("RootId", rootId);
            Assert.AreEqual("Id", operationId);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        public void SetUserAndSessionContextForWebRequestDoesNotFailWithNullWebRequest()
        {
            var telemetry = new DependencyTelemetry();

            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(telemetry, null);
        }
Пример #6
0
        public void SetUserAndSessionContextForWebRequestFailsWithNullTelemetry()
        {
            var webRequest = WebRequest.Create(new Uri("http://bing.com"));

            WebRequestDependencyTrackingHelpers.SetUserAndSessionContextForWebRequest(null, webRequest);
        }