protected void ValidateIsFirstSessionFalseAndSessionNotStarted(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { // If a second request is made with the session cookie that is obtained from the first request, // IsFirst is false and no SessionState telemetry is generated Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >(1, testListenerTimeoutInMs); var sessionCookie = new Cookie(CookieNames.SessionCookie, requestResponseContainer.CookieCollection.ReceiveSessionCookie()); requestResponseContainer = new RequestResponseContainer(new [] { sessionCookie }, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var items = Listener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RequestData>, TelemetryItem <SessionStateData> >(testListenerTimeoutInMs); Assert.AreEqual(1, items.Length, "We expected only 1 request. SessionState should not be generated."); var request = items[0] as TelemetryItem <RequestData>; Assert.IsTrue((request.SessionContext.IsFirst == null) || !request.SessionContext.IsFirst.Value, "IsFirst should be false or null because cookie existed"); }
/// <summary> /// Tests the scenario when the initial request contains a cookie (corresponding to user), in which case, the response should contain a similar cookie with the information /// replicated into the listener data. /// </summary> protected void ValidateUserIdWithRequestCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs, Cookie[] additionalCookies = null) { DateTimeOffset time = DateTimeOffset.UtcNow; List <Cookie> cookies = new List <Cookie>(); int additionalCookiesLength = 0; if (null != additionalCookies) { cookies.AddRange(additionalCookies); additionalCookiesLength = additionalCookies.Length; } string userCookieStr = "userId|" + time.ToString("O"); var cookie = new Cookie(CookieNames.UserCookie, userCookieStr); cookies.Add(cookie); var requestResponseContainer = new RequestResponseContainer(cookies.ToArray(), requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2 + additionalCookiesLength, requestResponseContainer.CookieCollection.Count); Assert.AreEqual("userId", item.UserContext.Id); Assert.AreEqual(time, item.UserContext.AcquisitionDate.Value); Assert.AreEqual(userCookieStr, userCookie); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
/// <summary> /// Tests the scenario when the initial request contains a cookie (corresponding to user), in which case, the response should contain a similar cookie with the information /// replicated into the listener data. /// </summary> protected void ValidateUserIdWithRequestCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs, Cookie[] additionalCookies = null) { DateTimeOffset time = DateTimeOffset.UtcNow; List<Cookie> cookies = new List<Cookie>(); int additionalCookiesLength = 0; if (null != additionalCookies) { cookies.AddRange(additionalCookies); additionalCookiesLength = additionalCookies.Length; } string userCookieStr = "userId|" + time.ToString("O"); var cookie = new Cookie(CookieNames.UserCookie, userCookieStr); cookies.Add(cookie); var requestResponseContainer = new RequestResponseContainer(cookies.ToArray(), requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2 + additionalCookiesLength, requestResponseContainer.CookieCollection.Count); Assert.AreEqual("userId", item.UserContext.Id); Assert.AreEqual(time, item.UserContext.AcquisitionDate.Value); Assert.AreEqual(userCookieStr, userCookie); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
/// <summary> /// Tests the scenario when the initial request contains a cookie (corresponding to user), in which case, the response should contain a similar cookie with the information /// replicated into the listener data. /// </summary> protected void ValidateSessionIdWithRequestCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { DateTime currentTime = DateTime.Now; string currentTimeString = currentTime.ToString("O"); string actualCookie = "sessionId|" + currentTimeString + "|" + currentTimeString; var cookie = new Cookie(CookieNames.SessionCookie, actualCookie); Cookie[] cookies = { cookie }; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(actualCookie, sessionCookie); Assert.AreEqual("sessionId", item.SessionContext.Id); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
/// <summary> ///Tests the scenario if user related information is present in the listener when customer invokes TrackMetric() ///method from his application without a cookie. /// </summary> protected void ValidateUserCookieWhenTrackMetricIsInvokedWithoutCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); var item = Listener.ReceiveItemsOfType<TelemetryItem<MetricData>>( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
protected void CheckIfUserIsCollectedIfResponseIsFlushedEarly(string requestPath, string contentMarker, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >(1, testListenerTimeoutInMs)[0]; var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); Trace.Write(requestResponseContainer.ResponseData); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
/// <summary> ///Tests the scenario if session related information is present in the listener when customer invokes TrackMetric() ///method from his application without a cookie. /// </summary> protected void ValidateSessionCookieWhenTrackMetricIsInvokedWithoutCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType<TelemetryItem<MetricData>>( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
/// <summary> ///Tests the scenario if user related information is present in the listener when customer invokes TrackMetric() ///method from his application without a cookie. /// </summary> protected void ValidateUserCookieWhenTrackMetricIsInvokedWithoutCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); var item = Listener.ReceiveItemsOfType <TelemetryItem <MetricData> >( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
protected void CheckIfSessionIsInitializedWhenPostResolveCacheIsSkipped(string requestPath, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateFailedRequest(requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >(1, testListenerTimeoutInMs)[0]; var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
protected void ValidateIsFirstSessionTrueAndNewSessionStarted(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { // For the first request that is being sent we create a new user and a new session // Check: IsFirst true; new SessionState is generated Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); TelemetryItem<RequestData> requestItem; TelemetryItem<SessionStateData> sessionStateItem; this.ReceiveRequestAndSession(testListenerTimeoutInMs, out requestItem, out sessionStateItem); Assert.IsTrue(requestItem.SessionContext.IsFirst.Value, "A new userId is associated with isFirstSession False"); Assert.AreEqual(sessionStateItem.Data.BaseData.State, SessionState.Start); }
/// <summary> ///Tests the scenario if session related information is present in the listener when customer invokes TrackMetric() ///method from his application without a cookie. /// </summary> protected void ValidateSessionCookieWhenTrackMetricIsInvokedWithoutCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType <TelemetryItem <MetricData> >( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
protected void CheckIfSessionIsCollectedIfResponseIsFlushedEarly(string requestPath, string contentMarker, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateSuccessfullRequest(contentMarker, requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >(1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
protected void ValidateIsFirstSessionTrueAndNewSessionStarted(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { // For the first request that is being sent we create a new user and a new session // Check: IsFirst true; new SessionState is generated Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); TelemetryItem <RequestData> requestItem; TelemetryItem <SessionStateData> sessionStateItem; this.ReceiveRequestAndSession(testListenerTimeoutInMs, out requestItem, out sessionStateItem); Assert.IsTrue(requestItem.SessionContext.IsFirst.Value, "A new userId is associated with isFirstSession False"); Assert.AreEqual(sessionStateItem.Data.BaseData.State, SessionState.Start); }
protected void CheckIfUserIsInitializedWhenPostResolveCacheIsSkipped(string requestPath, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateFailedRequest(requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var item = Listener.ReceiveItemsOfType <TelemetryItem <RequestData> >(1, testListenerTimeoutInMs)[0]; Assert.IsNotNull(item.UserContext.Id); Assert.IsNotNull(item.UserContext.AcquisitionDate.Value); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); Trace.Write(requestResponseContainer.ResponseData); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
protected void ValidateIsFirstSessionFalseAndSessionNotStarted(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { // If a second request is made with the session cookie that is obtained from the first request, // IsFirst is false and no SessionState telemetry is generated Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>(1, testListenerTimeoutInMs); var sessionCookie = new Cookie(CookieNames.SessionCookie, requestResponseContainer.CookieCollection.ReceiveSessionCookie()); requestResponseContainer = new RequestResponseContainer(new []{sessionCookie}, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var items = Listener.ReceiveAllItemsDuringTimeOfType<TelemetryItem<RequestData>, TelemetryItem<SessionStateData>>(testListenerTimeoutInMs); Assert.AreEqual(1, items.Length, "We expected only 1 request. SessionState should not be generated."); var request = items[0] as TelemetryItem<RequestData>; Assert.IsTrue((request.SessionContext.IsFirst == null) || !request.SessionContext.IsFirst.Value, "IsFirst should be false or null because cookie existed"); }
/// <summary> /// Tests the scenario when the initial request contains a cookie (corresponding to user), in which case, the response should contain a similar cookie with the information /// replicated into the listener data. /// </summary> protected void ValidateSessionIdWithRequestCookie(string requestPath, int testListenerTimeoutInMs, int testRequestTimeOutInMs) { DateTime currentTime = DateTime.Now; string currentTimeString = currentTime.ToString("O"); string actualCookie = "sessionId|" + currentTimeString + "|" + currentTimeString; var cookie = new Cookie(CookieNames.SessionCookie, actualCookie); Cookie[] cookies = { cookie }; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeOutInMs); requestResponseContainer.SendRequest(); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>( 1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(actualCookie, sessionCookie); Assert.AreEqual("sessionId", item.SessionContext.Id); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
protected void CheckIfUserIsInitializedWhenPostResolveCacheIsSkipped(string requestPath, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateFailedRequest(requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>(1, testListenerTimeoutInMs)[0]; Assert.IsNotNull(item.UserContext.Id); Assert.IsNotNull(item.UserContext.AcquisitionDate.Value); var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); Trace.Write(requestResponseContainer.ResponseData); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
protected void CheckIfSessionIsInitializedWhenPostResolveCacheIsSkipped(string requestPath, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateFailedRequest(requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>(1, testListenerTimeoutInMs)[0]; var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }
protected void CheckIfUserIsCollectedIfResponseIsFlushedEarly(string requestPath, string contentMarker, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>(1, testListenerTimeoutInMs)[0]; var userCookie = requestResponseContainer.CookieCollection.ReceiveUserCookie(); Trace.Write(requestResponseContainer.ResponseData); Assert.AreEqual(userCookie, item.UserContext.Id + "|" + item.UserContext.AcquisitionDate.Value.ToString("O")); }
protected void CheckIfSessionIsCollectedIfResponseIsFlushedEarly(string requestPath, string contentMarker, int testListenerTimeoutInMs, int testRequestTimeoutInMs) { Cookie[] cookies = new Cookie[0]; var requestResponseContainer = new RequestResponseContainer(cookies, requestPath, this.Config.ApplicationUri, testListenerTimeoutInMs, testRequestTimeoutInMs); requestResponseContainer.SendRequest(); this.ValidateSuccessfullRequest(contentMarker, requestResponseContainer.ResponseTask, testRequestTimeoutInMs); var sessionCookie = requestResponseContainer.CookieCollection.ReceiveSessionCookie(); var item = Listener.ReceiveItemsOfType<TelemetryItem<RequestData>>(1, testListenerTimeoutInMs)[0]; Assert.AreEqual("OK", requestResponseContainer.ResponseTask.Result.ReasonPhrase); Assert.AreNotEqual(string.Empty, sessionCookie); Assert.AreEqual(2, requestResponseContainer.CookieCollection.Count); Assert.AreEqual(sessionCookie.Substring(0, sessionCookie.IndexOf("|", StringComparison.Ordinal)), item.SessionContext.Id); }