Exemplo n.º 1
0
 private static XElement AssertNodeExistsInConfiguration(XDocument configAfterTransform, Type typeToFind)
 {
     return(ConfigurationHelpers.GetTelemetryInitializers(configAfterTransform)
            .Descendants()
            .FirstOrDefault(
                element =>
                (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) ==
                ConfigurationHelpers.GetPartialTypeName(typeToFind)));
 }
        public void InstallAddsExceptionTrackingTelemetryModule()
        {
            string    emptyConfig          = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);

            var typeToFind = typeof(ExceptionTrackingTelemetryModule);

            var node = ConfigurationHelpers.GetTelemetryModules(configAfterTransform)
                       .Descendants()
                       .FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind));

            Assert.IsNotNull(node);
        }
        public void InstallAddsUserAgentProcessorDefaultConfiguration()
        {
            string    emptyConfig          = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);

            var typeToFind = typeof(UserAgentTelemetryProcessor);

            var node = ConfigurationHelpers.GetTelemetryProcessors(configAfterTransform)
                       .Descendants()
                       .FirstOrDefault(element => element.Attribute("Type").Value == ConfigurationHelpers.GetPartialTypeName(typeToFind))
                       .Descendants()
                       .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "AlwaysOn");

            Assert.IsNotNull(node);
        }
        public void InstallAddsHandlerProcessorWithDefaultConfiguration()
        {
            string    emptyConfig          = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);

            var typeToFind = typeof(HandlerTelemetryProcessor);

            var handler = ConfigurationHelpers.GetTelemetryProcessors(configAfterTransform)
                          .Descendants()
                          .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == ConfigurationHelpers.GetPartialTypeName(typeToFind));

            var node = handler
                       .Descendants()
                       .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Handlers.TransferRequestHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.StaticFileHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Handlers.AssemblyResourceLoader");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Optimization.BundleHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Script.Services.ScriptHandlerFactory");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Handlers.TraceHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.Services.Discovery.DiscoveryRequestHandler");

            Assert.IsNotNull(node);

            node = handler
                   .Descendants()
                   .FirstOrDefault(element => (element.Attribute("Value") != null ? element.Attribute("Value").Value : null) == "System.Web.HttpDebugHandler");

            Assert.IsNotNull(node);
        }
        public void UninstallRemovesAllTelemetryProcessorsExceptAdaptiveSampling()
        {
            string    emptyConfig        = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterInstall = ConfigurationHelpers.InstallTransform(emptyConfig);

            XDocument configAfterUninstall = ConfigurationHelpers.UninstallTransform(configAfterInstall.ToString());

            var children = ConfigurationHelpers.GetTelemetryProcessors(configAfterUninstall)
                           .Descendants().ToList();
            var handler = children
                          .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == ConfigurationHelpers.GetPartialTypeName(typeof(HandlerTelemetryProcessor)));

            var userAgent = children
                            .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == ConfigurationHelpers.GetPartialTypeName(typeof(UserAgentTelemetryProcessor)));

            var sampler = children
                          .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel");

            Assert.IsNull(handler, "HandlerTelemetryProcessor was not removed.");
            Assert.IsNull(userAgent, "UserAgentTelemetryProcessor was not removed.");
            Assert.IsNotNull(sampler, "AdaptiveSamplingTelemetryProcessor was removed");
        }
        public void InstallAddsAdaptiveSamplingProcessorLast()
        {
            string    emptyConfig          = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterTransform = ConfigurationHelpers.InstallTransform(emptyConfig);

            var children = ConfigurationHelpers.GetTelemetryProcessors(configAfterTransform)
                           .Descendants().ToList();
            var handler = children
                          .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == ConfigurationHelpers.GetPartialTypeName(typeof(HandlerTelemetryProcessor)));

            var userAgent = children
                            .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == ConfigurationHelpers.GetPartialTypeName(typeof(UserAgentTelemetryProcessor)));

            var sampler = children
                          .FirstOrDefault(element => (element.Attribute("Type") != null ? element.Attribute("Type").Value : null) == "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel");

            var handlerIndex   = children.IndexOf(handler);
            var userAgentIndex = children.IndexOf(userAgent);
            var samplerIndex   = children.IndexOf(sampler);

            Assert.IsTrue(samplerIndex > handlerIndex, "AdaptiveSamplingTelemetryProcessor is not placed before HandlerTelemetryProcessor");
            Assert.IsTrue(samplerIndex > userAgentIndex, "AdaptiveSamplingTelemetryProcessor is not placed before UserAgentTelemetryProcessor");
        }