public void ShouldWriteSummary()
        {
            var example = new ExampleResult {
                Reason      = Resources.TestReason,
                ElapsedTime = 1000,
                Message     = "Test Exception",
                StackTrace  = "System.InvalidOperationException: Test Exception",
                Status      = ResultStatus.Error
            };
            var results    = new Collection <ExpressionResult>();
            var expression = new ExpressionResult();
            var group      = new ExampleGroupResult();

            group.Examples.Add(example);
            expression.Examples.Add(group);
            results.Add(expression);

            this.consoleFormatter.WriteError(example);
            this.consoleFormatter.WriteSummary(results);
            this.stringWriter.Flush();

            var value = "F" + Environment.NewLine + Environment.NewLine +
                        "Failures:" + Environment.NewLine + Environment.NewLine +
                        "1) test" + Environment.NewLine +
                        "   Failure/Error: System.InvalidOperationException: Test Exception" + Environment.NewLine + Environment.NewLine +
                        "Finished in 1 seconds" + Environment.NewLine +
                        "1 examples, 1 failures" + Environment.NewLine;

            this.stringWriter.ToString().Should().Be(value);
        }
        public ExpressionResult Execute(Expression expression, string exampleText)
        {
            var expressionResult = new ExpressionResult {
                Name = expression.Name
            };

            foreach (var exampleGroup in expression.FindExampleGroup(exampleText))
            {
                expressionResult.Examples.Add(ExecuteExampleGroup(exampleGroup));

                return(expressionResult);
            }

            foreach (var example in expression.FindExample(exampleText))
            {
                var exampleResult = new ExampleGroupResult {
                    Reason = example.ExampleGroup.Reason
                };

                exampleResult.Examples.Add(ExecuteExample(example.ExampleGroup, example.Example));
                expressionResult.Examples.Add(exampleResult);

                return(expressionResult);
            }

            expression.Examples.ForEach(group => expressionResult.Examples.Add(ExecuteExampleGroup(group)));

            return(expressionResult);
        }
        public void ShouldWriteSummary()
        {
            var example = new ExampleResult {
                Reason = Resources.TestReason,
                ElapsedTime = 1000,
                Message = "Test Exception",
                StackTrace = "System.InvalidOperationException: Test Exception",
                Status = ResultStatus.Error
            };
            var results = new Collection<ExpressionResult>();
            var expression = new ExpressionResult();
            var group = new ExampleGroupResult();
            group.Examples.Add(example);
            expression.Examples.Add(group);
            results.Add(expression);

            this.consoleFormatter.WriteError(example);
            this.consoleFormatter.WriteSummary(results);
            this.stringWriter.Flush();

            var value = "F" + Environment.NewLine + Environment.NewLine +
                "Failures:" + Environment.NewLine + Environment.NewLine +
                "1) test" + Environment.NewLine +
                "   Failure/Error: System.InvalidOperationException: Test Exception" + Environment.NewLine + Environment.NewLine + 
                "Finished in 1 seconds" + Environment.NewLine + 
                "1 examples, 1 failures" + Environment.NewLine;
            this.stringWriter.ToString().Should().Be(value);
        }
        private ExampleGroupResult ExecuteExampleGroup(ExampleGroup exampleGroup)
        {
            var result = new ExampleGroupResult { Reason = exampleGroup.Reason };
            stratergyOption.Into(stratergy => stratergy.ExecuteAction(exampleGroup.BeforeAll));

            exampleGroup.Examples.ForEach(example => result.Examples.Add(ExecuteExample(exampleGroup, example)));

            stratergyOption.Into(stratergy => stratergy.ExecuteAction(exampleGroup.AfterAll));

            return result;
        }
        private ExampleGroupResult ExecuteExampleGroup(ExampleGroup exampleGroup)
        {
            var result = new ExampleGroupResult {
                Reason = exampleGroup.Reason
            };

            stratergyOption.Into(stratergy => stratergy.ExecuteAction(exampleGroup.BeforeAll));

            exampleGroup.Examples.ForEach(example => result.Examples.Add(ExecuteExample(exampleGroup, example)));

            stratergyOption.Into(stratergy => stratergy.ExecuteAction(exampleGroup.AfterAll));

            return(result);
        }
        private static void CreateSuccesses(ExampleGroupResult group, ICollection <testcaseType> cases)
        {
            var testcaseTypes = @group.Examples.AllSuccesses().Select(success => new testcaseType
            {
                name     = success.Reason,
                executed = bool.TrueString,
                success  = bool.TrueString,
                result   = "Success",
                asserts  = "0",
                time     = ConvertToSeconds(success.ElapsedTime).ToString(CultureInfo.InvariantCulture)
            });

            foreach (var @case in testcaseTypes)
            {
                cases.Add(@case);
            }
        }
        public void ShouldWriteSummaryWithOneSuccess()
        {
            var results = new Collection <ExpressionResult>();
            var result  = new ExpressionResult();
            var group   = new ExampleGroupResult();
            var example = new ExampleResult {
                ElapsedTime = 1000
            };

            group.Examples.Add(example);
            result.Examples.Add(group);
            results.Add(result);

            consoleFormatter.WriteSummary(results);
            stringWriter.Flush();
            var value = Environment.NewLine + Resources.TestReason + Environment.NewLine + Environment.NewLine +
                        "Finished in 1 seconds" + Environment.NewLine +
                        "1 examples, 0 failures" + Environment.NewLine;

            stringWriter.ToString().Should().Be(value);
        }
        public ExpressionResult Execute(Expression expression, string exampleText)
        {
            var expressionResult = new ExpressionResult { Name = expression.Name };

            foreach (var exampleGroup in expression.FindExampleGroup(exampleText)) {
                expressionResult.Examples.Add(ExecuteExampleGroup(exampleGroup));

                return expressionResult;
            }

            foreach (var example in expression.FindExample(exampleText)) {
                var exampleResult = new ExampleGroupResult { Reason = example.ExampleGroup.Reason };

                exampleResult.Examples.Add(ExecuteExample(example.ExampleGroup, example.Example));
                expressionResult.Examples.Add(exampleResult);

                return expressionResult;
            }

            expression.Examples.ForEach(group => expressionResult.Examples.Add(ExecuteExampleGroup(group)));

            return expressionResult;
        }
        private static void CreateErrors(ExampleGroupResult group, Collection <testcaseType> cases)
        {
            var testcaseTypes = from error in @group.Examples.AllErrors()
                                let failure = new failureType
            {
                message    = CreateCDataSection(error.Message),
                stacktrace = CreateCDataSection(error.StackTrace)
            }
            select new testcaseType
            {
                name     = error.Reason,
                executed = bool.TrueString,
                success  = bool.FalseString,
                result   = "Failure",
                asserts  = "0",
                time     = ConvertToSeconds(error.ElapsedTime).ToString(CultureInfo.InvariantCulture),
                Item     = failure
            };

            foreach (var @case in testcaseTypes)
            {
                cases.Add(@case);
            }
        }
 private static void CreateSuccesses(ExampleGroupResult group, ICollection<testcaseType> cases)
 {
     var testcaseTypes = @group.Examples.AllSuccesses().Select(success => new testcaseType
         {
             name = success.Reason,
             executed = bool.TrueString,
             success = bool.TrueString,
             result = "Success",
             asserts = "0",
             time = ConvertToSeconds(success.ElapsedTime).ToString(CultureInfo.InvariantCulture)
         });
     foreach (var @case in testcaseTypes)
     {
         cases.Add(@case);
     }
 }
 private static void CreateErrors(ExampleGroupResult group, Collection<testcaseType> cases)
 {
     var testcaseTypes = from error in @group.Examples.AllErrors()
                         let failure = new failureType
                             {
                                 message = CreateCDataSection(error.Message),
                                 stacktrace = CreateCDataSection(error.StackTrace)
                             }
                         select new testcaseType
                             {
                                 name = error.Reason,
                                 executed = bool.TrueString,
                                 success = bool.FalseString,
                                 result = "Failure",
                                 asserts = "0",
                                 time = ConvertToSeconds(error.ElapsedTime).ToString(CultureInfo.InvariantCulture),
                                 Item = failure
                             };
     foreach (var @case in testcaseTypes)
     {
         cases.Add(@case);
     }
 }
        public void ShouldWriteSummaryWithOneSuccess()
        {
            var results = new Collection<ExpressionResult>();
            var result = new ExpressionResult();
            var group = new ExampleGroupResult();
            var example = new ExampleResult { ElapsedTime = 1000 };
            group.Examples.Add(example);
            result.Examples.Add(group);
            results.Add(result);

            consoleFormatter.WriteSummary(results);
            stringWriter.Flush();
            var value = Environment.NewLine + Resources.TestReason + Environment.NewLine + Environment.NewLine +
                "Finished in 1 seconds" + Environment.NewLine + 
                "1 examples, 0 failures" + Environment.NewLine;
            stringWriter.ToString().Should().Be(value);
        }