Example #1
0
        public int Run(RunnerInvocation invocation, Func <RunnerInvocation, int> action, string dll)
        {
            this.dll = dll;

            var setup = new AppDomainSetup();

            setup.ConfigurationFile = Path.GetFullPath(config);

            setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            domain = AppDomain.CreateDomain("NSpecDomain.Run", null, setup);

            var type = typeof(Wrapper);

            var assemblyName = type.Assembly.GetName().Name;

            var typeName = type.FullName;

            domain.AssemblyResolve += Resolve;

            var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);

            var failures = wrapper.Execute(invocation, action);

            AppDomain.Unload(domain);

            return(failures);
        }
        public void Setup()
        {
            formatter = new XUnitFormatter();

            outDirPath = Path.Combine(
                Path.GetTempPath(),
                "NSpec.Tests",
                nameof(describe_XUnitFormatter));

            Directory.CreateDirectory(outDirPath);

            outFilePath = Path.Combine(
                outDirPath,
                Path.ChangeExtension(Path.GetRandomFileName(), "xml"));

            formatter.Options = new Dictionary <string, string>()
            {
                { "file", outFilePath },
            };

            var invocation = new RunnerInvocation(
                dll: typeof(describe_XUnitFormatter).GetTypeInfo().Assembly.Location,
                tags: typeof(xunit_formatter_sample_spec).Name,
                formatter: formatter,
                failFast: false);

            contexts = invocation.Run();
        }
Example #3
0
        public void Setup()
        {
            formatter = new FormatterStub();

            var invocation = new RunnerInvocation(typeof(describe_LiveFormatter_with_context_filter).GetTypeInfo().Assembly.Location, typeof(liveconsole_sample_spec).Name, formatter, false);

            contexts = invocation.Run();
        }
        public void Setup()
        {
            formatter = new FormatterStub();

            var invocation = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, typeof(liveconsole_sample_spec).Name, formatter, false);

            contexts = invocation.Run();
        }
Example #5
0
        static void Main(string[] args)
        {
            var shouldShowHelp = false;

            var useXUnitFormatter = false;

            var options = new OptionSet
            {
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null },
                { "f|formatter", "console (default) | xunit",
                  f => useXUnitFormatter = string.Compare(f, "xunit", StringComparison.InvariantCultureIgnoreCase) == 0 }
            };

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: [OPTIONS] path/to/test.assembly.dll path/to/test.2.assembly.dll");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
            }

            IFormatter formatter = null;

            if (useXUnitFormatter)
            {
                formatter = new XUnitFormatter();
            }
            else
            {
                formatter = new ConsoleFormatter();
            }

            IEnumerable <FileInfo> extra;

            try
            {
                extra = options.Parse(args).Select(n => new FileInfo(n)).Where(n => n.Exists);

                foreach (var asm in extra)
                {
                    var invocation = new RunnerInvocation(asm.FullName, null, formatter, false);

                    var result = invocation.Run();
                    var failes = result.Failures().ToArray();

                    if (failes.Any())
                    {
                        throw new Exception($"NSpec run of {asm} reported Failures");
                    }
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `--help' for more information.");
                return;
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            var ri = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, "", false);

            ri.Run();

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
Example #7
0
        public void DebugAppSettingKeyCollectionSpecs()
        {
            const string tagOrClassName = "AppSettingKeyCollectionSpecs";
            var          invocation     = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, tagOrClassName);
            var          contexts       = invocation.Run();

            //assert that there aren't any failures
            contexts.Failures().Count().should_be(0);
        }
Example #8
0
    //tests can be run via TDD.net
    public void debug()
    {
        var tagOrClassName = "";

        var invocation = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, tagOrClassName);

        var contexts = invocation.Run();

        contexts.Failures().Count().should_be(0);
    }
Example #9
0
        public static void Main(string[] args)
        {
            var ri      = new RunnerInvocation(Assembly.GetEntryAssembly().Location, "", false);
            var results = ri.Run();

            if (results.Failures().Count() > 0)
            {
                Environment.Exit(1);
            }
        }
Example #10
0
    //[Test]
    public void debug()
    {
        var tagOrClassName = "describe_RollOffsController";

        var invocation = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, tagOrClassName);

        var contexts = invocation.Run();

        //assert that there aren't any failures
        contexts.Failures().Count().should_be(0);
    }
Example #11
0
    //[Test]
    public void debug()
    {
        var tagOrClassName = "class_or_tag_you_want_to_debug";

        var invocation = new RunnerInvocation(Assembly.GetExecutingAssembly().Location, tagOrClassName);

        var contexts = invocation.Run();

        //assert that there aren't any failures
        contexts.Failures().Count().should_be(0);
    }
Example #12
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowUsage();
                return;
            }
            try
            {
                // extract either a class filter or a tags filter (but not both)
                var argsTags = "";

                var failFast           = IsFailFast(args);
                var formatterClassName = GetFormatterClassName(args);

                var formatter = FindFormatter(formatterClassName);

                args = RemoveOptionsAndSwitches(args);

                if (args.Length > 1)
                {
                    // see rspec and cucumber for ideas on better ways to handle tags on the command line:
                    // https://github.com/cucumber/cucumber/wiki/tags
                    // https://www.relishapp.com/rspec/rspec-core/v/2-4/docs/command-line/tag-option
                    if (args[1] == "--tag" && args.Length > 2)
                    {
                        argsTags = args[2];
                    }
                    else
                    {
                        argsTags = args[1];
                    }
                }

                var specDLL = args[0];

                var invocation = new RunnerInvocation(specDLL, argsTags, formatter, failFast);

                var domain = new NSpecDomain(specDLL + ".config");

                var failures = domain.Run(invocation, i => i.Run().Failures().Count(), specDLL);

                if (failures > 0)
                {
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                //hopefully this is handled before here, but if not, this is better than crashing the runner
                Console.WriteLine(e);
                Environment.Exit(1);
            }
        }
Example #13
0
        public BatchExampleRunner(
            string testAssemblyPath,
            string tags,
            string formatterClassName,
            IDictionary <string, string> formatterOptions,
            bool failFast)
        {
            var formatter = FindFormatter(formatterClassName, formatterOptions);

            invocation = new RunnerInvocation(testAssemblyPath, tags, formatter, failFast);
        }
Example #14
0
        public SessionResults RunAssembly(Assembly assembly, IEnumerable <string> filters)
        {
            var sessionResults = new SessionResults();
            var tags           = string.Empty;

            if (filters.Any())
            {
                tags = filters.Aggregate((working, next) => working + "," + next);
            }
            var runner = new RunnerInvocation(assembly.Location, tags, new GilesSessionResultsFormatter(sessionResults), false);

            runner.Run();
            return(sessionResults);
        }
        public void NSpec()
        {
            if (nspecCollection != null)
            {
                foreach (var tagOrClassName in nspecCollection)
                {
                    var invocation = new RunnerInvocation(targetLocation, tagOrClassName);

                    var contexts = invocation.Run();

                    // Uncomment the below line if the test invocation is to be stopped
                    // as soon as a failure is detected.

                    contexts.Failures().Count().should_be(0);
                }
            }
        }
Example #16
0
 public ContextWrapper Execute(RunnerInvocation invocation, Func <RunnerInvocation, ContextWrapper> action)
 {
     return(action(invocation));
 }
Example #17
0
 public int Execute(RunnerInvocation invocation, Func <RunnerInvocation, int> action)
 {
     return(action(invocation));
 }