예제 #1
0
        Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
        {
            NSpecAssemblyTest assemblyTest;

            if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
            {
                assemblyTest = new NSpecAssemblyTest(assembly.Name, assembly, frameworkVersion);
                assemblyTest.Kind = TestKinds.Assembly;

                ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata);

                string frameworkName = String.Format("NSpec v{0}", frameworkVersion);
                assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
                assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
                assemblyTest.Kind = TestKinds.Assembly;

                parentTest.AddChild(assemblyTest);
                assemblyTests.Add(assembly, assemblyTest);
            }

            if (populateRecursively)
            {
                var reflector = new NSpec.Domain.Reflector(assembly.Path);
                var finder = new SpecFinder(reflector);
                var builder = new ContextBuilder(finder, new DefaultConventions());

                ContextCollection contexts = builder.Contexts();
                contexts.Build();
                contexts.Do(c => assemblyTest.AddChild(this.CreateGallioTestFrom(c)));
            }

            return assemblyTest;
        }
예제 #2
0
        public ContextCollection Run()
        {
            var reflector = new Reflector(this.dll);

            var finder = new SpecFinder(reflector);

            var tagsFilter = new Tags().Parse(Tags);

            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());

            var runner = new ContextRunner(tagsFilter, Formatter, failFast);

            var contexts = builder.Contexts().Build();

            if(contexts.AnyTaggedWithFocus())
            {
                tagsFilter = new Tags().Parse(NSpec.Domain.Tags.Focus);

                builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());

                runner = new ContextRunner(tagsFilter, Formatter, failFast);

                contexts = builder.Contexts().Build();
            }

            return runner.Run(contexts);
        }
예제 #3
0
        public TestCaseDTO[] DiscoverTests()
        {
            var conv = new DefaultConventions().Initialize();
            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb = new ContextBuilder(finder, new Tags());
            var dia = new DiaSession(SandboxedAssembly.Location);

            var examples = cb.Contexts()
                .Build()
                .AllContexts()
                .SelectMany(context => context.Examples);

            var result = from example in examples
                         let method = GetAction(example)
                         let location = dia.GetNavigationData(method.DeclaringType.FullName, method.Name)
                            ?? new DiaNavigationData(null, 0, 0)
                         select new TestCaseDTO
                         {
                             Name = example.FullName(),
                             FileName = location.FileName,
                             LineNumber = location.MinLineNumber,
                             Traits = example.Tags.ToArray()
                         };

            return result.ToArray();
        }
예제 #4
0
    public void debug()
    {
        //the specification class you want to test
        //this can be a regular expression
        var testClassYouWantToDebug = "describe_SomeTest";

        //initialize NSpec's specfinder
        var finder = new SpecFinder(
            Assembly.GetExecutingAssembly().Location,
            new Reflector(),
            testClassYouWantToDebug);

        //initialize NSpec's builder
        var builder = new ContextBuilder(
            finder,
            new DefaultConventions());

        //initialize the root context
        var contexts = builder.Contexts();

        //build the tests
        contexts.Build();

        //run the tests that were found
        contexts.Run();

        //print the output
        new ConsoleFormatter().Write(contexts);

        //assert that there aren't any failures
        contexts.Failures().Count().should_be(0);
    }
