Ejemplo n.º 1
0
        public void CurrentCanBeSetToEnableMocking()
        {
            var platform = new StubPlatform();

            PlatformSingleton.Current = platform;
            Assert.AreSame(platform, PlatformSingleton.Current);
        }
Ejemplo n.º 2
0
        public void InitializeTelemetryModulesFromConfigurationFile()
        {
            string configFileContents = Configuration(
                @"<TelemetryModules>    
    <Add Type=""Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"" />
  </TelemetryModules>"
                );

            var platform = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var modules = new TestableTelemetryModules();
                new TestableTelemetryConfigurationFactory().Initialize(new TelemetryConfiguration(), modules);

                Assert.Equal(1, modules.Modules.Count);
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
Ejemplo n.º 3
0
        public void InitializeInvokedWhenTelemetryProcessorAlsoImplementsITelemetryModule()
        {
            string configFileContents = Configuration(
                @"                  
                  <TelemetryProcessors>
                  <Add Type=""Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactoryTest+StubTelemetryProcessor2, Microsoft.ApplicationInsights.Core.Net40.Tests"" />
                  </TelemetryProcessors>"
                );
            var platform = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var configuration = new TelemetryConfiguration();
                new TestableTelemetryConfigurationFactory().Initialize(configuration, null);

                // Assume that LoadFromXml method is called, tested separately
                Assert.True(configuration.TelemetryProcessors != null);
                Assert.IsType <StubTelemetryProcessor2>(configuration.TelemetryProcessors.FirstTelemetryProcessor);
                Assert.True(((StubTelemetryProcessor2)configuration.TelemetryProcessors.FirstTelemetryProcessor).initialized);
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
Ejemplo n.º 4
0
        public void InitializeTelemetryProcessorFromConfigurationFileWhenEmptyTelemetryProcessorsTagSpecified()
        {
            // no TelemetryProcessors - TransmissionProcessor should be automatically created.
            string configFileContents = Configuration(
                @"
                  <TelemetryInitializers>
                  <Add Type=""Microsoft.ApplicationInsights.TestFramework.StubTelemetryInitializer, Microsoft.ApplicationInsights.TestFramework"" />
                  </TelemetryInitializers>
                  <TelemetryProcessors>                  
                  </TelemetryProcessors>"
                );
            var platform = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var configuration = new TelemetryConfiguration();
                new TestableTelemetryConfigurationFactory().Initialize(configuration, null);

                // Assume that LoadFromXml method is called, tested separately
                Assert.True(configuration.TelemetryProcessors != null);
                Assert.IsType <TransmissionProcessor>(configuration.TelemetryProcessors.FirstTelemetryProcessor);
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
Ejemplo n.º 5
0
        public void InitializeTelemetryProcessorFromConfigurationFile()
        {
            string configFileContents = Configuration(
                @"                  
                  <TelemetryProcessors>
                  <Add Type=""Microsoft.ApplicationInsights.TestFramework.StubTelemetryProcessor, Microsoft.ApplicationInsights.TestFramework"" />                  
                  </TelemetryProcessors>"
                );
            var platform = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var configuration = new TelemetryConfiguration();
                new TestableTelemetryConfigurationFactory().Initialize(configuration, null);

                // Assume that LoadFromXml method is called, tested separately
                Assert.True(configuration.TelemetryProcessors != null);
                Assert.IsType <StubTelemetryProcessor>(configuration.TelemetryProcessors.FirstTelemetryProcessor);

                //validate the chain linking stub1->transmission
                var stub1        = (StubTelemetryProcessor)configuration.TelemetryProcessors.FirstTelemetryProcessor;
                var transmission = (TransmissionProcessor)stub1.next;
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
 public void TestInitialize()
 {
     ServiceLocator.AddService<IPlatformService>(new PlatformService());
     ServiceLocator.AddService<IApplicationService>(new ApplicationService());
     this.applicationSettings = new Dictionary<string, object>(); 
     this.platform = new StubPlatform { OnGetApplicationSettings = () => this.applicationSettings, };
     PlatformSingleton.Current = this.platform;
 }
 public SessionTelemetryModuleTest()
 {
     this.platform = new StubPlatform { OnGetApplicationSettings = () => this.settings };
     this.channel = new StubTelemetryChannel { OnSend = t => this.sentTelemetry.Add(t) };
     this.configuration = new TelemetryConfiguration { TelemetryChannel = this.channel, InstrumentationKey = "Test Key" };
     ServiceLocator.AddService<IApplicationService>(new ApplicationService());
     TelemetryConfiguration.Active = configuration;
     HockeyClient.Current.AsInternal().IsTelemetryInitialized = true;
 }
 public void TestInitialize()
 {
     ServiceLocator.AddService <IPlatformService>(new PlatformService());
     ServiceLocator.AddService <IApplicationService>(new ApplicationService());
     this.applicationSettings = new Dictionary <string, object>();
     this.platform            = new StubPlatform {
         OnGetApplicationSettings = () => this.applicationSettings,
     };
     PlatformSingleton.Current = this.platform;
 }
        public void WindowsBootstraperSetInstrumentationKeyWhenSuppliedAndConfigurationFileHasAnEmptyKey()
        {
            string instrumentationKey = Guid.NewGuid().ToString();
            var platform = new StubPlatform { OnReadConfigurationXml = () => Configuration("<InstrumentationKey></InstrumentationKey>") };
            PlatformSingleton.Current = platform;

            WindowsAppInitializer.InitializeAsync(instrumentationKey, new TelemetryConfiguration() { Collectors = WindowsCollectors.Metadata }).GetAwaiter().GetResult();

            Assert.IsFalse(string.IsNullOrEmpty(TelemetryConfiguration.Active.InstrumentationKey));
            Assert.AreEqual(instrumentationKey, TelemetryConfiguration.Active.InstrumentationKey);
        }
Ejemplo n.º 10
0
 public SessionTelemetryModuleTest()
 {
     this.platform = new StubPlatform {
         OnGetApplicationSettings = () => this.settings
     };
     this.channel = new StubTelemetryChannel {
         OnSend = t => this.sentTelemetry.Add(t)
     };
     this.configuration = new TelemetryConfiguration {
         TelemetryChannel = this.channel, InstrumentationKey = "Test Key"
     };
     ServiceLocator.AddService <IApplicationService>(new ApplicationService());
     TelemetryConfiguration.Active = configuration;
     HockeyClient.Current.AsInternal().IsTelemetryInitialized = true;
 }
        public void WindowsBootstraperSetInstrumentationKeyWhenSuppliedAndConfigurationFileHasAnEmptyKey()
        {
            string instrumentationKey = Guid.NewGuid().ToString();
            var    platform           = new StubPlatform {
                OnReadConfigurationXml = () => Configuration("<InstrumentationKey></InstrumentationKey>")
            };

            PlatformSingleton.Current = platform;

            WindowsAppInitializer.InitializeAsync(instrumentationKey, new TelemetryConfiguration()
            {
                Collectors = WindowsCollectors.Metadata
            }).GetAwaiter().GetResult();

            Assert.IsFalse(string.IsNullOrEmpty(TelemetryConfiguration.Active.InstrumentationKey));
            Assert.AreEqual(instrumentationKey, TelemetryConfiguration.Active.InstrumentationKey);
        }
Ejemplo n.º 12
0
        public void InitializesInstanceWithInformationFromConfigurationFileWhenItExists()
        {
            string configFileContents = Configuration("<InstrumentationKey>F8474271-D231-45B6-8DD4-D344C309AE69</InstrumentationKey>");
            var    platform           = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var configuration = new TelemetryConfiguration();
                new TestableTelemetryConfigurationFactory().Initialize(configuration);

                // Assume that LoadFromXml method is called, tested separately
                Assert.False(string.IsNullOrEmpty(configuration.InstrumentationKey));
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
Ejemplo n.º 13
0
        public void InitializeTelemetryModulesFromConfigurationFileWithNoModules()
        {
            string configFileContents = Configuration(
                @"<TelemetryModules>    
                  </TelemetryModules>"
                );

            var platform = new StubPlatform {
                OnReadConfigurationXml = () => configFileContents
            };

            PlatformSingleton.Current = platform;
            try
            {
                var modules = new TestableTelemetryModules();
                new TestableTelemetryConfigurationFactory().Initialize(new TelemetryConfiguration(), modules);

                Assert.Equal(0, modules.Modules.Count);
            }
            finally
            {
                PlatformSingleton.Current = null;
            }
        }
Ejemplo n.º 14
0
 public void CurrentCanBeSetToEnableMocking()
 {
     var platform = new StubPlatform();
     PlatformSingleton.Current = platform;
     Assert.AreSame(platform, PlatformSingleton.Current);
 }