Esempio n. 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);
        }
Esempio n. 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);
        }
        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 };
        }
Esempio 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;
        }
Esempio n. 5
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());
        }
        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 };
        }
Esempio n. 7
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();
        }
Esempio n. 8
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());
        }
        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 };
        }