public void TestAsyncDetection()
 {
     Detector detector = new Detector();
     detector.Load(@"..\..\..\SampleDetector\bin\Debug\SampleDetector.dll");
     Microsoft.Protocols.TestManager.Detector.Prerequisites prerequisits = detector.GetPrerequisits();
     AutoResetEvent autoEvent = new AutoResetEvent(false);
     DetectionOutcome outcome = null;
     detector.BeginDetection((o) =>
         {
             outcome = o;
             autoEvent.Set();
         }
     );
     autoEvent.WaitOne();
     Assert.AreEqual(DetectionStatus.Error, outcome.Status, "Error should occur");
     Assert.IsNotNull(outcome.Exception, "Check exception");
 }
        /// <summary>
        /// Start the auto-detection
        /// </summary>
        /// <param name="callback">The call back function when the detection finished.</param>
        public void StartDetection(DetectionCallback callback)
        {
            stepIndex   = 0;
            detectorLog = Path.Combine(appConfig.AppDataDirectory, "Detector_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff") + ".log");
            logWriter   = new StreamWriter(detectorLog);
            detector.DetectLogCallback = (msg, style) =>
            {
                if (stepIndex == detectSteps.Count)
                {
                    return;
                }
                var item = detectSteps[stepIndex];
                item.Style = style;
                switch (style)
                {
                case Microsoft.Protocols.TestManager.Detector.LogStyle.Default:
                    detectSteps[stepIndex].DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Detecting;
                    break;

                case Microsoft.Protocols.TestManager.Detector.LogStyle.Error:
                    stepIndex++;
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Error;
                    break;

                case Microsoft.Protocols.TestManager.Detector.LogStyle.StepFailed:
                    stepIndex++;
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Failed;
                    break;

                case Microsoft.Protocols.TestManager.Detector.LogStyle.StepSkipped:
                    stepIndex++;
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Skipped;
                    break;

                case Microsoft.Protocols.TestManager.Detector.LogStyle.StepNotFound:
                    stepIndex++;
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.NotFound;
                    break;

                case Microsoft.Protocols.TestManager.Detector.LogStyle.StepPassed:
                    stepIndex++;
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Finished;
                    break;

                default:
                    item.DetectingStatus = Microsoft.Protocols.TestManager.Detector.DetectingStatus.Pending;
                    break;
                }
                logWriter.WriteLine("[{0}] {1}", DateTime.Now.ToString(), msg);
                logWriter.Flush();
            };
            detector.BeginDetection((outcome) =>
            {
                if (stepIndex < detectSteps.Count)
                {
                    detectSteps[stepIndex].DetectingStatus = TestManager.Detector.DetectingStatus.Pending;
                }
                callback(outcome);
                logWriter.Close();
                logWriter = null;
            });
        }