예제 #5
0
파일: Program.cs 프로젝트: adiel/NSpec
        static void Main(string[] args)
        {
            if(args.Length==0)
            {
                ShowUsage();
                return;
            }
            try
            {
                var classFilter = args.Length > 1 ? args[1] : "";

                var finder = new SpecFinder(args[0], new Reflector(), classFilter);

                //var finder = new SpecFinder(@"C:\Development\GameTrader\GameTrader.Specs\bin\Debug\GameTrader.Specs.dll", new Reflector(), "desribe_AuthenticationController");
                //var finder = new SpecFinder(@"C:\users\amir\nspec\samplespecs\bin\debug\samplespecs.dll", new Reflector(), "class_level_before");

                var builder = new ContextBuilder(finder);

                new ContextRunner(builder).Run();

                //new ContextRunner(new ContextBuilder(new SpecFinder(@"C:\Development\GameTrader\GameTrader.Specs\bin\Debug\GameTrader.Specs.dll", new Reflector()))).Run();
            }
            catch (Exception e)
            {
                //hopefully this is handled before here, but if not, this is better than crashing the runner
                Console.WriteLine(e);
            }
        }
        public NSpecResultModel Run()
        {
            var reflector = new Reflector(this._dllFile);

            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new Tags().Parse(_tags), new DefaultConventions());

            var runner = new ContextRunner(builder, _formatter, false);

            var contexts = builder.Contexts().Build();

            if (contexts.AnyTaggedWithFocus())
            {
                builder = new ContextBuilder(finder, new Tags().Parse(NSpec.Domain.Tags.Focus), new DefaultConventions());

                runner = new ContextRunner(builder, _formatter, true);
            }

            var contextCollection = runner.Run(contexts);
            
            var serializableContextCollection = new SerializableContextCollection();
            
            BuildResponse(serializableContextCollection, contextCollection);
            
            return new NSpecResultModel { ContextCollection = serializableContextCollection, Output = _formatter.GetFormattedString };
        }
예제 #7
0
        public ContextCollection Run()
        {
            var finder = new SpecFinder(this.dll, new Reflector());

            var builder = new ContextBuilder(finder, new Tags().Parse(Tags), new DefaultConventions());

            var runner = new ContextRunner(builder, Formatter, failFast);

            return runner.Run(builder.Contexts().Build());
        }
예제 #8
0
        public void DebugServiceSpecs()
        {
            const string tagOrClassName = "ServiceSpecs";

            var types = GetType().Assembly.GetTypes();
            var finder = new SpecFinder(types, "");
            var builder = new ContextBuilder(finder, new Tags().Parse(tagOrClassName), new DefaultConventions());
            var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
            var results = runner.Run(builder.Contexts().Build());
            results.Failures().Count().should_be(0);
        }
예제 #9
0
        public ContextCollection Run()
        {
            var reflector = new Reflector(this.dll);
            var finder    = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new Tags().Parse(Tags), new DefaultConventions());

            var runner = new ContextRunner(builder, Formatter, failFast);

            return(runner.Run(builder.Contexts().Build()));
        }
예제 #10
0
        public void Execute(IReceiveTestResult observer)
        {
            this.observer = observer;

            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb = new ContextBuilder(finder, new Tags());

            cb.Contexts()
                .Build()
                .ForEach(context => context.Run(this, false));
        }
        public void it_runs_things_in_a_strange_order()
        {
            SpecFinder finder = new SpecFinder(new[] { typeof(before_all_sampleSpec) });

            var builder = new ContextBuilder(finder, new DefaultConventions());

            var runner = new ContextRunner(builder, new SilentLiveFormatter(), false);

            contexts = runner.Run(builder.Contexts().Build());

            var instance = contexts.Find("before all sampleSpec").GetInstance() as before_all_sampleSpec;

            CollectionAssert.AreEqual(new[] { "messed_up_context", "before_all", "another_messed_up_context", "a_regular_context_method" }, instance.sequence);
        }
예제 #12
0
    public void debug()
    {
        var tagOrClassName = "class_or_tag_you_want_to_debug";

        var types = GetType().Assembly.GetTypes();
        // OR
        types = new System.Type[] { typeof(StatisticsCacheServiceTest.NSpecTests.garbage_collecting_test) };
        var finder = new SpecFinder(types, "");
        var builder = new ContextBuilder(finder, new Tags().Parse(tagOrClassName), new DefaultConventions());
        var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
        var results = runner.Run(builder.Contexts().Build());

        //assert that there aren't any failures
        results.Failures().Count().should_be(0);
    }
예제 #13
0
        public void Execute(IReceiveTestResult observer, string[] testNames)
        {
            this.observer = observer;

            var examples = new HashSet<string>(testNames);

            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb = new ContextBuilder(finder, new Tags());

            cb.Contexts()
                .Build()
                .SelectMany(c => c.AllExamples())
                .Where(example => examples.Contains(example.FullName()))
                .ForEach(example => example.Context.Run(this, false, example.Context.GetInstance()));
        }
