private void TestItem_Click(object sender, RoutedEventArgs e)
        {
            WirelessUnitTest test = ((MenuItem)sender).DataContext as WirelessUnitTest;

            if (test != null)
            {
                WirelessUnitTestInstance instance = WirelessUnitTestInstance.RunUnitTest(Network, test);
                MessageBox.Show(instance.TestPassed ? "Passed!" : "Failed!");
            }
        }
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            int count     = IterationCount;
            int pass      = 0;
            int fail      = 0;
            int completed = 0;

            // Determine which test to use
            WirelessUnitTest test = ((ComboBoxItem)comboSelectTest.SelectedItem)?.DataContext as WirelessUnitTest;

            if (test == null)
            {
                return;
            }

            listBox.Items.Clear();
            listBox.Items.Add(new ListBoxItem()
            {
                Content = $"Starting {count} iterations of {test.UnitTestMethod.Name}", Background = Brushes.LightBlue
            });


            btnStart.IsEnabled = false;
            ThreadPool.QueueUserWorkItem((context) =>
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Parallel.For(0, count, (index) =>
                {
                    WirelessUnitTestInstance instance = WirelessUnitTestInstance.RunUnitTest(LinkedWindow.Network, test);

                    if (instance.TestPassed)
                    {
                        Interlocked.Increment(ref pass);
                    }
                    else
                    {
                        Interlocked.Increment(ref fail);

                        Dispatcher.Invoke(() =>
                        {
                            ListBoxItem lb = new ListBoxItem()
                            {
                                Content = $"({index}) Test Failed: {instance.TestException.ToString()}", DataContext = instance, Background = Brushes.LightPink
                            };
                            lb.MouseDoubleClick += OpenTestFailureItem;
                            listBox.Items.Add(lb);
                        });
                    }
                    if (Interlocked.Increment(ref completed) % 50 == 0)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            Title = $"Running tests... ({(pass + fail)}/{count})";
                        });
                    }
                });
                sw.Stop();

                double ms = Math.Floor(sw.Elapsed.TotalMilliseconds * 100) / 100;

                Dispatcher.Invoke(() => {
                    listBox.Items.Add(new ListBoxItem()
                    {
                        Content = $"Completed in {ms}ms. {pass} Passed, {fail} Failed.", Background = Brushes.LightBlue
                    });

                    Title = "Run Unit Tests";
                    btnStart.IsEnabled = true;
                });
            });
        }