private static string Format(RunResult result)
        {
            var ret = "\n\nSPECIFICATION: " + (result.SpecificationName ?? result.FoundOnMemberInfo.Name) + " ";

            ret += (result.Passed ? "PASSED" : "FAILED") + " " + result.Message + "\n\n";
            if (result.Thrown != null)
                ret += result.Thrown + "\n\n";

            ret += "\tEXPECTATIONS:\n\t-------------\n";

            foreach (var exp in result.Expectations)
            {
                if (!exp.Passed)
                    ret += "\n\t<<<----------\n";

                ret += "\t" + exp.Text + " " + (exp.Passed ? "PASSED" : "FAILED") + "\n";

                if (!exp.Passed)
                {
                    ret += PadMultiLineText(exp.Exception.Message) + "\n\n";
                    ret += "\t>>>----------\n\n";
                }
            }

            return ret;
        }
Esempio n. 2
0
        public static void Print(RunResult result, TextWriter output)
        {
            var passed = result.Passed ? "Passed" : "Failed";
            output.WriteLine(result.Name.Replace('_', ' ') + " - " + passed);
            if (result.Thrown != null)
            {
                output.WriteLine();
                output.WriteLine("Specification threw an exception.");
                output.WriteLine(result.Thrown);
                output.WriteLine();
                return;
            }
            var @on = result.GetOnResult();
            if (@on != null)
            {
                output.WriteLine();
                output.WriteLine("On:");
                output.WriteLine(NicePrint(@on));
                output.WriteLine();
            }
            if (result.Result != null)
            {
                output.WriteLine();
                output.WriteLine("Results with:");
                if (result.Result is Exception)
                    output.WriteLine(result.Result.GetType() + "\n" + ((Exception) result.Result).Message);
                else
                    output.WriteLine(NicePrint(result.Result));
                output.WriteLine();
            }

            output.WriteLine("Expectations:");
            foreach (var expecation in result.Expectations)
            {
                if (expecation.Passed)
                    output.WriteLine("\t" + expecation.Text + " " + (expecation.Passed ? "Passed" : "Failed"));
                else
                    output.WriteLine(expecation.Exception.Message);
            }
            if (result.Thrown != null)
            {
                output.WriteLine("Specification failed: " + result.Message);
                output.WriteLine();
                output.WriteLine(result.Thrown);
            }
            output.WriteLine(new string('-', 80));
            output.WriteLine();

            output.Flush();
        }
Esempio n. 3
0
        private static string Format(RunResult result)
        {
            var ret = "\n\n*** SPECIFICATION: " + (result.SpecificationName ?? result.FoundOnMemberInfo.Name) + " ";

            ret += (result.Passed ? "PASSED" : "FAILED") + " " + result.Message + "\n\n";
            if (result.Thrown != null)
                ret += result.Thrown + "\n\n";

            ret += "ON:\n--\n";

            var on = result.GetOnResult();
            if (on != null)
            {
                ret += on.ToString();
            }

            if (result.Result != null)
            {

                ret += ("\nResults with:\n");
                if (result.Result is Exception)
                    ret += (result.Result.GetType() + "\n" + ((Exception)result.Result).Message);
                else
                    ret += (result.Result.ToString());

                ret += "\n";
            }

            ret += "\nEXPECTATIONS:\n-------------\n";

            foreach (var exp in result.Expectations)
            {
                if (!exp.Passed)
                    ret += "\n<<<----------\n";

                ret += exp.Text + " " + (exp.Passed ? "PASSED" : "FAILED") + "\n";

                if (!exp.Passed)
                {
                    ret += PadMultiLineText(exp.Exception.Message) + "\n\n";
                    ret += "\t>>>----------\n\n";
                }
            }

            return ret;
        }
Esempio n. 4
0
 private static string Format(RunResult result)
 {
   //  if (result.Passed) return "";
     var ret = (result.SpecificationName ?? result.FoundOnMemberInfo.Name) + " ";
     ret += (result.Passed ? "PASSED" : "FAILED") + " " + result.Message + "\n\n";
     if (result.Thrown != null)
         ret += result.Thrown + "\n\n";
     foreach (var exp in result.Expectations)
     {
         ret += "\t" + exp.Text + " " + (exp.Passed ? "PASSED" : "FAILED") + "\n";
         if (!exp.Passed)
         {
             ret += exp.Exception.Message + "\n\n";
         }
     }
     ret += "\n---------------------------------------------------------------------------\n";
     return ret;
 }
        private string GetSpecificationCategory(RunResult result)
        {
            if (result.FoundOnMemberInfo.DeclaringType == null)
                return "Other";

            const string specifications = "Specifications";

            var pieces = result.FoundOnMemberInfo.DeclaringType.FullName.Split('.', '+')
                               .SkipWhile(piece => piece != specifications)
                               .Skip(1)
                               .Select(Inflector.Underscore)
                               .Select(Inflector.Titleize)
                               .Select(
                                   piece => piece.EndsWith(specifications)
                                       ? piece.Substring(0, piece.Length - specifications.Length)
                                       : piece);

            return String.Join("/", pieces);
        }