예제 #14
0
        public void debug()
        {
            var testClassYouWantToDebug = "";

            var finder = new SpecFinder(
                Assembly.GetExecutingAssembly().Location,
                new Reflector(),
                testClassYouWantToDebug);

            var builder = new ContextBuilder(
                finder,
                new DefaultConventions());

            new ContextRunner(builder, new ConsoleFormatter()).Run();
        }
    //[Test]
    public void debug()
    {
        var tagOrClassName = "";

        var types = GetType().Assembly.GetTypes(); 
        // OR
        // var types = new Type[]{typeof(Some_Type_Containg_some_Specs)};
        var finder = new SpecFinder(types, "");
        var builder = new ContextBuilder(finder, new Tags().Parse(tagOrClassName), new DefaultConventions());
        var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
        var results = runner.Run(builder.Contexts().Build());

        //assert that there aren't any failures
        results.Failures().Count().should_be(0);
    }
예제 #16
0
        public void output_verification(Type output, Type []testClasses, string tags)
        {
            var finder = new SpecFinder(testClasses, "");
            var builder = new ContextBuilder(finder, new Tags().Parse(tags), new DefaultConventions());
            var consoleFormatter = new ConsoleFormatter();

            var actual = new System.Collections.Generic.List<string>();
            consoleFormatter.WriteLineDelegate = actual.Add;

            var runner = new ContextRunner(builder, consoleFormatter, false);
            runner.Run(builder.Contexts().Build());

            var expectedString = ScrubStackTrace(ScrubNewLines(output.GetField("Output").GetValue(null) as string));
            var actualString = ScrubStackTrace(String.Join("\n", actual)).Trim();
            actualString.should_be(expectedString);
        }
예제 #17
0
        public void run()
        {
            var currentSpec = GetType();
            var finder = new SpecFinder(new[] { currentSpec });
            var builder = new ContextBuilder(finder, new Tags().Parse(currentSpec.Name), new DefaultConventions());
            var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
            var collection = builder.Contexts().Build();
            var results = runner.Run(collection);

            //assert that there aren't any failures
            var failures = results.Failures();
            var count = failures.Count();
            count.ShouldBe(0);

            // TODO: figure out how to programmatically skip, when there are pending
        }
예제 #18
0
        public void debug()
        {
            //the specification class you want to test
            //this can be a regular expression
            var testClassYouWantToDebug = "NSpecSpecs.ClassContextBug.Child";

            //initialize NSpec's specfinder
            var finder = new SpecFinder(
                Assembly.GetExecutingAssembly().Location,
                new Reflector(),
                testClassYouWantToDebug );

            //initialize NSpec's builder
            var builder = new ContextBuilder( finder, new DefaultConventions() );

            //this line runs the tests you specified in the filter
            TestFormatter formatter = new TestFormatter();
            new ContextRunner( builder, formatter ).Run();

            Context grandParent = formatter.Contexts[0];
            Assert.That( grandParent.Name, Is.EqualTo( "Grand Parent" ) );
            Assert.That( grandParent.Contexts.Count, Is.EqualTo( 2 ) );
            Assert.That( grandParent.Contexts[0].Name, Is.EqualTo( "Grand Parent Context" ) );
            Assert.That( grandParent.Contexts[1].Name, Is.EqualTo( "Parent" ) );
            Assert.That( grandParent.Contexts[0].Examples[0].Spec, Is.EqualTo( "TestValue should be \"Grand Parent!!!\"" ) );
            Assert.That( grandParent.Contexts[0].Examples[0].ExampleLevelException, Is.Null );
            Assert.That( grandParent.Contexts[0].Examples[0].Pending, Is.False );

            Context parent = formatter.Contexts[0].Contexts[1];
            Assert.That( parent.Name, Is.EqualTo( "Parent" ) );
            Assert.That( parent.Contexts.Count, Is.EqualTo( 2 ) );
            Assert.That( parent.Contexts[0].Name, Is.EqualTo( "Parent Context" ) );
            Assert.That( parent.Contexts[1].Name, Is.EqualTo( "Child" ) );
            Assert.That( parent.Contexts[0].Examples[0].Spec, Is.EqualTo( "TestValue should be \"Grand Parent.Parent!!!@@@\"" ) );
            Assert.That( parent.Contexts[0].Examples[0].ExampleLevelException, Is.Null );
            Assert.That( parent.Contexts[0].Examples[0].Pending, Is.False );

            Context child = formatter.Contexts[0].Contexts[1].Contexts[1];
            Assert.That( child.Name, Is.EqualTo( "Child" ) );
            Assert.That( child.Contexts.Count, Is.EqualTo( 1 ) );
            Assert.That( child.Contexts[0].Name, Is.EqualTo( "Child Context" ) );
            Assert.That( child.Contexts[0].Examples[0].Spec, Is.EqualTo( "TestValue should be \"Grand Parent.Parent.Child!!!@@@###\"" ) );
            Assert.That( child.Contexts[0].Examples[0].ExampleLevelException, Is.Null );
            Assert.That( child.Contexts[0].Examples[0].Pending, Is.False );
        }
