コード例 #1
0
ファイル: UniqueValues.cs プロジェクト: gezidan/ZYSOCKET
        public static int Count(IEnumerable actual)
        {
            NUnit.ObjectList list = new NUnit.ObjectList();

            foreach (object o1 in actual)
                if (!list.Contains(o1))
                    list.Add(o1);

            return list.Count;
        }
コード例 #2
0
ファイル: UniqueValues.cs プロジェクト: zhaopan-vip/ZYSOCKET
        public static int Count(IEnumerable actual)
        {
            NUnit.ObjectList list = new NUnit.ObjectList();

            foreach (object o1 in actual)
            {
                if (!list.Contains(o1))
                {
                    list.Add(o1);
                }
            }

            return(list.Count);
        }
コード例 #3
0
ファイル: TestRunner.cs プロジェクト: rolfbjarne/guiunit
        void ExecuteWithListener(string[] args, TcpWriter tcpWriter)
        {
            if (!commandLineOptions.NoHeader)
            {
                WriteHeader(this.writer);
            }

            if (commandLineOptions.ShowHelp)
            {
                writer.Write(commandLineOptions.HelpText);
            }
            else if (commandLineOptions.Error)
            {
                writer.WriteLine(commandLineOptions.ErrorMessage);
                writer.WriteLine(commandLineOptions.HelpText);
            }
            else
            {
                WriteRuntimeEnvironment(this.writer);

                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                {
                    writer.WriteLine("Ignoring /wait option - only valid for Console");
                }

                                #if SILVERLIGHT
                IDictionary loadOptions = new System.Collections.Generic.Dictionary <string, string>();
                                #else
                IDictionary loadOptions = new Hashtable();
                                #endif
                //if (options.Load.Count > 0)
                //    loadOptions["LOAD"] = options.Load;

                //IDictionary runOptions = new Hashtable();
                //if (commandLineOptions.TestCount > 0)
                //    runOptions["RUN"] = commandLineOptions.Tests;

                ITestFilter filter = commandLineOptions.TestCount > 0
                                        ? new SimpleNameFilter(commandLineOptions.Tests)
                                                : TestFilter.Empty;

                try
                {
                    if (TestRunner.LoadFileMethod != null)
                    {
                        foreach (string name in commandLineOptions.Parameters)
                        {
                            assemblies.Add(TestRunner.LoadFileMethod.Invoke(null, new[] { Path.GetFullPath(name) }));
                        }
                    }

                    if (assemblies.Count == 0)
                    {
                        assemblies.Add(Assembly.GetEntryAssembly());
                    }

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0] as Assembly;

                    if (!runner.Load(assembly, loadOptions))
                    {
                        AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly);
                        Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                    {
                        ExploreTests();
                    }
                    else
                    {
                        if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
                        {
                            TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

                            if (filter.IsEmpty)
                            {
                                filter = includeFilter;
                            }
                            else
                            {
                                filter = new AndFilter(filter, includeFilter);
                            }
                        }

                        if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
                        {
                            TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

                            if (filter.IsEmpty)
                            {
                                filter = excludeFilter;
                            }
                            else if (filter is AndFilter)
                            {
                                ((AndFilter)filter).Add(excludeFilter);
                            }
                            else
                            {
                                filter = new AndFilter(filter, excludeFilter);
                            }
                        }

                        if (MainLoop == null)
                        {
                            RunTests(filter);
                        }
                        else
                        {
                            MainLoop.InitializeToolkit();
                            System.Threading.ThreadPool.QueueUserWorkItem(d => {
                                try {
                                    RunTests(filter);
                                } catch (Exception ex) {
                                    Console.WriteLine("Unexpected error while running the tests: {0}", ex);
                                } finally {
                                    Shutdown();
                                }
                            });
                            MainLoop.RunMainLoop();
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.ToString());
                    ExitCode = 1;
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #4
0
ファイル: TextUI.cs プロジェクト: stride3d/nunitlite
        /// <summary>
        /// Execute a test run based on the aruments passed
        /// from Main.
        /// </summary>
        /// <param name="args">An array of arguments</param>
        public void Execute(string[] args)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
            {
                this.writer = new StreamWriter(commandLineOptions.OutFile);
            }

            if (!commandLineOptions.NoHeader)
            {
                WriteHeader(this.writer);
            }

            if (commandLineOptions.ShowHelp)
            {
                writer.Write(commandLineOptions.HelpText);
            }
            else if (commandLineOptions.Error)
            {
                writer.WriteLine(commandLineOptions.ErrorMessage);
                writer.WriteLine(commandLineOptions.HelpText);
            }
            else
            {
                WriteRuntimeEnvironment(this.writer);

                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                {
                    writer.WriteLine("Ignoring /wait option - only valid for Console");
                }

#if SILVERLIGHT
                IDictionary loadOptions = new System.Collections.Generic.Dictionary <string, string>();
#else
                IDictionary loadOptions = new Hashtable();
#endif
                //if (options.Load.Count > 0)
                //    loadOptions["LOAD"] = options.Load;

                //IDictionary runOptions = new Hashtable();
                //if (commandLineOptions.TestCount > 0)
                //    runOptions["RUN"] = commandLineOptions.Tests;

                ITestFilter filter = commandLineOptions.TestCount > 0
                    ? new SimpleNameFilter(commandLineOptions.Tests)
                    : TestFilter.Empty;

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                    {
                        assemblies.Add(Assembly.Load(name));
                    }

                    if (assemblies.Count == 0)
                    {
                        assemblies.Add(callingAssembly);
                    }

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0] as Assembly;

                    if (!runner.Load(assembly, loadOptions))
                    {
                        AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly);
                        Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                    {
                        ExploreTests();
                    }
                    else
                    {
                        if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
                        {
                            TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

                            if (filter.IsEmpty)
                            {
                                filter = includeFilter;
                            }
                            else
                            {
                                filter = new AndFilter(filter, includeFilter);
                            }
                        }

                        if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
                        {
                            TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

                            if (filter.IsEmpty)
                            {
                                filter = excludeFilter;
                            }
                            else if (filter is AndFilter)
                            {
                                ((AndFilter)filter).Add(excludeFilter);
                            }
                            else
                            {
                                filter = new AndFilter(filter, excludeFilter);
                            }
                        }
                        RunTests(filter);
                    }
                }
                catch (FileNotFoundException ex)
                {
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Execute a test run based on the aruments passed
        /// from Main.
        /// </summary>
        /// <param name="args">An array of arguments</param>
        public void Execute(string[] args)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = ProcessArguments(args);

            if (!commandLineOptions.ShowHelp && !commandLineOptions.Error)
            {
                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                {
                    writer.WriteLine("Ignoring /wait option - only valid for Console");
                }

                IDictionary loadOptions = new Hashtable();
                //if (options.Load.Count > 0)
                //    loadOptions["LOAD"] = options.Load;

                IDictionary runOptions = new Hashtable();
                if (commandLineOptions.TestCount > 0)
                {
                    runOptions["RUN"] = commandLineOptions.Tests;
                }

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                    {
                        assemblies.Add(Assembly.Load(name));
                    }

                    if (assemblies.Count == 0)
                    {
                        assemblies.Add(callingAssembly);
                    }

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0] as Assembly;

                    if (!runner.Load(assembly, loadOptions))
                    {
                        Console.WriteLine("No tests found in assembly {0}", assembly.GetName().Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                    {
                        ExploreTests();
                    }
                    else
                    {
                        RunTests();
                    }
                }
                catch (FileNotFoundException ex)
                {
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #6
0
ファイル: TextUI.cs プロジェクト: qipa/NUnitLite
        /// <summary>
        /// Execute a test run based on the aruments passed
        /// from Main.
        /// </summary>
        /// <param name="args">An array of arguments</param>
        public void Execute(string[] args)
        {
            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (runner == null)
            {
#if MONODROID_TOOLS
                if (!string.IsNullOrEmpty(commandLineOptions.Android))
                {
                    runner = AndroidRunner(commandLineOptions.Android);
                }
                else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("android:"))
                {
                    Xamarin.AndroidRemoteRunner.App = commandLineOptions.Remote.Substring(8);
                    runner = DefaultRunner();
                }
                else
#elif MONOTOUCH_TOOLS
                if (!string.IsNullOrEmpty(commandLineOptions.iOS))
                {
                    runner = iOSRunner(commandLineOptions.iOS);
                }
                else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("ios:"))
                {
                    // Xamarin.iOSRemoteRunner.App = commandLineOptions.Remote.Substring (4);
                    // runner = DefaultRunner ();
                    throw new NotImplementedException();
                }
                else
#elif WASM_TOOLS
                if (!string.IsNullOrEmpty(commandLineOptions.WebAssembly))
                {
                    runner = WebAssemblyRunner(commandLineOptions.WebAssembly);
                }
                else if (!string.IsNullOrEmpty(commandLineOptions.Remote) && commandLineOptions.Remote.StartsWith("wasm:"))
                {
                    // Xamarin.WebAssemblyRemoteRunner.App = commandLineOptions.Remote.Substring (5);
                    // runner = DefaultRunner ();
                    throw new NotImplementedException();
                }
                else
#endif
                {
                    runner = DefaultRunner();
                }
            }

            if (commandLineOptions.OutFile != null)
            {
                this.writer = new StreamWriter(commandLineOptions.OutFile);
            }

            if (!commandLineOptions.NoHeader)
            {
                WriteHeader(this.writer);
            }

            if (commandLineOptions.ShowHelp)
            {
                writer.Write(commandLineOptions.HelpText);
            }
            else if (commandLineOptions.Error)
            {
                writer.WriteLine(commandLineOptions.ErrorMessage);
                writer.WriteLine(commandLineOptions.HelpText);
            }
            else
            {
                WriteRuntimeEnvironment(this.writer);

                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                {
                    writer.WriteLine("Ignoring /wait option - only valid for Console");
                }

#if SILVERLIGHT
                IDictionary loadOptions = new System.Collections.Generic.Dictionary <string, string>();
#else
                IDictionary loadOptions = new Hashtable();
#endif
                //if (options.Load.Count > 0)
                //    loadOptions["LOAD"] = options.Load;

                //IDictionary runOptions = new Hashtable();
                //if (commandLineOptions.TestCount > 0)
                //    runOptions["RUN"] = commandLineOptions.Tests;

                ITestFilter filter = commandLineOptions.TestCount > 0
                    ? new SimpleNameFilter(commandLineOptions.Tests)
                    : TestFilter.Empty;

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                    {
                        try {
                            assemblies.Add(Assembly.LoadFrom(name));
                        }
                        catch (FileNotFoundException /* e*/) {
                            assemblies.Add(Assembly.Load(name));
                        }
                    }

                    if (assemblies.Count == 0)
                    {
                        // NOTE: Execute must be directly called from the
                        // test assembly in order for the mechanism to work.
                        Assembly callingAssembly = Assembly.GetCallingAssembly();
                        assemblies.Add(callingAssembly);
                    }

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0] as Assembly;

                    Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    if (!runner.Load(assembly, loadOptions))
                    {
                        AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly);
                        Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                    {
                        ExploreTests();
                    }
                    else
                    {
                        if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
                        {
                            TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

                            if (filter.IsEmpty)
                            {
                                filter = includeFilter;
                            }
                            else
                            {
                                filter = new AndFilter(filter, includeFilter);
                            }
                        }

                        if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
                        {
                            TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

                            if (filter.IsEmpty)
                            {
                                filter = excludeFilter;
                            }
                            else if (filter is AndFilter)
                            {
                                ((AndFilter)filter).Add(excludeFilter);
                            }
                            else
                            {
                                filter = new AndFilter(filter, excludeFilter);
                            }
                        }

#if MONO
                        filter = Xamarin.BabysitterSupport.AddBabysitterFilter(filter);
#endif
                        RunTests(filter);
                    }
                }
                catch (FileNotFoundException ex)
                {
                    Failure = true;
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Failure = true;
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }