/// <summary>
        /// Initializes a new instance of the <see cref="T:NSpecAdapterForxUnit.ExampleCommand"/> to a specific <see cref="T:NSpec.Domain.Example"/>.
        /// </summary>
        /// <param name="method">The method that contains the <paramref name="example"/>.</param>
        /// <param name="example">The example to run.</param>
        /// <param name="instance">The instance to run the example.</param>
        /// <exception cref="T:System.ArgumentNullException">One of the arguments is <see langword="null"/>. </exception>
        public ExampleCommand(IMethodInfo method, Example example, nspec instance)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (example == null)
            {
                throw new ArgumentNullException("example");
            }

            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            this.Method = method;
            this.Example = example;
            this.Instance = instance;
        }
        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 };
        }
        /// <summary>
        /// Recursively adds commands to all examples in a given <see cref="T:Context"/>.
        /// </summary>
        /// <param name="method">The method where the examples belong.</param>
        /// <param name="instance">The <see cref="T:nspec"/> instance.</param>
        /// <param name="context">The parent context.</param>
        /// <param name="commands">A list where the commands will be stored.</param>
        private static void BuildCommandList(IMethodInfo method, nspec instance, Context context, List<ITestCommand> commands)
        {
            foreach (var example in context.Examples)
            {
                commands.Add(new ExampleCommand(method, example, instance));
            }

            foreach (var childContext in context.ChildContexts())
            {
                BuildCommandList(method, instance, childContext, commands);
            }
        }
Example #4
0
 public override void Run(nspec nspec)
 {
     throw new NotImplementedException();
 }