Ejemplo n.º 1
0
        public void TestlistUseWithOppositeOrder()
        {
            var f = new StringBuilder();

            f.AppendLine("procedure void ExecuteAllTests()");
            f.AppendLine("{");
            f.AppendLine("   var iterator = AllTests.GetProcedureIterator();");
            f.AppendLine("   while (iterator.GetNext())");
            f.AppendLine("   {");
            f.AppendLine("      iterator.Procedure( iterator.Arguments );");
            f.AppendLine("   }");
            f.AppendLine("}");
            f.AppendLine("testlist AllTests");
            f.AppendLine("{");
            f.AppendLine("   * FirstTestCase");
            f.AppendLine("}");
            f.AppendLine("procedure void FirstTestCase() {}");

            var file = FileBuilder.ParseFiles((ILogger)null, new Tuple <string, string>("myfile.tss", f.ToString()))[0];

            Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            var procedure = file.ListElements().First(p => p.Name == "ExecuteAllTests") as IFileProcedure;

            Exception exeException = null;
            var       taskContext  = ExecutionHelper.ExeContext();

            try
            {
                taskContext.CallProcedure(procedure);
            }
            catch (Exception ex)
            {
                exeException = ex;
            }
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            if (exeException != null)
            {
                throw exeException;
            }

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - myfile.ExecuteAllTests - <arguments>");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> myfile.FirstTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
        public void ErrorHandling_ContinueOnFail()
        {
            // With title and expect is passing
            var f = new StringBuilder();

            f.AppendLine("bool MyProcedure() : ContinueOnFail");
            f.AppendLine("{");
            f.AppendLine("   expect (4 < 10);");
            f.AppendLine("   expect (7 < 10);");
            f.AppendLine("   expect (10 < 10);");
            f.AppendLine("   expect (9 < 10);");
            f.AppendLine("   return true;");
            f.AppendLine("}");
            var file      = FileBuilder.ParseFile(null, f.ToString());
            var procedure = file.GetFileElement <IFileProcedure>("MyProcedure");;

            var taskContext = ExecutionHelper.ExeContext();
            var result      = taskContext.CallProcedure(procedure);

            Assert.AreEqual(true, (bool)result);

            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyProcedure - <arguments>");
            log.ExpectNext("2 - Normal - 3 - EXPECT: 4<10; Actual: <TRUE>  =>  Pass");
            log.ExpectNext("2 - Normal - 4 - EXPECT: 7<10; Actual: <TRUE>  =>  Pass");
            log.ExpectNext("2 - Error - 5 - EXPECT: 10<10; Actual: <FALSE>  =>  Fail");
            log.ExpectNext("2 - Normal - 6 - EXPECT: 9<10; Actual: <TRUE>  =>  Pass");
            log.ExpectNext("2 - Post");
        }
Ejemplo n.º 3
0
        public void LogConstantString()
        {
            var procedure = FileBuilder.ParseProcedure(
                "procedure void Anders() {",
                "   log (\"Ello!\");",
                "}");

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - Anders - <arguments>");
            log.ExpectNext("2 - Normal - 2 - log: Ello!");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
        public void TestPartnerOnProcedureUsingThisModifier()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("procedure MyProcedure() :");
            f.AppendLine("    partner MyHelper : Helper {}");
            f.AppendLine("procedure void Helper(this MyProcedure proc)");   // Note the 'this' keyword.
            f.AppendLine("{ log (\"Doing partner for \" + proc.Name); }");
            f.AppendLine("procedure void ExecuteIt()");
            f.AppendLine("{");
            f.AppendLine("   log (\"Before\");");
            f.AppendLine("   MyProcedure.MyHelper();");                     // Not setting the 'proc' parameter; it is implicit via the 'this' modifier.
            f.AppendLine("   log (\"After\");");
            f.AppendLine("}");

            var file = FileBuilder.ParseFiles((ILogger)null, new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()))[0];

            Assert.AreEqual(3, file.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            var procedure = file.ListElements().First(p => p.Name == "ExecuteIt") as IFileProcedure;

            Exception exeException = null;
            var       taskContext  = ExecutionHelper.ExeContext();

            try
            {
                taskContext.CallProcedure(procedure);
            }
            catch (Exception ex)
            {
                exeException = ex;
            }
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            if (exeException != null)
            {
                throw exeException;
            }

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.ExecuteIt - <arguments>");
            log.ExpectNext("2 - Normal - 8 - log: Before");
            log.ExpectNext("2 - Pre - MyFile.Helper - <arguments>");
            log.ExpectNext("3 - Normal - 5 - log: Doing partner for MyProcedure");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Normal - 10 - log: After");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
        public void TestPartnerOnTestList()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("testlist MyTestSuite :");
            f.AppendLine("    partner MyHelper : Helper;");
            f.AppendLine("procedure void Helper(this MyTestSuite suite)");
            f.AppendLine("{ log (\"Inside Helper for \" + suite.Name); }");
            f.AppendLine("procedure void ExecuteIt()");
            f.AppendLine("{");
            f.AppendLine("   log (\"Before\");");
            f.AppendLine("   MyTestSuite.MyHelper();");
            f.AppendLine("   log (\"After\");");
            f.AppendLine("}");

            var file = FileBuilder.ParseFiles((ILogger)null, new Tuple <string, string>("myfile.tss", f.ToString()))[0];

            Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            var procedure = file.ListElements().First(p => p.Name == "ExecuteIt") as IFileProcedure;

            Exception exeException = null;
            var       taskContext  = ExecutionHelper.ExeContext();

            try
            {
                taskContext.CallProcedure(procedure);
            }
            catch (Exception ex)
            {
                exeException = ex;
            }
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            if (exeException != null)
            {
                throw exeException;
            }

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.ExecuteIt - <arguments>");
            log.ExpectNext("2 - Normal - 8 - log: Before");
            log.ExpectNext("2 - Pre - MyFile.Helper - <arguments>");
            log.ExpectNext("3 - Normal - 5 - log: Inside Helper for MyTestSuite");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Normal - 10 - log: After");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 6
0
        public void ThreeCodeModulesSetup()
        {
            var f = new StringBuilder();

            f.AppendLine("using " + typeof(LowLayerCodeModule).Namespace + ";");
            f.AppendLine("namespace ObjectUsing;");
            f.AppendLine("public " + typeof(LowLayerCodeModule).Name + " lowLevelObject");
            f.AppendLine("{");
            f.AppendLine("   IntProp: 12");
            f.AppendLine("}");
            f.AppendLine("public " + typeof(MidLayerCodeModule).Name + " midLevelObject");
            f.AppendLine("{");
            f.AppendLine("   LowLayer: lowLevelObject,");
            f.AppendLine("   IntProp: 2");
            f.AppendLine("}");
            f.AppendLine("public " + typeof(HighLayerCodeModule).Name + " highLevelObject");
            f.AppendLine("{");
            f.AppendLine("   MidLayer: midLevelObject,");
            f.AppendLine("   IntProp: 41");
            f.AppendLine("}");
            f.AppendLine("procedure int UseIt()");
            f.AppendLine("{");
            f.AppendLine("   return highLevelObject.Fcn(4);");
            f.AppendLine("}");

            var file = FileBuilder.ParseFiles(
                (ILogger)null,
                this.GetType().Assembly,
                new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()))[0];

            Assert.AreEqual(4, file.ListElements().Count());
            Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            var procedure = file.ListElements().First(p => p.Name == "UseIt") as IFileProcedure;

            var taskContext = ExecutionHelper.ExeContext();
            var result      = taskContext.CallProcedure(procedure);

            Assert.AreEqual(1648L, result);

            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - ObjectUsing.UseIt - <arguments>");
            log.ExpectNext("2 - Normal - HighLayerCodeModule.Fcn - i: 4");
            log.ExpectNext("2 - Normal - MidLayerCodeModule.Fcn - i: 8");
            log.ExpectNext("2 - Normal - LowLayerCodeModule.Fcn - i: 19");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 7
0
        public void ProcedureCallSimpleNoParamsNoReturn2Levels()
        {
            var taskContext = ExecutionHelper.ExeContext();

            var procedure = this.CreateTestFileNoParams("Bent", "AB");

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.Bent - <arguments>");
            log.ExpectNext("2 - Normal - 6 - log: This is Bent");
            log.ExpectNext("2 - Pre - MyFile.Anders - <arguments>");
            log.ExpectNext("3 - Normal - 3 - log: This is Anders");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 8
0
        public void TestStepsIndexNoTitle()
        {
            var taskContext = ExecutionHelper.ExeContext();
            var procedure   = this.CreateTestFile("Anders");

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.Anders - <arguments>");
            log.ExpectNext("2 - Normal - 4 - STEP #1");
            log.ExpectNext("2 - Normal - 5 - STEP #2");
            log.ExpectNext("2 - Normal - 6 - STEP #3");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 9
0
        public void TestStepsIndexAndTitle()
        {
            var taskContext = ExecutionHelper.ExeContext();
            var procedure   = this.CreateTestFile("Christian");

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.Christian - <arguments>");
            log.ExpectNext("2 - Normal - 16 - STEP #1 : First");
            log.ExpectNext("2 - Normal - 17 - STEP #2 : Second");
            log.ExpectNext("2 - Normal - 18 - STEP #3 : Third");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 10
0
        public void LogStringEnumerable()
        {
            var procedure = FileBuilder.ParseProcedure(typeof(DummyClass),
                                                       "procedure void Anders() {",
                                                       "   log (DummyClass.MethodListSomeNames());",
                                                       "}");

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - Anders - <arguments>");
            log.ExpectNext("2 - Normal - 2 - Anders");
            log.ExpectNext("2 - Normal - 2 - Berditto");
            log.ExpectNext("2 - Normal - 2 - Chrushtor");
            log.ExpectNext("2 - Normal - 2 - Dowfick");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 11
0
        public void LogSimpleNonStringTypes()
        {
            var procedure = FileBuilder.ParseProcedure(
                "procedure void Anders() {",
                "   log (true);",
                "   log (36);",
                "   log (pass);",
                "}");

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - Anders - <arguments>");
            log.ExpectNext("2 - Normal - 2 - log: True");
            log.ExpectNext("2 - Normal - 3 - log: 36");
            log.ExpectNext("2 - Normal - 4 - log: Pass");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 12
0
        public void AsyncExecutionSimple()
        {
            var f = new StringBuilder();

            f.AppendLine("procedure void Main()");
            f.AppendLine("{");
            f.AppendLine("   log (\"Started\");");
            f.AppendLine("   delay (100ms);     // Give time for test to detect state 'Running'");
            f.AppendLine("   log (\"Ending\");");
            f.AppendLine("}");

            StepBro.Core.Main.Initialize();
            try
            {
                var file = FileBuilder.ParseFiles(
                    StepBro.Core.Main.ServiceManager,
                    StepBro.Core.Main.GetService <IMainLogger>().Logger.RootLogger,
                    new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()))[0];

                Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
                var procedure = file.ListElements().First(p => p.Name == "Main") as IFileProcedure;

                var  execution = StepBro.Core.Main.StartProcedureExecution(procedure);
                bool isRunning = false;
                while (execution.Task.CurrentState == StepBro.Core.Tasks.TaskExecutionState.Created)
                {
                    ;
                }
                while (execution.Task.CurrentState == StepBro.Core.Tasks.TaskExecutionState.Started)
                {
                    ;
                }
                while ((DateTime.Now - execution.Task.StartTime) < TimeSpan.FromMilliseconds(5000))
                {
                    if (execution.Task.CurrentState == StepBro.Core.Tasks.TaskExecutionState.Running)
                    {
                        isRunning = true;
                        break;
                    }
                }
                Assert.IsTrue(isRunning);
                while ((DateTime.Now - execution.Task.StartTime) < TimeSpan.FromMilliseconds(10000))
                {
                    var state = execution.Task.CurrentState;
                    if (state > StepBro.Core.Tasks.TaskExecutionState.Running)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(1);
                }
                System.Diagnostics.Debug.WriteLine($"Execution time: {(execution.Task.EndTime - execution.Task.StartTime).ToString()}");
                Assert.AreEqual(StepBro.Core.Tasks.TaskExecutionState.Ended, execution.Task.CurrentState);

                var log = new LogInspector(ServiceManager.Global.Get <IMainLogger>().Logger);
                log.DebugDump();

                log.ExpectNext("0 - Pre - StepBro - Main logger created");
                log.ExpectNext("1 - Normal - MainLogger - Service started");
                log.ExpectNext("1 - Pre - Script Execution - Main");
                log.ExpectNext("1 - Pre - myfile.Main - <arguments>");
                log.ExpectNext("2 - Normal - 3 - log: Started");
                log.ExpectNext("2 - Normal - 5 - log: Ending");
                log.ExpectNext("2 - Post");
                log.ExpectNext("2 - Post - Script Execution - Script execution ended. Result value: <null>");
                log.ExpectEnd();
            }
            finally
            {
                StepBro.Core.Main.DeinitializeInternal(true);
            }
        }
        public void TestSetupWithFrameworkFile()
        {
            var f = new StringBuilder();

            f.AppendLine("using TestFramework;");
            f.AppendLine("procedure MyTestCase() : TestCase,");
            f.AppendLine("   FreeParameters,");
            f.AppendLine("   partner override Setup: TestCaseSetup,");
            f.AppendLine("   partner override Cleanup:	TestCaseCleanup;");

            f.AppendLine("procedure void TestCaseSetup(this TestCase testcase)");
            f.AppendLine("{ log (\"Doing default setup for \" + testcase.Name); }");
            f.AppendLine("procedure void TestCaseCleanup(this TestCase testcase)");
            f.AppendLine("{ log (\"Doing default cleanup for \" + testcase.Name); }");

            f.AppendLine("procedure void TestCaseSpecialSetup(this TestCase testcase)");
            f.AppendLine("{ log (\"Doing special setup for \" + testcase.Name); }");
            f.AppendLine("procedure void TestCaseSpecialCleanup(this TestCase testcase)");
            f.AppendLine("{ log (\"Doing special cleanup for \" + testcase.Name); }");

            f.AppendLine("testlist AllTests : TestSuite");
            f.AppendLine("{");
            f.AppendLine("    * FirstTestCase");
            f.AppendLine("    * SecondTestCase");
            f.AppendLine("    * ThirdTestCase");
            f.AppendLine("}");

            f.AppendLine("procedure void FirstTestCase() : MyTestCase,");
            f.AppendLine(" partner override Setup: TestCaseSpecialSetup");
            f.AppendLine("{ log(\"Inside FirstTestCase\"); }");

            f.AppendLine("procedure void SecondTestCase() : MyTestCase,");
            f.AppendLine("partner override Cleanup:	TestCaseSpecialCleanup");
            f.AppendLine("{ log(\"Inside SecondTestCase\"); }");

            f.AppendLine("procedure void ThirdTestCase() : MyTestCase");
            f.AppendLine("{ log(\"Inside ThirdTestCase\"); }");

            f.AppendLine("procedure void ExecuteAllTests()");
            f.AppendLine("{");
            f.AppendLine("   AllTests.FormalTest();");
            f.AppendLine("}");

            var files = FileBuilder.ParseFiles((ILogger)null,
                                               new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()),
                                               new Tuple <string, string>("TestFramework." + Main.StepBroFileExtension, CreateTestFrameworkFile()));
            var myfile    = files.First(file => file.FileName == "myfile." + Main.StepBroFileExtension);
            var framework = files.First(file => file.FileName == "TestFramework." + Main.StepBroFileExtension);

            Assert.AreEqual(9, myfile.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            Assert.AreEqual(1, myfile.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            Assert.AreEqual(7, framework.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            Assert.AreEqual(1, framework.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());

            var list = myfile["AllTests"] as ITestList;

            Assert.AreEqual("AllTests", list.Name);
            Assert.AreEqual(3, list.EntryCount);
            Assert.AreEqual("FirstTestCase", list[0].ReferenceName);
            Assert.AreEqual("SecondTestCase", list[1].ReferenceName);
            Assert.AreEqual("ThirdTestCase", list[2].ReferenceName);

            var procedure = myfile.ListElements().First(p => p.Name == "ExecuteAllTests") as IFileProcedure;

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - myfile.ExecuteAllTests - <arguments>");
            log.ExpectNext("2 - Pre - TestFramework.TestSuiteFormalTestExecution - <arguments>");

            log.ExpectNext("3 - Pre - TestFramework.TestSuiteEmptyPreTest - <arguments>");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: FirstTestCase");
            log.ExpectNext("3 - Pre - myfile.TestCaseSpecialSetup - <arguments>");
            log.ExpectNext("4 - Normal - 11 - log: Doing special setup for FirstTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.FirstTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 22 - log: Inside FirstTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - myfile.TestCaseCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 9 - log: Doing default cleanup for FirstTestCase");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: SecondTestCase");
            log.ExpectNext("3 - Pre - myfile.TestCaseSetup - <arguments>");
            log.ExpectNext("4 - Normal - 7 - log: Doing default setup for SecondTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.SecondTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 25 - log: Inside SecondTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - myfile.TestCaseSpecialCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 13 - log: Doing special cleanup for SecondTestCase");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: ThirdTestCase");
            log.ExpectNext("3 - Pre - myfile.TestCaseSetup - <arguments>");
            log.ExpectNext("4 - Normal - 7 - log: Doing default setup for ThirdTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.ThirdTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 27 - log: Inside ThirdTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - myfile.TestCaseCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 9 - log: Doing default cleanup for ThirdTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
Ejemplo n.º 14
0
        public void TestFileWithSingleSimpleTestList()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("procedure void FirstTestCase() {}");
            f.AppendLine("procedure void SecondTestCase() {}");
            f.AppendLine("procedure void ThirdTestCase() {}");
            f.AppendLine("testlist AllTests");
            f.AppendLine("{");
            f.AppendLine("   * FirstTestCase");
            f.AppendLine("   * SecondTestCase");
            f.AppendLine("   * ThirdTestCase");
            f.AppendLine("}");
            f.AppendLine("procedure void ExecuteAllTests()");
            f.AppendLine("{");
            f.AppendLine("   var iterator = AllTests.GetProcedureIterator();");
            f.AppendLine("   while (iterator.GetNext())");
            f.AppendLine("   {");
            f.AppendLine("      iterator.Procedure( iterator.Arguments );");
            f.AppendLine("   }");
            f.AppendLine("}");

            var file = FileBuilder.ParseFile(null, f.ToString());

            Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            var list = file["AllTests"] as ITestList;

            Assert.AreEqual("AllTests", list.Name);
            Assert.AreEqual(3, list.EntryCount);
            Assert.AreSame(file["FirstTestCase"], list[0].Reference);
            Assert.AreSame(file["SecondTestCase"], list[1].Reference);
            Assert.AreSame(file["ThirdTestCase"], list[2].Reference);
            Assert.AreEqual("FirstTestCase", list[0].Reference.Name);
            Assert.AreEqual("SecondTestCase", list[1].Reference.Name);
            Assert.AreEqual("ThirdTestCase", list[2].Reference.Name);
            Assert.AreEqual("FirstTestCase", list[0].ReferenceName);
            Assert.AreEqual("SecondTestCase", list[1].ReferenceName);
            Assert.AreEqual("ThirdTestCase", list[2].ReferenceName);
            Assert.AreSame(list, list[0].Home);
            Assert.AreSame(list, list[1].Home);
            Assert.AreSame(list, list[2].Home);

            var procedure = file.ListElements().First(p => p.Name == "ExecuteAllTests") as IFileProcedure;

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.ExecuteAllTests - <arguments>");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.FirstTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.SecondTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.ThirdTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
        public void TestSetupWithSpecialSetupFile()
        {
            var f = new StringBuilder();

            f.AppendLine("using TestFramework;");
            f.AppendLine("using SpecialTest;");
            f.AppendLine("using StepBroCoreTest.Data;");
            f.AppendLine("using SomeTool;");

            f.AppendLine("DummyClass anders { PropInt = 20 }");

            f.AppendLine("procedure void TestCaseLocalSetup(this TestCase testcase)");
            f.AppendLine("{ log (this.Name + \" \" + testcase.Name); }");
            f.AppendLine("procedure void TestCaseLocalCleanup(this TestCase testcase)");
            f.AppendLine("{ log (this.Name + \" \" + testcase.Name); }");

            f.AppendLine("testlist AllTests : TestSuite,");
            f.AppendLine("    partner override PreTest : MyPreTest");
            f.AppendLine("{");
            f.AppendLine("    * FirstTestCase");
            f.AppendLine("    * SecondTestCase");
            f.AppendLine("    * ThirdTestCase");
            f.AppendLine("}");

            f.AppendLine("procedure void FirstTestCase() : SpecialTestCase,");
            f.AppendLine("    partner override Setup: TestCaseLocalSetup");
            f.AppendLine("{ log(\"Inside \" + this.Name + \": \" + anders.PropInt); }");

            f.AppendLine("procedure void SecondTestCase() : SpecialTestCase,");
            f.AppendLine("    partner override Setup: TestCaseSpecialSetup");
            f.AppendLine("{ log(\"Inside \" + this.Name + \": \" + bent.PropInt); }");

            f.AppendLine("procedure void ThirdTestCase() : SpecialTestCase");
            f.AppendLine("{ log(\"Inside \" + this.Name + \": \" + DummyFunc()); }");

            f.AppendLine("procedure void ExecuteAllTests()");
            f.AppendLine("{");
            f.AppendLine("   AllTests.FormalTest();");
            f.AppendLine("}");

            f.AppendLine("procedure bool MyPreTest()");
            f.AppendLine("{");
            f.AppendLine("    log(this.Name + \":\" + anders.PropInt);");
            f.AppendLine("    return true;");
            f.AppendLine("}");

            var tf = new StringBuilder();

            tf.AppendLine("using StepBroCoreTest.Data;");
            tf.AppendLine("public DummyClass bent { PropInt = 1986 }");
            tf.AppendLine("public function int DummyFunc(){ return 729; }");

            var files = FileBuilder.ParseFiles((ILogger)null, typeof(DummyClass).Assembly,
                                               new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()),
                                               new Tuple <string, string>("SomeTool." + Main.StepBroFileExtension, tf.ToString()),
                                               new Tuple <string, string>("SpecialTest." + Main.StepBroFileExtension, CreateSpecialTestFile()),
                                               new Tuple <string, string>("TestFramework." + Main.StepBroFileExtension, CreateTestFrameworkFile()));
            var myfile    = files.First(file => file.FileName == "myfile." + Main.StepBroFileExtension);
            var special   = files.First(file => file.FileName == "SpecialTest." + Main.StepBroFileExtension);
            var framework = files.First(file => file.FileName == "TestFramework." + Main.StepBroFileExtension);

            Assert.AreEqual(7, myfile.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            Assert.AreEqual(1, myfile.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            Assert.AreEqual(6, special.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            Assert.AreEqual(1, special.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            Assert.AreEqual(7, framework.ListElements().Where(e => e.ElementType == FileElementType.ProcedureDeclaration).Count());
            Assert.AreEqual(1, framework.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());

            var list = myfile["AllTests"] as ITestList;

            Assert.AreEqual("AllTests", list.Name);
            Assert.AreEqual(3, list.EntryCount);
            Assert.AreEqual("FirstTestCase", list[0].ReferenceName);
            Assert.AreEqual("SecondTestCase", list[1].ReferenceName);
            Assert.AreEqual("ThirdTestCase", list[2].ReferenceName);

            var procedure = myfile.ListElements().First(p => p.Name == "ExecuteAllTests") as IFileProcedure;
            //var testcase = special.ListElements().First(p => p.Name == "TestCase") as IFileProcedure;
            //var testcasebase = framework.ListElements().First(p => p.Name == "TestCaseBase") as IFileProcedure;

            var taskContext = ExecutionHelper.ExeContext(services: FileBuilder.LastServiceManager.Manager);

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - myfile.ExecuteAllTests - <arguments>");
            log.ExpectNext("2 - Pre - TestFramework.TestSuiteFormalTestExecution - <arguments>");

            log.ExpectNext("3 - Pre - myfile.MyPreTest - <arguments>");
            log.ExpectNext("4 - Normal - 31 - log: MyPreTest:20");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: FirstTestCase");
            log.ExpectNext("3 - Pre - myfile.TestCaseLocalSetup - <arguments>");
            log.ExpectNext("4 - Normal - 7 - log: TestCaseLocalSetup FirstTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.FirstTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 19 - log: Inside FirstTestCase: 20");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - SpecialTest.TestCaseCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 8 - log: TestCaseCleanup FirstTestCase");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: SecondTestCase");
            log.ExpectNext("3 - Pre - SpecialTest.TestCaseSpecialSetup - <arguments>");
            log.ExpectNext("4 - Normal - 10 - log: TestCaseSpecialSetup SecondTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.SecondTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 22 - log: Inside SecondTestCase: 1986");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - SpecialTest.TestCaseCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 8 - log: TestCaseCleanup SecondTestCase");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Normal - 34 - log: Starting Test: ThirdTestCase");
            log.ExpectNext("3 - Pre - SpecialTest.TestCaseSetup - <arguments>");
            log.ExpectNext("4 - Normal - 6 - log: TestCaseSetup ThirdTestCase");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - <DYNAMIC CALL> myfile.ThirdTestCase - <arguments>");
            log.ExpectNext("4 - Normal - 24 - log: Inside ThirdTestCase: 729");
            log.ExpectNext("4 - Post");
            log.ExpectNext("3 - Pre - SpecialTest.TestCaseCleanup - <arguments>");
            log.ExpectNext("4 - Normal - 8 - log: TestCaseCleanup ThirdTestCase");
            log.ExpectNext("4 - Post");

            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }
        public void ErrorHandling_SubProcedure_Pass()
        {
            // With title and expect is passing
            var f = new StringBuilder();

            f.AppendLine("bool MySub()");
            f.AppendLine("{");
            f.AppendLine("   log (\"ResultB1: \" + this.Result.Verdict);");
            f.AppendLine("   log (\"ResultB1.HasFails: \" + this.HasFails);");
            f.AppendLine("   log (\"ResultB1.HasErrors: \" + this.HasErrors);");
            f.AppendLine("   expect (4 < 10);");
            f.AppendLine("   log (\"ResultB2: \" + this.Result.Verdict);");
            f.AppendLine("   log (\"ResultB2.HasFails: \" + this.HasFails);");
            f.AppendLine("   log (\"ResultB2.HasErrors: \" + this.HasErrors);");
            f.AppendLine("   return true;");
            f.AppendLine("}");
            f.AppendLine("bool MyProcedure()");
            f.AppendLine("{");
            f.AppendLine("   bool result;");
            f.AppendLine("   log (\"ResultA1: \" + this.Result.Verdict);");
            f.AppendLine("   log (\"ResultA1.HasFails: \" + this.HasFails);");
            f.AppendLine("   log (\"ResultA1.HasErrors: \" + this.HasErrors);");
            f.AppendLine("   result = MySub();");
            f.AppendLine("   log (\"ResultA2: \" + this.Result.Verdict);");
            f.AppendLine("   log (\"ResultA2.HasFails: \" + this.HasFails);");
            f.AppendLine("   log (\"ResultA2.HasErrors: \" + this.HasErrors);");
            f.AppendLine("   return result;");
            f.AppendLine("}");
            var file      = FileBuilder.ParseFile(null, f.ToString());
            var procedure = file.GetFileElement <IFileProcedure>("MyProcedure");;

            var taskContext = ExecutionHelper.ExeContext();
            var result      = taskContext.CallProcedure(procedure);

            Assert.AreEqual(true, (bool)result);

            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();

            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyProcedure - <arguments>");
            log.ExpectNext("2 - Normal - 15 - log: ResultA1: Unset");
            log.ExpectNext("2 - Normal - 16 - log: ResultA1.HasFails: False");
            log.ExpectNext("2 - Normal - 17 - log: ResultA1.HasErrors: False");
            log.ExpectNext("2 - Pre - MySub - <arguments>");
            log.ExpectNext("3 - Normal - 3 - log: ResultB1: Unset");
            log.ExpectNext("3 - Normal - 4 - log: ResultB1.HasFails: False");
            log.ExpectNext("3 - Normal - 5 - log: ResultB1.HasErrors: False");
            log.ExpectNext("3 - Normal - 6 - EXPECT: 4<10; Actual: <TRUE>  =>  Pass");
            log.ExpectNext("3 - Normal - 7 - log: ResultB2: Pass");
            log.ExpectNext("3 - Normal - 8 - log: ResultB2.HasFails: False");
            log.ExpectNext("3 - Normal - 9 - log: ResultB2.HasErrors: False");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Normal - 19 - log: ResultA2: Pass");
            log.ExpectNext("2 - Normal - 20 - log: ResultA2.HasFails: False");
            log.ExpectNext("2 - Normal - 21 - log: ResultA2.HasErrors: False");
            log.ExpectNext("2 - Post");
        }
        public void TestSetupBasic()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("procedure void TestCase() :");
            f.AppendLine("    FreeParameters,");
            f.AppendLine("    partner Setup : TestCaseBaseSetup,");
            f.AppendLine("    partner Cleanup : TestCaseBaseCleanup;");

            f.AppendLine("procedure void TestCaseBaseSetup(this TestCase testcase){ log (\"Doing setup for \" + testcase.Name); }");
            f.AppendLine("procedure void TestCaseBaseCleanup(this TestCase testcase){ log (\"Doing cleanup for \" + testcase.Name); }");

            f.AppendLine("procedure void FirstTestCase() : TestCase {}");
            f.AppendLine("procedure void SecondTestCase() : TestCase {}");
            f.AppendLine("procedure void ThirdTestCase() : TestCase {}");

            f.AppendLine("testlist AllTests");
            f.AppendLine("{");
            f.AppendLine("   * FirstTestCase");
            f.AppendLine("   * SecondTestCase");
            f.AppendLine("   * ThirdTestCase");
            f.AppendLine("}");

            f.AppendLine("procedure void ExecuteAllTests()");
            f.AppendLine("{");
            f.AppendLine("   var iterator = AllTests.GetProcedureIterator();");
            f.AppendLine("   while (iterator.GetNext())");
            f.AppendLine("   {");
            f.AppendLine("      log (\"Starting Test: \" + iterator.Procedure.Name);");
            f.AppendLine("      TestCase testcase = iterator.Procedure;");
            f.AppendLine("      testcase.Setup();");
            f.AppendLine("      iterator.Procedure( iterator.Arguments );");
            f.AppendLine("      testcase.Cleanup();");
            f.AppendLine("   }");
            f.AppendLine("}");

            var file = FileBuilder.ParseFiles((ILogger)null, new Tuple <string, string>("myfile." + Main.StepBroFileExtension, f.ToString()))[0];

            Assert.AreEqual(1, file.ListElements().Where(e => e.ElementType == FileElementType.TestList).Count());
            var list = file["AllTests"] as ITestList;

            Assert.AreEqual("AllTests", list.Name);
            Assert.AreEqual(3, list.EntryCount);
            Assert.AreEqual("FirstTestCase", list[0].ReferenceName);
            Assert.AreEqual("SecondTestCase", list[1].ReferenceName);
            Assert.AreEqual("ThirdTestCase", list[2].ReferenceName);
            Assert.AreSame(file["FirstTestCase"], list[0].Reference);
            Assert.AreSame(file["SecondTestCase"], list[1].Reference);
            Assert.AreSame(file["ThirdTestCase"], list[2].Reference);
            Assert.AreEqual("FirstTestCase", list[0].Reference.Name);
            Assert.AreEqual("SecondTestCase", list[1].Reference.Name);
            Assert.AreEqual("ThirdTestCase", list[2].Reference.Name);
            Assert.AreSame(list, list[0].Home);
            Assert.AreSame(list, list[1].Home);
            Assert.AreSame(list, list[2].Home);

            var procedure = file.ListElements().First(p => p.Name == "ExecuteAllTests") as IFileProcedure;

            var taskContext = ExecutionHelper.ExeContext();

            taskContext.CallProcedure(procedure);
            var log = new LogInspector(taskContext.Logger);

            log.DebugDump();
            log.ExpectNext("0 - Pre - TestRun - Starting");
            log.ExpectNext("1 - Pre - MyFile.ExecuteAllTests - <arguments>");
            log.ExpectNext("2 - Normal - 22 - log: Starting Test: FirstTestCase");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseSetup - <arguments>");
            log.ExpectNext("3 - Normal - 6 - log: Doing setup for FirstTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.FirstTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseCleanup - <arguments>");
            log.ExpectNext("3 - Normal - 7 - log: Doing cleanup for FirstTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Normal - 22 - log: Starting Test: SecondTestCase");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseSetup - <arguments>");
            log.ExpectNext("3 - Normal - 6 - log: Doing setup for SecondTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.SecondTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseCleanup - <arguments>");
            log.ExpectNext("3 - Normal - 7 - log: Doing cleanup for SecondTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Normal - 22 - log: Starting Test: ThirdTestCase");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseSetup - <arguments>");
            log.ExpectNext("3 - Normal - 6 - log: Doing setup for ThirdTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - <DYNAMIC CALL> MyFile.ThirdTestCase - <arguments>");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Pre - MyFile.TestCaseBaseCleanup - <arguments>");
            log.ExpectNext("3 - Normal - 7 - log: Doing cleanup for ThirdTestCase");
            log.ExpectNext("3 - Post");
            log.ExpectNext("2 - Post");
            log.ExpectEnd();
        }