Example #1
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();
        }
        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();
        }