private AnalysisResult2[] TestAnalysisCoordinator(ISegment <FileInfo>[] segments)
        {
            Contract.Requires(segments != null);

            var preparer = new DummySourcePreparer();

            AnalysisCoordinator coordinator = new AnalysisCoordinator(
                preparer,
                saveIntermediateWavFiles: SaveBehavior.Always,
                uniqueDirectoryPerSegment: false,
                isParallel: false);

            IAnalyser2 dummyAnalyzer = new DummyAnalyzer(false);
            var        settings      = dummyAnalyzer.DefaultSettings;

            settings.AnalysisOutputDirectory = this.TestOutputDirectory;
            settings.AnalysisTempDirectory   = this.TestOutputDirectory.Combine("Temp");

            return(coordinator.Run(segments, dummyAnalyzer, settings));
        }
        private void TestAnalysisCoordinatorPaths(SaveBehavior wav, bool unique, DirectoryInfo temp, State[] states)
        {
            Contract.Requires(states.Length == 5);

            var preparer = new DummySourcePreparer();

            AnalysisCoordinator coordinator = new AnalysisCoordinator(
                preparer,
                saveIntermediateWavFiles: wav,
                uniqueDirectoryPerSegment: unique,
                isParallel: false);

            // an empty non-existent file
            var source = TempFileHelper.NewTempFile(this.TestOutputDirectory).Touch();

            FileSegment segment = new FileSegment(source, duration: 120.0.Seconds(), sampleRate: 123456);

            var dummyAnalyzer = new DummyAnalyzer(true);
            var settings      = dummyAnalyzer.DefaultSettings;

            Trace.WriteLine("Class output directory:" + this.TestOutputDirectory.FullName);

            settings.AnalysisMaxSegmentDuration = 60.Seconds();
            settings.AnalysisOutputDirectory    = this.AnalysisOutput;
            settings.AnalysisTempDirectory      = temp;

            this.settingsAccessor.Fields["fallbackTempDirectory"]?.SetValue(settings, this.FallbackTemp.FullName);

            var task = Task.Run(() =>
            {
                var results = coordinator.Run(segment, dummyAnalyzer, settings);

                // summarize is currently called manually
                dummyAnalyzer.SummariseResults(settings, segment, null, null, null, results);
            });

            // set up path strings
            string basename = Path.GetFileNameWithoutExtension(source.Name);
            var    paths    = new CoordinatorPathTestSet
            {
                output   = this.AnalysisOutput.FullName,
                temp     = (temp ?? this.TestTemp).FullName,
                tempNull = this.FallbackTemp.FullName,
                fragment = "Ecosounds.TempusSubstitutus",
                unique1  = basename + "_000000.00-000060.00",
                unique2  = basename + "_000060.00-000120.00",
                source   = basename,
            };

            // wait for the analyzer to pause
            while (!dummyAnalyzer.IsPaused)
            {
                Thread.Sleep(0);
            }

            // manually pump the analysis
            // before analyze
            this.AssertFilesAreAsExpected(0, states[0], paths);

            dummyAnalyzer.Pump();

            // segment 1
            this.AssertFilesAreAsExpected(1, states[1], paths);

            dummyAnalyzer.Pump();

            // segment 2
            this.AssertFilesAreAsExpected(2, states[2], paths);

            dummyAnalyzer.Pump();

            // after summarize
            this.AssertFilesAreAsExpected(3, states[3], paths);

            // complete
            // TODO: remove this rubbish and stick in a IoC file system for testing!
            dummyAnalyzer.Pump(false);
            do
            {
                Thread.Sleep(0.5.Seconds());
                dummyAnalyzer.Pump(false);
            }while (!task.IsCompleted);
            task.Wait(1.0.Seconds());

            this.AssertFilesAreAsExpected(4, states[4], paths);

            Assert.IsTrue(task.IsCompleted, "task was not yet completed");
        }