Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        protected when_running_specs Run(params Type[] types)
        {
            //if (types.Count() == 1) tags = types.First().Name;

            this.types = types;

            builder = new ContextBuilder(new SpecFinder(types), new Tags().Parse(tags), new DefaultConventions());

            runner = new ContextRunner(builder, formatter, failFast);

            contextCollection = builder.Contexts();

            contextCollection.Build();

            classContext = contextCollection
                .AllContexts()
                .Where(c => c is ClassContext)
                .Cast<ClassContext>()
                .FirstOrDefault(c => types.Contains(c.type));

            methodContext = contextCollection.AllContexts().FirstOrDefault(c => c is MethodContext);

            runner.Run(contextCollection);

            return this;
        }
        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 };
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void setup()
        {
            finder = MockRepository.GenerateMock<ISpecFinder>();

            finder.Stub(f => f.SpecClasses()).IgnoreArguments().Return(new[] { typeof(child), typeof(parent), typeof(sibling) });

            builder = new ContextBuilder(finder);

            builder.Contexts();
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 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()));
        }
Exemplo n.º 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));
        }
Exemplo n.º 11
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);
        }
        public void setup()
        {
            reflector = MockRepository.GenerateMock<IReflector>();

            RhinoMocksExtensions.Stub(reflector, r => r.GetTypesFrom("")).IgnoreArguments().Return(new[] { typeof(SpecClass) });

            var contextBuilder = new ContextBuilder(new SpecFinder("", reflector), new DefaultConventions());

            classContext = contextBuilder.Contexts().First();

            classContext.Build();

            classContext.Run(new SilentLiveFormatter(), failFast: 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);
        }
    //[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);
    }
Exemplo n.º 15
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);
    }
Exemplo n.º 16
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()));
        }
Exemplo n.º 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
        }
Exemplo n.º 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, false).Run(builder.Contexts().Build());

            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].Exception, 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].Exception, 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].Exception, Is.Null);
            Assert.That(child.Contexts[0].Examples[0].Pending, Is.False);
        }
Exemplo n.º 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);
            });
        }
Exemplo n.º 20
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());
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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()));
        }
Exemplo n.º 23
0
        protected when_running_specs Init(Type[] types, string tags = null, bool failFast = false)
        {
            this.types = types;

            builder = new ContextBuilder(new SpecFinder(types), new Tags().Parse(tags), new DefaultConventions());

            runner = new ContextRunner(builder, formatter, failFast);

            contextCollection = builder.Contexts();

            contextCollection.Build();

            classContext = contextCollection
                .AllContexts()
                .Where(c => c is ClassContext)
                .Cast<ClassContext>()
                .FirstOrDefault(c => types.Contains(c.type));

            methodContext = contextCollection.AllContexts().FirstOrDefault(c => c is MethodContext);

            return this;
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 25
0
        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 };
        }
Exemplo n.º 26
0
        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 };
        }
Exemplo n.º 27
0
        public void output_verification(Type output, Type []testClasses, string tags)
        {
            var finder = new SpecFinder(testClasses, "");
            var tagsFilter = new Tags().Parse(tags);
            var builder = new ContextBuilder(finder, tagsFilter, new DefaultConventions());
            var consoleFormatter = new ConsoleFormatter();

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

            var runner = new ContextRunner(tagsFilter, 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);

            var guid = Guid.NewGuid();
        }
Exemplo n.º 28
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());
        }
Exemplo n.º 29
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();
        }
        protected void RunWithReflector(Type specClassType)
        {
            IReflector reflector = MockRepository.GenerateMock<IReflector>();

            reflector.Stub(r => r.GetTypesFrom()).Return(new[] { specClassType });

            var contextBuilder = new ContextBuilder(new SpecFinder(reflector), new DefaultConventions());

            classContext = contextBuilder.Contexts().First();

            classContext.Build();

            classContext.Run(new SilentLiveFormatter(), failFast: false);
        }