예제 #19
0
        public void Execute(IReceiveTestResult observer, string[] testNames)
        {
            this.observer = observer;

            var selectedExamples = new HashSet<string>(testNames);

            var finder = new SpecFinder(SandboxedAssembly.GetTypes(), "");
            var cb = new ContextBuilder(finder, new Tags());

            ContextCollection contextCollection = cb.Contexts().Build();

            FilterOutNonSelectedExamples(contextCollection, selectedExamples);

            contextCollection.ForEach(context =>
            {
                context.Run(this, false);
            });
        }
예제 #20
0
        protected void Run(Type type)
        {
            var finder = new SpecFinder(new[] { type });

            var builder = new ContextBuilder(finder, new DefaultConventions());

            var contexts = builder.Contexts();

            contexts.Build();

            contexts.Run();

            classContext = contexts
                .AllContexts()
                .Select(c => c as ClassContext)
                .First(c => c.type == type);

            methodContext = contexts.AllContexts().First(c => c is MethodContext);
        }
예제 #21
0
        public static void Main(string[] args)
        {
            //format();
            //Tests.GenerateTestComponents.Generate();

            //var tagOrClassName = "focus";
            var tagOrClassName = string.Empty;

            var types = Assembly.GetAssembly(typeof(describe_Entity)).GetTypes();

            var finder = new SpecFinder(types, "");
            var tagsFilter = new Tags().Parse(tagOrClassName);
            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
            var runner = new ContextRunner(tagsFilter, new ConsoleFormatter(), false);

            var results = runner.Run(builder.Contexts().Build());

            Environment.Exit(results.Failures().Count());
        }
예제 #22
0
    public void debug()
    {
        //the specification class you want to test
        //this can be a regular expression
        var testClassYouWantToDebug = "describe_SomeTest";

        //initialize NSpec's specfinder
        var finder = new SpecFinder(
            Assembly.GetExecutingAssembly().Location,
            new Reflector(),
            testClassYouWantToDebug);

        //initialize NSpec's builder
        var builder = new ContextBuilder(
            finder,
            new DefaultConventions());

        //this line runs the tests you specified in the filter
        new ContextRunner(builder, new ConsoleFormatter()).Run();
    }
예제 #23
0
        public ContextCollection Run()
        {
            var reflector = new Reflector(this.dll);

            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new Tags().Parse(Tags), new DefaultConventions());

            var runner = new ContextRunner(builder, Formatter, failFast);

            var contexts = builder.Contexts().Build();

            if (contexts.AnyTaggedWithFocus())
            {
                builder = new ContextBuilder(finder, new Tags().Parse(NSpec.Domain.Tags.Focus), new DefaultConventions());

                runner = new ContextRunner(builder, Formatter, failFast);
            }

            return(runner.Run(builder.Contexts().Build()));
        }
