示例#1
0
 public void CreateKeyValuePair_EmptyValueParam_ThrowsArgNullException()
 {
     // Arrange
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => TelemetryProvider.CreateKeyValuePair("Key", string.Empty));
 }
示例#2
0
 public void WriteMenuCommandEvent_EmptyToolFormatParam_ThrowsArgNullException()
 {
     // Arrange
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => TelemetryProvider.WriteMenuCommandEvent(string.Empty));
 }
示例#3
0
 public void WriteEvent_EmptyDataParam_ThrowsArgNullException()
 {
     // Arrange
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded, string.Empty));
 }
示例#4
0
        public void WriteEvent_EventNameAndDictionary_GetsSent()
        {
            // Arrange
            List <KeyValuePair <string, string> > pairs = new List <KeyValuePair <string, string> >()
            {
                TelemetryProvider.CreateKeyValuePair("Key1", "Value1"),
                TelemetryProvider.CreateKeyValuePair("Key2", "Value2")
            };
            Dictionary <string, string> dictionary = pairs.ToDictionary(x => x.Key, x => x.Value);
            EventTelemetry item = new EventTelemetry(TelemetryEvent.ViewerExtensionLoaded.ToString());

            pairs.ForEach(p => item.Properties.Add(p));
            Mock <ITelemetryChannel> mockChannel = InitializeTelemetryProvider();

            mockChannel.Setup(m => m.Send(item));
            mockChannel.Setup(m => m.Flush());

            // Act
            TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded, dictionary);

            // Assert
            mockChannel.Verify(c => c.Send(It.Is <EventTelemetry>(t => t.Properties["Key1"] == "Value1" &&
                                                                  t.Properties["Key2"] == "Value2")));
            mockChannel.Verify(c => c.Flush());
        }
示例#5
0
        public void CreateKeyValuePair_Succeeds()
        {
            // Arrange
            var control = new KeyValuePair <string, string>("Keymaster", "Gatekeeper");

            // Act
            var result = TelemetryProvider.CreateKeyValuePair("Keymaster", "Gatekeeper");

            // Assert
            Assert.Equal(control.Key, result.Key);
            Assert.Equal(control.Value, result.Value);
        }
示例#6
0
        private Mock <ITelemetryChannel> InitializeTelemetryProvider()
        {
            var mockChannel = new Mock <ITelemetryChannel>();
            TelemetryConfiguration configuration = new TelemetryConfiguration()
            {
                TelemetryChannel   = mockChannel.Object,
                InstrumentationKey = Guid.Empty.ToString()
            };

            TelemetryProvider.Reset();
            TelemetryProvider.Initialize(configuration);

            return(mockChannel);
        }
示例#7
0
        internal static void ProcessSarifLog(SarifLog sarifLog, string logFilePath, Solution solution)
        {
            // Clear previous data
            SarifTableDataSource.Instance.CleanAllErrors();
            CodeAnalysisResultManager.Instance.SarifErrors.Clear();
            CodeAnalysisResultManager.Instance.FileDetails.Clear();

            foreach (Run run in sarifLog.Runs)
            {
                TelemetryProvider.WriteEvent(TelemetryEvent.LogFileRunCreatedByToolName,
                                             TelemetryProvider.CreateKeyValuePair("ToolName", run.Tool.Name));
                Instance.WriteRunToErrorList(run, logFilePath, solution);
            }
        }
