Skip to content

Instantly share code, notes, and snippets.

Created September 8, 2017 01:35
Show Gist options
  • Save anonymous/ad879b967eb88b283c9941f9c3455d13 to your computer and use it in GitHub Desktop.
Save anonymous/ad879b967eb88b283c9941f9c3455d13 to your computer and use it in GitHub Desktop.
Same as amirrajan, working on .net core 2.0 on ubuntu machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using NSpec;
using System.IO;
using NSpec.Api;
using NSpec.Domain; // SpecFinder
using NSpec.Domain.Formatters; // ConsoleFormatter
namespace Calculator.specs
{
class Program
{
/*
* Original version, from NSpec documentation, or Gist example:
var types = GetType().GetTypeInfo().Assembly.GetTypes();
* leads to:
Program.cs(17,21): error CS0120: An object reference is required for
the nonstatic field, method, or property 'member'
'object.GetType()' [./Calculator/specs/specs.csproj]
*/
static void Main(string[] args)
{
// lazy way : var types = (new Program()).GetType().GetTypeInfo().Assembly.GetTypes();
// Quite correct way:
var types = System.Reflection.MethodInfo.GetCurrentMethod()
.DeclaringTyp‌​e.GetTypeInfo()
.Assembly.GetTypes();
var finder = new SpecFinder(types, "");
var tagsFilter = new Tags().Parse("");
var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
var runner = new ContextRunner(tagsFilter, new ConsoleFormatter(), false);
var results = runner.Run(builder.Contexts().Build());
if(results.Failures().Count() > 0)
{
Environment.Exit(1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment