Ejemplo n.º 1
0
 public NSpecExampleTest( ExampleBase example )
     : base( example.Spec, null )
 {
     this.Kind = TestKinds.Test;
     this.IsTestCase = true;
     this._example = example;
 }
Ejemplo n.º 2
0
        public void AddExample(ExampleBase example)
        {
            example.Context = this;

            example.Tags.AddRange(Tags);

            Examples.Add(example);

            example.Pending |= IsPending();
        }
Ejemplo n.º 3
0
        public void Write(ExampleBase example, int level)
        {
            var result = example.Failed()
                ? new TestResultDTO { Outcome = TestOutcome.Failed, StackTrace = example.Exception.StackTrace, Message = example.Exception.Message }
                : new TestResultDTO { Outcome = example.Pending ? TestOutcome.Skipped : TestOutcome.Passed };
            result.TestName = example.FullName();
            result.Source = this.Source;

            this.observer.Receive(result);
        }
Ejemplo n.º 4
0
        NSpecExampleTest CreateGallioTestFrom(ExampleBase nspecExample)
        {
            try
            {
                NSpecExampleTest exampleTest = new NSpecExampleTest(nspecExample);

                return exampleTest;
            }
            catch
            {
                throw new Exception(String.Format("Error adding example {0}", nspecExample.Spec));
            }
        }
Ejemplo n.º 5
0
        public MethodInfo GetAction(ExampleBase example)
        {
            if (example is MethodExample)
            {
                return example.GetType()
                    .GetField("method", BindingFlags.Instance | BindingFlags.NonPublic)
                    .GetValue(example) as MethodInfo;
            }

            var action = example.GetType()
                .GetField("action", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(example) as Action;
            return action.Method;
        }
Ejemplo n.º 6
0
        public void Write(ExampleBase e, int level)
        {
            string name = string.Empty;
            Utilities.GenerateUniqueExampleName(e.Context, ref name, e.Spec);
            if (ExamplesToProcess.Count == 0 || ExamplesToProcess.Contains(GetSpecName(e)))
            {
                var noFailure = e.Exception == null;
                var failureMessage = noFailure ? "" : " - FAILED - {0}".With(e.Exception.CleanMessage());
                var whiteSpace = indent.Times(level);
                var result = e.Pending ? whiteSpace + e.Spec + " - PENDING" : whiteSpace + e.Spec + failureMessage;
                WriteLineDelegate(result);

                if (ExampleProcessed != null)
                    ExampleProcessed(new ExampleEventArgs(e));
            }
        }
Ejemplo n.º 7
0
        public void Exercise(ExampleBase example, nspec nspec)
        {
            if (example.ShouldSkip(nspec.tagsFilter))
            {
                return;
            }

            RunAndHandleException(RunBefores, nspec, ref Exception);

            RunAndHandleException(RunActs, nspec, ref Exception);

            RunAndHandleException(example.Run, nspec, ref example.Exception);

            bool exceptionThrownInAfters = RunAndHandleException(RunAfters, nspec, ref Exception);

            // when an expected exception is thrown and is set to be cleared by 'expect<>',
            // a subsequent exception thrown in 'after' hooks would go unnoticed, so do not clear in this case

            if (exceptionThrownInAfters)
            {
                ClearExpectedException = false;
            }
        }
Ejemplo n.º 8
0
 public RunnableExample(Context context, ExampleBase example)
 {
     this.context = context;
     this.example = example;
 }
Ejemplo n.º 9
0
 void ILiveFormatter.Write(ExampleBase e, int level)
 {
     base.Write(e, level);
 }
Ejemplo n.º 10
0
        public void Exercise(ExampleBase example, nspec nspec)
        {
            if (example.ShouldSkip(nspec.tagsFilter)) return;

            RunAndHandleException(RunBefores, nspec, ref Exception);

            RunAndHandleException(RunActs, nspec, ref Exception);

            RunAndHandleException(example.Run, nspec, ref example.Exception);

            bool exceptionThrownInAfters = RunAndHandleException(RunAfters, nspec, ref Exception);

            // when an expected exception is thrown and is set to be cleared by 'expect<>',
            // a subsequent exception thrown in 'after' hooks would go unnoticed, so do not clear in this case

            if (exceptionThrownInAfters) ClearExpectedException = false;
        }
Ejemplo n.º 11
0
        public void Exercise(ExampleBase example, nspec nspec)
        {
            if (example.ShouldSkip(nspec.tagsFilter)) return;

            RunAndHandleException(RunBefores, nspec, ref Exception);

            RunAndHandleException(RunActs, nspec, ref Exception);

            RunAndHandleException(example.Run, nspec, ref example.Exception);

            RunAndHandleException(RunAfters, nspec, ref Exception);

            example.AssignProperException(Exception);
        }
Ejemplo n.º 12
0
 public ExampleEventArgs(ExampleBase ex)
 {
     string name = string.Empty;
     Utilities.GenerateUniqueExampleName(ex.Context,ref name,ex.Spec);
     Example = new SerializableExampleBase
     {
         Spec = ex.Spec,
         Exception = ex.Exception != null ? new SerializableExampleFailureException { ExampleException = ex.Exception.GetBaseException() } : null,
         Context = new SerializableContext { Name = ex.Context.Name, Tags = ex.Context.Tags },
         Tags = ex.Tags,
         UniqueName = name
     };
 }
Ejemplo n.º 13
0
 private string GetSpecName(ExampleBase e)
 {
     string name = string.Empty;
     Utilities.GenerateUniqueExampleName(e.Context, ref name, e.Spec);
     return name;
 }
Ejemplo n.º 14
0
 public string WriteFailure(ExampleBase example)
 {
     var failure = "\n" + example.FullName().Replace("_", " ") + "\n";
     failure += example.Exception.CleanMessage() + "\n";
     var stackTrace = FailureLines(example.Exception);
     stackTrace.AddRange(FailureLines(example.Exception.InnerException));
     var flattenedStackTrace = stackTrace.Flatten("\n").TrimEnd() + "\n";
     failure += example.Context.GetInstance().StackTraceToPrint(flattenedStackTrace);
     return failure;
 }
 public void Write(ExampleBase example, int level)
 {
     WrittenExamples.Add(example);
 }