Inheritance: ITelemetryProcessor
        public void ProcessCallsNextIfRequestFailed()
        {
            HttpContext.Current = HttpModuleHelper.GetFakeHttpContextForFailedRequest();

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new HandlerTelemetryProcessor(spy);

            source.Process(new RequestTelemetry());

            Assert.AreEqual(1, spy.ReceivedCalls);
        }
        public void ProcessCallsNextIfSuccessfulRequestUserAgentIsNotFiltered()
        {
            HttpContext.Current = HttpModuleHelper.GetFakeHttpContext(new Dictionary<string, string> { { "User-Agent", "a" } });

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new UserAgentTelemetryProcessor(spy);

            source.Process(new RequestTelemetry());

            Assert.AreEqual(1, spy.ReceivedCalls);
        }
        public void ProcessCallsNextIfHttpContextIsNull()
        {
            HttpContext.Current = null;

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new HandlerTelemetryProcessor(spy);

            source.Process(new RequestTelemetry());

            Assert.AreEqual(1, spy.ReceivedCalls);
        }
        public void QuickPulseTelemetryProcessorCallsNext()
        {
            // ARRANGE
            var spy = new SimpleTelemetryProcessorSpy();
            var telemetryProcessor = new QuickPulseTelemetryProcessor(spy);

            // ACT
            telemetryProcessor.Process(new RequestTelemetry() { Context = { InstrumentationKey = "some ikey" } });

            // ASSERT
            Assert.AreEqual(1, spy.ReceivedCalls);
        }
        public void ProcessReturnsIfSuccessfulRequestHandlerIsFilteredByDefault()
        {
            HttpContext.Current = HttpModuleHelper.GetFakeHttpContext(new Dictionary<string, string> { { "User-Agent", "a" } });
            HttpContext.Current.Handler = new AssemblyResourceLoader();

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new HandlerTelemetryProcessor(spy);
            source.Handlers.Add(new FilterRequest { Value = "System.Web.Handlers.AssemblyResourceLoader" });

            source.Process(new RequestTelemetry());

            Assert.AreEqual(0, spy.ReceivedCalls);
        }
        public void ProcessCallsNextIfSuccessfulRequestHandlerIsNotFiltered()
        {
            HttpContext.Current = HttpModuleHelper.GetFakeHttpContext(new Dictionary<string, string> { { "User-Agent", "a" } });
            HttpContext.Current.Handler = new AssemblyResourceLoader();

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new HandlerTelemetryProcessor(spy);
            source.Handlers.Add(new FilterRequest { Value = "Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModuleTest+FakeHttpHandler" });

            source.Process(new RequestTelemetry());

            Assert.AreEqual(1, spy.ReceivedCalls);
        }
        public void UserAgentIsFilteredIfItIsWhiteSpaceAndWhitespaceExplicitlySpecified()
        {
            HttpContext.Current = HttpModuleHelper.GetFakeHttpContext(new Dictionary<string, string> { { "User-Agent", "    " } });

            var spy = new SimpleTelemetryProcessorSpy();

            var source = new UserAgentTelemetryProcessor(spy);

            source.UserAgents.Add(new FilterRequest { Value = "\n " });

            source.Process(new RequestTelemetry());

            Assert.AreEqual(0, spy.ReceivedCalls);
        }
        public void QuickPulseTelemetryProcessorRegistersWithModule()
        {
            // ARRANGE
            var module = new QuickPulseTelemetryModule(null, null, null, null, null);

            TelemetryModules.Instance.Modules.Add(module);

            // ACT
            var spy = new SimpleTelemetryProcessorSpy();
            var telemetryProcessor = new QuickPulseTelemetryProcessor(spy);
            telemetryProcessor.Initialize(new TelemetryConfiguration());

            // ASSERT
            Assert.AreEqual(telemetryProcessor, QuickPulseTestHelper.GetTelemetryProcessors(module).Single());
        }
        public void QuickPulseTelemetryProcessorFiltersOutDependencyCallsToQuickPulseServiceDuringCollection()
        {
            // ARRANGE
            var accumulatorManager = new QuickPulseDataAccumulatorManager();
            var simpleTelemetryProcessorSpy = new SimpleTelemetryProcessorSpy();
            var telemetryProcessor = new QuickPulseTelemetryProcessor(simpleTelemetryProcessorSpy);
            var config = new TelemetryConfiguration() { InstrumentationKey = "some ikey" };

            ((IQuickPulseTelemetryProcessor)telemetryProcessor).StartCollection(
                accumulatorManager,
                new Uri("https://qps.cloudapp.net/endpoint.svc"),
                config);

            // ACT
            telemetryProcessor.Process(
                new DependencyTelemetry() { Name = "http://microsoft.ru", Context = { InstrumentationKey = config.InstrumentationKey } });
            telemetryProcessor.Process(
                new DependencyTelemetry() { Name = "http://qps.cloudapp.net/blabla", Context = { InstrumentationKey = config.InstrumentationKey } });
            telemetryProcessor.Process(
                new DependencyTelemetry() { Name = "https://bing.com", Context = { InstrumentationKey = config.InstrumentationKey } });

            // ASSERT
            Assert.AreEqual(2, simpleTelemetryProcessorSpy.ReceivedCalls);
            Assert.AreEqual("http://microsoft.ru", (simpleTelemetryProcessorSpy.ReceivedItems[0] as DependencyTelemetry).Name);
            Assert.AreEqual("https://bing.com", (simpleTelemetryProcessorSpy.ReceivedItems[1] as DependencyTelemetry).Name);
            Assert.AreEqual(2, accumulatorManager.CurrentDataAccumulator.AIDependencyCallCount);
        }
        public void QuickPulseTelemetryProcessorFiltersOutDependencyCallsToDefaultQuickPulseServiceEndpointInIdleMode()
        {
            // ARRANGE
            var simpleTelemetryProcessorSpy = new SimpleTelemetryProcessorSpy();
            var telemetryProcessor = new QuickPulseTelemetryProcessor(simpleTelemetryProcessorSpy);

            // ACT
            telemetryProcessor.Process(new DependencyTelemetry() { Name = "http://microsoft.ru" });
            telemetryProcessor.Process(new DependencyTelemetry() { Name = "http://rt.services.visualstudio.com/blabla" });
            telemetryProcessor.Process(new DependencyTelemetry() { Name = "https://bing.com" });

            // ASSERT
            Assert.AreEqual(2, simpleTelemetryProcessorSpy.ReceivedCalls);
            Assert.AreEqual("http://microsoft.ru", (simpleTelemetryProcessorSpy.ReceivedItems[0] as DependencyTelemetry).Name);
            Assert.AreEqual("https://bing.com", (simpleTelemetryProcessorSpy.ReceivedItems[1] as DependencyTelemetry).Name);
        }