Esempio n. 1
0
        Task RunTests(Func <IReadOnlyList <AssemblyRunInfo> > testCaseAccessor)
        {
            var tcs = new TaskCompletionSource <object>(null);

            Action handler = () =>
            {
                var toDispose = new List <IDisposable>();

                try
                {
                    cancelled = false;
                    var assemblies            = testCaseAccessor();
                    var parallelizeAssemblies = assemblies.All(runInfo => runInfo.Configuration.ParallelizeAssemblyOrDefault);


                    using (AssemblyHelper.SubscribeResolve())
                    {
                        if (parallelizeAssemblies)
                        {
                            assemblies
                            .Select(runInfo => RunTestsInAssemblyAsync(toDispose, runInfo))
                            .ToList()
                            .ForEach(@event => @event.WaitOne());
                        }
                        else
                        {
                            assemblies
                            .ForEach(runInfo => RunTestsInAssembly(toDispose, runInfo));
                        }
                    }
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                }
                finally
                {
                    toDispose.ForEach(disposable => disposable.Dispose());
                    //    OnTestRunCompleted();
                    tcs.TrySetResult(null);
                }
            };

            ThreadPoolHelper.RunAsync(handler);

            return(tcs.Task);
        }
Esempio n. 2
0
        ManualResetEvent RunTestsInAssemblyAsync(List <IDisposable> toDispose, AssemblyRunInfo runInfo)
        {
            var @event = new ManualResetEvent(false);

            void Handler()
            {
                try
                {
                    RunTestsInAssembly(toDispose, runInfo);
                }
                finally
                {
                    @event.Set();
                }
            }

            ThreadPoolHelper.RunAsync(Handler);

            return(@event);
        }
Esempio n. 3
0
        public Task <IReadOnlyList <TestAssemblyViewModel> > Discover()
        {
            var tcs = new TaskCompletionSource <IReadOnlyList <TestAssemblyViewModel> >();

            ThreadPoolHelper.RunAsync(() =>
            {
                try
                {
                    var runInfos = DiscoverTestsInAssemblies();
                    var list     = runInfos.Select(ri => new TestAssemblyViewModel(ri, this))
                                   .ToList();

                    tcs.SetResult(list);
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                }
            });

            return(tcs.Task);
        }