Esempio n. 6
0
 private static void PrintSpec(RunResult result)
 {
     var passed = result.Passed ? "Passed" : "Failed";
     Console.WriteLine(result.Name.Replace('_', ' ') + " - " +passed);
     var on = result.GetOnResult();
         if(on != null)
         {
             Console.WriteLine();
             Console.WriteLine("On:");
             Console.WriteLine(on.ToString());
             Console.WriteLine();
         }
         if (result.Result != null)
         {
             Console.WriteLine();
             Console.WriteLine("Results with:");
             if(result.Result is Exception)
                 Console.WriteLine(result.Result.GetType() + "\n" + ((Exception) result.Result).Message );
             else
                 Console.WriteLine(result.Result.ToString());
             Console.WriteLine();
         }
     
     Console.WriteLine("Expectations:");
     foreach(var expecation in result.Expectations)
     {
         if(expecation.Passed)
             Console.WriteLine("\t" + expecation.Text + " " + (expecation.Passed ? "Passed" : "Failed"));
         else
             Console.WriteLine(expecation.Exception.Message);
     }
     if(result.Thrown != null)
     {
         Console.WriteLine("Specification failed: " + result.Message);
         Console.WriteLine();
         Console.WriteLine(result.Thrown);
     }
     Console.WriteLine(new string('-', 80));
     Console.WriteLine();
 	Console.ReadLine();
 }
Esempio n. 7
0
        private RunResult Run <T>(TypedSpecification <T> spec)
        {
            var result = new RunResult {
                SpecificationName = spec.GetName()
            };

            try
            {
                var before = spec.GetBefore();
                before.InvokeIfNotNull();
            }
            catch (Exception ex)
            {
                result.MarkFailure("Before Failed", ex.InnerException);
                return(result);
            }
            object sut = null;

            try
            {
                var given = spec.GetOn();
                sut       = given.DynamicInvoke();
                result.On = given;
            }
            catch (Exception ex)
            {
                result.MarkFailure("On Failed", ex.InnerException);
            }
            object   whenResult = null;
            Delegate when;

            try
            {
                when = spec.GetWhen();
                if (when == null)
                {
                    return new RunResult {
                               SpecificationName = spec.GetName(), Passed = false, Message = "No when on specification"
                    }
                }
                ;
                if (when.Method.GetParameters().Length == 1)
                {
                    whenResult = when.DynamicInvoke(new[] { sut });
                }
                else
                {
                    whenResult = when.DynamicInvoke();
                }
                if (when.Method.ReturnType != typeof(void))
                {
                    result.Result = whenResult;
                }
                else
                {
                    result.Result = sut;
                }
            }
            catch (Exception ex)
            {
                result.MarkFailure("When Failed", ex.InnerException);
                return(result);
            }
            var  fromWhen = when.Method.ReturnType == typeof(void) ? sut : whenResult;
            bool allOk    = true;

            foreach (var exp in spec.GetAssertions())
            {
                var partiallyApplied = PartialApplicationVisitor.Apply(exp, fromWhen);
                try
                {
                    PAssert.IsTrue(partiallyApplied);
                    result.Expectations.Add(new ExpectationResult {
                        Passed = true, Text = PAssert.CreateSimpleFormatFor(partiallyApplied), OriginalExpression = exp
                    });
                }
                catch (Exception ex)
                {
                    allOk = false;
                    result.Expectations.Add(new ExpectationResult {
                        Passed = false, Text = PAssert.CreateSimpleFormatFor(partiallyApplied), OriginalExpression = exp, Exception = ex
                    });
                }
            }
            try
            {
                var Finally = spec.GetFinally();
                Finally.InvokeIfNotNull();
            }
            catch (Exception ex)
            {
                allOk          = false;
                result.Message = "Finally failed";
                result.Thrown  = ex.InnerException;
            }
            result.Passed = allOk;
            return(result);
        }
Esempio n. 8
0
 private string BuildMessage(RunResult res)
 {
     var ret = res.Message ?? "";
     foreach(var exp in res.Expectations)
     {
         if (!exp.Passed)
             ret += exp.Text;
     }
     return ret;
 }