示例#8
0
        public void WriteEvent_EventName_GetsSent()
        {
            // Arrange
            EventTelemetry           item        = new EventTelemetry(TelemetryEvent.ViewerExtensionLoaded.ToString());
            Mock <ITelemetryChannel> mockChannel = InitializeTelemetryProvider();

            mockChannel.Setup(m => m.Send(item));
            mockChannel.Setup(m => m.Flush());

            // Act
            TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded);

            // Assert
            mockChannel.Verify(c => c.Send(It.Is <EventTelemetry>(t => t.Name == item.Name)));
            mockChannel.Verify(c => c.Flush());
        }
        internal static void ProcessSarifLog(SarifLog sarifLog, string logFilePath, Solution solution, bool showMessageOnNoResults)
        {
            // Clear previous data
            CodeAnalysisResultManager.Instance.ClearCurrentMarkers();
            SarifTableDataSource.Instance.CleanAllErrors();
            CodeAnalysisResultManager.Instance.RunDataCaches.Clear();

            bool hasResults = false;

            foreach (Run run in sarifLog.Runs)
            {
                // run.tool is required, add one if it's missing
                if (run.Tool == null)
                {
                    run.Tool = new Tool
                    {
                        Driver = new ToolComponent
                        {
                            Name = Resources.UnknownToolName
                        }
                    };
                }

                TelemetryProvider.WriteEvent(TelemetryEvent.LogFileRunCreatedByToolName,
                                             TelemetryProvider.CreateKeyValuePair("ToolName", run.Tool.Driver.Name));
                if (Instance.WriteRunToErrorList(run, logFilePath, solution) > 0)
                {
                    hasResults = true;
                }
            }

            // We are finished processing the runs, so make this property inavalid.
            CodeAnalysisResultManager.Instance.CurrentRunId = -1;

            if (!hasResults && showMessageOnNoResults)
            {
                VsShellUtilities.ShowMessageBox(SarifViewerPackage.ServiceProvider,
                                                string.Format(Resources.NoResults_DialogMessage, logFilePath),
                                                null, // title
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
示例#10
0
        public void WriteEvent_EventNameAndData_GetsSent()
        {
            // Arrange
            string         data = "The quick brown fox";
            EventTelemetry item = new EventTelemetry(TelemetryEvent.ViewerExtensionLoaded.ToString());

            item.Properties.Add("Data", data);
            Mock <ITelemetryChannel> mockChannel = InitializeTelemetryProvider();

            mockChannel.Setup(m => m.Send(item));
            mockChannel.Setup(m => m.Flush());

            // Act
            TelemetryProvider.WriteEvent(TelemetryEvent.ViewerExtensionLoaded, data);

            // Assert
            mockChannel.Verify(c => c.Send(It.Is <EventTelemetry>(t => t.Properties["Data"] == data)));
            mockChannel.Verify(c => c.Flush());
        }
示例#11
0
        public void WriteMenuCommandEvent_ToolFormat_GetsSent()
        {
            // Arrange
            string         format = "SARIF";
            EventTelemetry item   = new EventTelemetry(TelemetryEvent.LogFileOpenedByMenuCommand.ToString());

            item.Properties.Add("Format", format);
            Mock <ITelemetryChannel> mockChannel = InitializeTelemetryProvider();

            mockChannel.Setup(m => m.Send(item));
            mockChannel.Setup(m => m.Flush());

            // Act
            TelemetryProvider.WriteMenuCommandEvent(format);

            // Assert
            mockChannel.Verify(c => c.Send(It.Is <EventTelemetry>(t => t.Name == item.Name &&
                                                                  t.Properties["Format"] == format)));
            mockChannel.Verify(c => c.Flush());
        }
        internal static void ProcessSarifLog(SarifLog sarifLog, string logFilePath, Solution solution)
        {
            // Clear previous data
            SarifTableDataSource.Instance.CleanAllErrors();
            CodeAnalysisResultManager.Instance.SarifErrors.Clear();
            CodeAnalysisResultManager.Instance.FileDetails.Clear();

            bool hasResults = false;

            foreach (Run run in sarifLog.Runs)
            {
                // run.tool is required, add one if it's missing
                if (run.Tool == null)
                {
                    run.Tool = new Tool
                    {
                        Name = Resources.UnknownToolName
                    };
                }

                TelemetryProvider.WriteEvent(TelemetryEvent.LogFileRunCreatedByToolName,
                                             TelemetryProvider.CreateKeyValuePair("ToolName", run.Tool.Name));
                if (Instance.WriteRunToErrorList(run, logFilePath, solution) > 0)
                {
                    hasResults = true;
                }
            }

            if (!hasResults)
            {
                VsShellUtilities.ShowMessageBox(SarifViewerPackage.ServiceProvider,
                                                string.Format(Resources.NoResults_DialogMessage, logFilePath),
                                                null, // title
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
示例#13
0
        public void Test_TelemetryProvider_Methods()
        {
            mockConfiguration.Setup(x => x[It.IsNotNull <string>()]).Returns("b92bcd6b-a8b3-433d-8fc5-5cdf60e974f3");

            var telemetryProvider = new TelemetryProvider(mockConfiguration.Object);

            Assert.DoesNotThrow(() => telemetryProvider.TrackEvent("Test event"));
            Assert.DoesNotThrow(() => telemetryProvider.TrackEvent("Test event", new Dictionary <string, string>()
            {
                { "test key", "test value" }
            }));
            Assert.DoesNotThrow(() => telemetryProvider.TrackEvent("Test event",
                                                                   new Dictionary <string, string>()
            {
                { "test key", "test value" }
            }, new Dictionary <string, double>()
            {
                { "test key", 3242 }
            }));
            Assert.DoesNotThrow(() => telemetryProvider.TrackTrace("Test trace"));
            Assert.DoesNotThrow(() => telemetryProvider.TrackMetric("Test metric", 10));
            Assert.DoesNotThrow(() => telemetryProvider.TrackException(new Exception("Test exception")));
            Assert.DoesNotThrow(() => telemetryProvider.TrackDependency("Test dependency", "type name", "data", DateTime.Now, new TimeSpan(), true));
        }
示例#14
0
 public void Include(TelemetryProvider vm)
 {
     var vm1 = new TelemetryProvider(null, null);
 }
示例#15
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            #if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                DebugSettings.EnableFrameRateCounter = true;
            }
            #endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat application initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            // add needed objects to IoC container
            var locator = Resources[LocaterResource] as ViewModelLocator;
            if (locator != null)
            {
                var container = locator.Container;
                container.Register(locator);

                var dateTimeTask = new DateTimeProvider(container);
                container.Register(dateTimeTask);
                dateTimeTask.Start();

                var client = new MqttClient(MqttBrokerAddress);
                container.Register(client);

                var telemetryProvider = new TelemetryProvider(container);
                container.Register(telemetryProvider);

                var rssProvider = new RssProvider(container);
                container.Register(rssProvider);
                rssProvider.Start();

                var speechInterpreter = new SpeechInterpreter(container);
                container.Register(speechInterpreter);
                speechInterpreter.Start();

                var WeatherProvider = new WeatherProvider(container);
                container.Register(WeatherProvider);

                var ioProvider = new IOProvider(container);
                container.Register(ioProvider);
            }

            ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
            if (locator != null)
            {
                var container = locator.Container;
                container.Register(Window.Current);
            }
        }
示例#16
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat application initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            // add needed objects to IoC container
            var locator = Resources[LocaterResource] as ViewModelLocator;
            if (locator != null)
            {
                var container = locator.Container;
                container.Register(locator);

                var dateTimeTask = new DateTimeProvider(container);
                container.Register(dateTimeTask);
                dateTimeTask.Start();

                var client = new MqttClient(MqttBrokerAddress);
                container.Register(client);

                var telemetryProvider = new TelemetryProvider(container);
                container.Register(telemetryProvider);

                var rssProvider = new RssProvider(container);
                container.Register(rssProvider);
                rssProvider.Start();

                var speechInterpreter = new SpeechInterpreter(container);
                container.Register(speechInterpreter);
                speechInterpreter.Start();

                var WeatherProvider = new WeatherProvider(container);
                container.Register(WeatherProvider);

                var ioProvider = new IOProvider(container);
                container.Register(ioProvider);
            }

            ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
            if (locator != null)
            {
                var container = locator.Container;
                container.Register(Window.Current);
            }
        }