public void UninstallRemovesAllTelemetryModules()
        {
            string    emptyConfig        = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterInstall = ConfigurationHelpers.InstallTransform(emptyConfig);

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

            Assert.AreEqual(0, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).ToList().Count);
        }
        public void UninstallDoesNotRemoveTelemetryModulesTagIfCustomTelemetryModuleIsPresent()
        {
            string    emptyConfig        = ConfigurationHelpers.GetEmptyConfig();
            XDocument configAfterInstall = ConfigurationHelpers.InstallTransform(emptyConfig);

            // Replace valid type on custom so during uninstall it should stay in the config
            string customConfig = configAfterInstall.ToString().Replace("ExceptionTrackingTelemetryModule", "blah");

            XDocument configAfterUninstall = ConfigurationHelpers.UninstallTransform(customConfig);

            Assert.AreEqual(1, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).ToList().Count);
            Assert.AreEqual(1, ConfigurationHelpers.GetTelemetryModules(configAfterUninstall).Descendants().ToList().Count);
        }
        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");
        }