public void ApplicationInsightsJsHelper_CheckIfContainsNonce_ScriptPlain()
        {
            var httpContext = _serviceProvider.GetRequiredService <IHttpContextAccessor>();

            IOptions <ApplicationInsightsServiceOptions> someOptions = Options.Create <ApplicationInsightsServiceOptions>(new ApplicationInsightsServiceOptions());

            var fakeJs = new MockJavaScriptSnippet(_telemetryConfiguration, someOptions, httpContext,
                                                   new JavaScriptTestEncoder());

            var script = new ApplicationInsightsJsHelper(httpContext, fakeJs).ScriptPlain;

            Assert.AreEqual(true, script.Contains("Microsoft.ApplicationInsights"));
        }
        public void ApplicationInsightsJsHelper_GetCurrentUserId_NotLogin()
        {
            var httpContextAccessor = new HttpContextAccessor
            {
                HttpContext = new DefaultHttpContext()
            };
            IOptions <ApplicationInsightsServiceOptions> someOptions = Options.Create <ApplicationInsightsServiceOptions>(new ApplicationInsightsServiceOptions());

            var fakeJs = new MockJavaScriptSnippet(_telemetryConfiguration, someOptions, httpContextAccessor,
                                                   new JavaScriptTestEncoder());

            var script = new ApplicationInsightsJsHelper(httpContextAccessor, fakeJs).GetCurrentUserId();

            Assert.AreEqual("", script);
        }
        public void ApplicationInsightsJsHelper_CheckIfContainsNonce_ScriptTag()
        {
            var httpContext = _serviceProvider.GetRequiredService <IHttpContextAccessor>();

            var toCheckNonce = Guid.NewGuid() + "__";

            httpContext.HttpContext.Items["csp-nonce"] = toCheckNonce;

            var someOptions = Options.Create(new ApplicationInsightsServiceOptions());

            var fakeJs = new MockJavaScriptSnippet(_telemetryConfiguration, someOptions, httpContext,
                                                   new JavaScriptTestEncoder());

            var script = new ApplicationInsightsJsHelper(httpContext, fakeJs).ScriptTag;

            Assert.AreEqual(true, script.Contains(toCheckNonce));
            Assert.AreEqual(true, script.Contains("Microsoft.ApplicationInsights"));
        }
        public async Task ApplicationInsightsJsHelper_GetCurrentUserId_WithId()
        {
            var httpContextAccessor = _serviceProvider.GetRequiredService <IHttpContextAccessor>();
            var userManager         = _serviceProvider.GetRequiredService <IUserManager>();

            var result = await userManager.SignUpAsync("test", "email", "test", "test");

            await userManager.SignIn(httpContextAccessor.HttpContext, result.User);

            IOptions <ApplicationInsightsServiceOptions> someOptions = Options.Create(new ApplicationInsightsServiceOptions());

            var fakeJs = new MockJavaScriptSnippet(_telemetryConfiguration, someOptions, httpContextAccessor,
                                                   new JavaScriptTestEncoder());


            var script = new ApplicationInsightsJsHelper(httpContextAccessor, fakeJs).GetCurrentUserId();

            Assert.AreEqual(userManager.GetUser("email", "test").Id.ToString(), script);
        }