예제 #24
0
        public void ValidateSpec()
        {
            var finder = new SpecFinder(new[] {GetType()});
            var builder = new ContextBuilder(finder, new DefaultConventions());

            ContextCollection result = new ContextRunner(builder, new MyFormatter(), false).Run(builder.Contexts().Build());

            if(result.Failures() == null)
            {
                Assert.Fail("*****   Failed to execute some tests   *****");
            }

            var crashes = result.AllContexts().Where(context => context.Exception != null).ToList();
            if(crashes.Any())
            {
                throw new SpecificationException("unknown", crashes.First().Exception);
            }

            if(result.Failures().Any())
            {
                throw new SpecificationException("unknown", result.First().Exception);
            }
        }
        public NSpecResultModel Run(string specName)
        {
            var reflector = new Reflector(this._dllFile);
            var nspecInstance = new nspec();
            var conventions = new DefaultConventions();
            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder,new Tags().Parse(_tags) , new DefaultConventions());
            var contexts = builder.Contexts().Build();

            var context = contexts.AllContexts().FirstOrDefault(t => t.Name == specName);
            var parentTypeInstance = contexts.AllContexts().FirstOrDefault(t => t is ClassContext);
            
            if (context != null && !context.HasAnyExecutedExample() && parentTypeInstance != null)
            {
                ILiveFormatter liveFormatter = new SilentLiveFormatter();

                if (_formatter is ILiveFormatter) liveFormatter = _formatter as ILiveFormatter;

                var instance = (parentTypeInstance as ClassContext).type.Instance<nspec>();
                context.Contexts.Where(t => t is MethodContext).Do(t => (t as MethodContext).Build(instance));
             
                context.Run(_formatter as ILiveFormatter, false, instance);
                context.AssignExceptions();

                if (builder.tagsFilter.HasTagFilters())
                {
                    context.TrimSkippedDescendants();
                }
            }

            var contextCollection = new ContextCollection { context };
            _formatter.Write(contextCollection);
            var serializableContextCollection = new SerializableContextCollection();
            BuildResponse(serializableContextCollection, contextCollection);
            return new NSpecResultModel { ContextCollection = serializableContextCollection, Output = _formatter.GetFormattedString };
        }
        public NSpecResultModel BuildContexts()
        {
            var reflector = new Reflector(this._dllFile);

            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new Tags().Parse(_tags), new DefaultConventions());

            var contexts = builder.Contexts().Build();

            if (contexts.AnyTaggedWithFocus())
            {
                builder = new ContextBuilder(finder, new Tags().Parse(NSpec.Domain.Tags.Focus), new DefaultConventions());
            }

            var contextCollection = builder.Contexts().Build();
            var serializableContextCollection = new SerializableContextCollection();
            BuildResponse(serializableContextCollection, contextCollection);
            var tags = _tagsCollection.Distinct().Select(t => new TagPair { Tag = t, Assembly = _dllFile }).ToList();
            return new NSpecResultModel { ContextCollection = serializableContextCollection, Output = string.Empty, Tags = tags };
        }
예제 #27
0
        protected void GivenDllContains(params Type[] types)
        {
            reflector = MockRepository.GenerateMock<IReflector>();

            reflector.Stub(r => r.GetTypesFrom()).Return(types);

            someDLL = "an nspec project dll";

            finder = new SpecFinder(reflector);
        }
예제 #28
0
 protected void GivenFilter(string filter)
 {
     finder = new SpecFinder(reflector, filter);
 }
예제 #29
0
        private ContextCollection RunContexts(string tags)
        {
            var reflector = new Reflector(this.dll);

            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new Tags().Parse(tags), new DefaultConventions());

            var runner = new ContextRunner(builder, new ConsoleFormatter(), false);

            var contexts = builder.Contexts().Build();

            if (contexts.AnyTaggedWithFocus())
            {
                builder = new ContextBuilder(finder, new Tags().Parse(NSpec.Domain.Tags.Focus), new DefaultConventions());

                runner = new ContextRunner(builder, new ConsoleFormatter(), false);
            }

            return runner.Run(builder.Contexts().Build());
        }
예제 #30
0
        private ContextCollection BuildContexts()
        {
            var reflector = new Reflector(this.dll);

            var finder = new SpecFinder(reflector);

            var builder = new ContextBuilder(finder, new DefaultConventions());

            var contexts = builder.Contexts().Build();

            if (contexts.AnyTaggedWithFocus())
            {
                builder = new ContextBuilder(finder, new Tags().Parse(NSpec.Domain.Tags.Focus), new DefaultConventions());
            }

            return builder.Contexts().Build();
        }