Esempio n. 9
0
 private TestResult BuildTestResult(RunResult res)
 {
     var message = BuildMessage(res);
     var state = res.Passed ? TestState.Passed : TestState.Failed;
     var result = new TestResult("SimpleTesting", 
                           res.FoundOnMemberInfo.DeclaringType.Assembly.FullName,
                           res.FoundOnMemberInfo.DeclaringType.Name,
                           0,
                           res.FoundOnMemberInfo.DeclaringType.FullName + "." + res.FoundOnMemberInfo.Name,
                           res.Name,
                           state,
                           message
                );
     if(state == TestState.Failed)
     {
         result.AddStackLines(getStackLines(res.Thrown));
     }
     return result;
 }
Esempio n. 10
0
 private static bool SpecificationFailed(RunResult result)
 {
     return false == result.Passed;
 }
        private static bool RunSetup <T>(TypedSpecification <T> spec, RunResult result, out RunResult runResult, out object sut,
                                         out object whenResult, out Delegate when)
        {
            when       = null;
            sut        = null;
            whenResult = null;
            runResult  = null;
            try
            {
                var before = spec.GetBefore();
                before.InvokeIfNotNull();
            }
            catch (Exception ex)
            {
                result.MarkFailure("Before Failed", ex.InnerException);
                {
                    runResult = result;

                    return(true);
                }
            }
            sut = null;
            try
            {
                var given = spec.GetOn();
                sut       = given.DynamicInvoke();
                result.On = given;
            }
            catch (Exception ex)
            {
                result.MarkFailure("On Failed", ex.InnerException);
            }
            whenResult = null;
            try
            {
                when = spec.GetWhen();
                if (when == null)
                {
                    runResult = new RunResult
                    {
                        SpecificationName = spec.GetName(), Passed = false, Message = "No when on specification"
                    };
                    return(true);
                }
                if (when.Method.GetParameters().Length == 1)
                {
                    whenResult = when.DynamicInvoke(new[] { sut });
                }
                else
                {
                    whenResult = when.DynamicInvoke();
                }
                if (when.Method.ReturnType != typeof(void))
                {
                    result.Result = whenResult;
                }
                else
                {
                    result.Result = sut;
                }
            }
            catch (Exception ex)
            {
                result.MarkFailure("When Failed", ex.InnerException);
                {
                    runResult = result;
                    return(true);
                }
            }
            return(false);
        }
 private void FormatRunResult(RunResult result)
 {
     output.WriteLine("<div class='alert alert-{0}'>", result.Passed ? "success" : "error");
     output.WriteLine("<details id='{0}'>", GetElementId(result));
     output.WriteLine("<summary>" + result.Name.Underscore().Titleize() + " - " + (result.Passed ? "Passed" : "Failed") + "</summary>");
     output.WriteLine("<pre>");
     FormatRunResultBody(result);
     output.WriteLine("</pre>");
     output.WriteLine("</details>");
     output.WriteLine("</div>");
 }
 private string GetElementId(RunResult result)
 {
     return (result.FoundOnMemberInfo.DeclaringType ?? typeof(Specification)).FullName
         .Underscore() + "_" + result.Name.Underscore();
 }
        private void FormatRunResultBody(RunResult result)
        {
            if (result.Thrown != null)
            {
                output.WriteLine("Specification threw an exception.");
                output.WriteLine(result.Thrown);
                output.WriteLine();
                return;
            }
            var @on = result.GetOnResult();
            if (@on != null)
            {
                output.WriteLine("On:");
                output.WriteLine(SpecificationPrinter.NicePrint(@on));
                output.WriteLine();
            }
            if (result.Result != null)
            {
                output.WriteLine("Results with:");
                if (result.Result is Exception)
                    output.WriteLine(result.Result.GetType() + "\n" + ((Exception)result.Result).Message);
                else
                    output.WriteLine(SpecificationPrinter.NicePrint(result.Result));
                output.WriteLine();
            }

            output.WriteLine("Expectations:");
            foreach (var expecation in result.Expectations)
            {
                if (expecation.Passed)
                    output.WriteLine("\t" + expecation.Text + " " + (expecation.Passed ? "Passed" : "Failed"));
                else
                    output.WriteLine(expecation.Exception.Message);
            }
            if (result.Thrown != null)
            {
                output.WriteLine("Specification failed: " + result.Message);
                output.WriteLine();
                output.WriteLine(result.Thrown);
            }
        }
Esempio n. 15
0
 private static void Print(RunResult runResult)
 {
     SpecificationPrinter.Print(runResult, Console.Out);
 }