public void InitializeSetsIdForTelemetryUsingIdFromRequestTelemetry()
        {
            var eventTelemetry   = new EventTelemetry("name");
            var source           = new TestableUserTelemetryInitializer();
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            requestTelemetry.Context.User.Id = "1";
            source.Initialize(eventTelemetry);

            Assert.AreEqual("1", eventTelemetry.Context.User.Id);
        }
        public void InitializeSetsIdForTelemetryUsingIdFromRequestTelemetry()
        {
            var metricTelemetry = new MetricTelemetry("name", 0);
            var source = new TestableUserTelemetryInitializer();
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            requestTelemetry.Context.User.Id = "1";
            source.Initialize(metricTelemetry);

            Assert.AreEqual("1", metricTelemetry.Context.User.Id);
        }
        public void InitializeDoesNotSetIdIfTelemetryHasIt()
        {
            var eventTelemetry   = new EventTelemetry("name");
            var source           = new TestableUserTelemetryInitializer();
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            requestTelemetry.Context.User.Id = "1";
            eventTelemetry.Context.User.Id   = "2";
            source.Initialize(eventTelemetry);

            Assert.AreEqual("2", eventTelemetry.Context.User.Id);
        }
        public void InitializeDoesNotSetIdIfTelemetryHasIt()
        {
            var metricTelemetry = new MetricTelemetry("name", 0);
            var source = new TestableUserTelemetryInitializer();
            var requestTelemetry = source.FakeContext.CreateRequestTelemetryPrivate();

            requestTelemetry.Context.User.Id = "1";
            metricTelemetry.Context.User.Id = "2";
            source.Initialize(metricTelemetry);

            Assert.AreEqual("2", metricTelemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieWithDateOnly()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();
            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture)))
                .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeReadSessionIdFromSimpleCookie()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();
            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", "123|" + DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture)))
                .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreEqual("123", telemetry.Context.User.Id);
            Assert.AreEqual("123", requestTelemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieFromEmptyValue()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();
            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", string.Empty))
                .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieWithDateOnly()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();

            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture)))
            .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeReadSessionIdFromSimpleCookie()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();

            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", "123|" + DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture)))
            .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreEqual("123", telemetry.Context.User.Id);
            Assert.AreEqual("123", requestTelemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieFromEmptyValue()
        {
            var requestTelemetry = new RequestTelemetry();

            var initializer = new TestableUserTelemetryInitializer();

            initializer.FakeContext.AddRequestCookie(new HttpCookie("ai_user", string.Empty))
            .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieWhenTimeIsMalformed()
        {
            var requestTelemetry = new RequestTelemetry();
            var time = DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture);
            var cookie = new HttpCookie("ai_user", "1|NotATime");

            var initializer = new TestableUserTelemetryInitializer();
            initializer.FakeContext.AddRequestCookie(cookie)
                .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeReadCookieWithMoreThanTwoParts()
        {
            var requestTelemetry = new RequestTelemetry();
            var time             = DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture);
            var cookie           = new HttpCookie("ai_user", "1|" + time + "|3");

            var initializer = new TestableUserTelemetryInitializer();

            initializer.FakeContext.AddRequestCookie(cookie)
            .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreEqual("1", requestTelemetry.Context.User.Id);
            Assert.AreEqual("1", telemetry.Context.User.Id);
        }
        public void InitializeDoNotReadCookieWhenTimeIsMalformed()
        {
            var requestTelemetry = new RequestTelemetry();
            var time             = DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture);
            var cookie           = new HttpCookie("ai_user", "1|NotATime");

            var initializer = new TestableUserTelemetryInitializer();

            initializer.FakeContext.AddRequestCookie(cookie)
            .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreNotEqual(string.Empty, requestTelemetry.Context.User.Id);
            Assert.AreNotEqual(string.Empty, telemetry.Context.User.Id);
        }
        public void InitializeReadCookieWithMoreThanTwoParts()
        {
            var requestTelemetry = new RequestTelemetry();
            var time = DateTimeOffset.Now.ToString("O", CultureInfo.InvariantCulture);
            var cookie = new HttpCookie("ai_user", "1|" + time + "|3");

            var initializer = new TestableUserTelemetryInitializer();
            initializer.FakeContext.AddRequestCookie(cookie)
                .AddRequestTelemetry(requestTelemetry);

            var telemetry = new EventTelemetry();

            initializer.Initialize(telemetry);

            Assert.AreEqual("1", requestTelemetry.Context.User.Id);
            Assert.AreEqual("1", telemetry.Context.User.Id);
        }