Exemplo n.º 1
0
        public void FileParsing_AccessVariablesSameNamespace()
        {
            var files = FileBuilder.ParseFiles((ILogger)null,
                                               new Tuple <string, string>("andrea.sbs", "using \"betty.sbs\"; namespace Anders; procedure int Absalon(){ \r\n int i = varPublic;\r\n i += varProtected;\r\n return i; }"),
                                               new Tuple <string, string>("betty.sbs", "namespace Anders; public int varPublic = 5; protected int varProtected = 8; private int varPrivate = 11;"));

            Assert.AreEqual(2, files.Length);
            Assert.AreEqual("andrea.sbs", files[0].FileName);
            Assert.AreEqual("betty.sbs", files[1].FileName);
            Assert.AreEqual(0, files[0].Errors.ErrorCount);
            Assert.AreEqual(0, files[1].Errors.ErrorCount);
            var procedureA = files[0].ListElements().First(p => p.Name == "Absalon") as IFileProcedure;

            Assert.IsNotNull(procedureA);
            var element = files[1].ListElements().First(p => p.Name == "varPublic") as IFileElement;

            Assert.IsNotNull(element);
            element = files[1].ListElements().First(p => p.Name == "varProtected") as IFileElement;
            Assert.IsNotNull(element);
            element = files[1].ListElements().First(p => p.Name == "varPrivate") as IFileElement;
            Assert.IsNotNull(element);

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

            var result = taskContext.CallProcedure(procedureA);

            Assert.AreEqual(13L, result);
        }
Exemplo n.º 2
0
        public void TesSBPecialFileVariableWithPropblockConfig()
        {
            var f = new StringBuilder();

            f.AppendLine("using " + typeof(DummyInstrumentClass).Namespace + ";");
            f.AppendLine("namespace ObjectUsing;");
            f.AppendLine("public " + typeof(DummyInstrumentClass).Name + " myTool");
            f.AppendLine("{");
            f.AppendLine("   BoolA: true,");
            f.AppendLine("   IntA:  19");
            //f.AppendLine("   Names: [\"Anders\", \"Bent\", \"Chris\"]");
            f.AppendLine("}");
            f.AppendLine("procedure int UseObject()");
            f.AppendLine("{");
            f.AppendLine("   return myTool.Fcn(\"Janse\", false);");
            f.AppendLine("}");
            var files = FileBuilder.ParseFiles((ILogger)null, this.GetType().Assembly,
                                               new Tuple <string, string>("myfile.sbs", f.ToString()));

            Assert.AreEqual("ObjectUsing", files[0].Namespace);
            var procedure = files[0].ListElements().First(p => p.Name == "UseObject") as IFileProcedure;

            Assert.AreEqual("UseObject", procedure.Name);

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

            Assert.AreEqual(19L, result);
        }
Exemplo n.º 3
0
        public static bool ParseFiles(bool force)
        {
            if (force || CheckIfFileParsingNeeded())
            {
                ILoggerScope logger = null;
                try
                {
                    logger = m_rootLogger.LogEntering("StepBro.Main", "Starting file parsing");
                    foreach (var f in m_loadedFilesManager.ListFiles <ScriptFile>())
                    {
                        f.ResetBeforeParsing(preserveUpdateableElements: force == false);
                    }

                    m_lastParsingErrorCount = FileBuilder.ParseFiles(m_serviceManagerAdmin.Manager, logger);
                }
                finally
                {
                    logger.LogExit("StepBro.Main", $"Ended file parsing. {m_lastParsingErrorCount} errors.");
                }
                return(m_lastParsingErrorCount == 0);
            }
            else
            {
                return(true);    // Success (at least no failures) ...
            }
        }
        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();
        }
        public void TestPartnerOnTestList_WithReturn()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("testlist MyTestSuite :");
            f.AppendLine("    partner MyHelper : Helper;");
            f.AppendLine("procedure string Helper(this MyTestSuite suite)");
            f.AppendLine("{ return \"Was here!\"; }");
            f.AppendLine("procedure void ExecuteIt()");
            f.AppendLine("{");
            f.AppendLine("   log (\"Before\");");
            f.AppendLine("   string res = \"\";");
            f.AppendLine("   res = MyTestSuite.MyHelper();");
            f.AppendLine("   log (\"res: \" + res);");
            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 - Post");
            log.ExpectNext("2 - Normal - 11 - log: res: Was here!");
            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();
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
        [TestMethod, Ignore]    // public using is not working yet.
        public void FileParsing_AccessProcedureInUsedFilesPublicUsingFile()
        {
            var files = FileBuilder.ParseFiles((ILogger)null,
                                               new Tuple <string, string>("andrea.sbs", "using \"betty.sbs\"; procedure int Absalon(){ int i = 0; i = Christian(); return i; }"),
                                               new Tuple <string, string>("betty.sbs", "public using \"chrissy.sbs\";"),
                                               new Tuple <string, string>("chrissy.sbs", "public int Christian() { return 82; }"));

            Assert.AreEqual(3, files.Length);
            Assert.AreEqual("andrea.sbs", files[0].FileName);
            Assert.AreEqual("betty.sbs", files[1].FileName);
            Assert.AreEqual("chrissy.sbs", files[2].FileName);
            Assert.AreEqual(0, files[0].Errors.ErrorCount);
            Assert.AreEqual(0, files[1].Errors.ErrorCount);
            Assert.AreEqual(0, files[2].Errors.ErrorCount);
            var procedureA = files[0].ListElements().First(p => p.Name == "Absalon") as IFileProcedure;

            Assert.IsNotNull(procedureA);
        }
Exemplo n.º 9
0
        //private static IAsyncResult EnqueueTask(Action action)
        //{
        //    var combinedActions = new DoubleAction(action, OnRunningTaskEnd);
        //    var task = new Task(combinedActions.ActionDoSecondAlways);
        //    lock (m_runningTasksSync)
        //    {
        //        if (m_runningTasks.Count == 0)
        //        {
        //            task.Start();
        //        }
        //        m_runningTasks.Enqueue(task);
        //    }
        //    return task;
        //}

        //private static void OnRunningTaskEnd()
        //{
        //    lock (m_runningTasksSync)
        //    {
        //        m_runningTasks.Dequeue();   // Remove task that just ended.
        //        if (m_runningTasks.Count > 0)
        //        {
        //            var next = m_runningTasks.Peek();
        //            next.Start();
        //        }
        //    }
        //}

        /// <summary>
        /// Starts a task parsing all loaded script files.
        /// </summary>
        /// <param name="force">Set to true to force a parsing of all files.</param>
        /// <returns>True if parsing succeeded (no errors or parsing skipped).</returns>
        public static ITask StartFileParsing(bool force)
        {
            if (m_parsingInQueue != null)
            {
                return(m_parsingInQueue);
            }
            if (force || CheckIfFileParsingNeeded())
            {
                m_parsingInQueue = m_hostActions.AddTask("Script File Parsing", true, null, (context) =>
                {
                    try
                    {
                        context.UpdateStatus($"Resetting files ({(force ? "forced" : "not forced")})");
                        foreach (var f in m_loadedFilesManager.ListFiles <ScriptFile>())
                        {
                            f.ResetBeforeParsing(preserveUpdateableElements: force == false);
                        }

                        context.UpdateStatus("Parsing files");
                        m_lastParsingErrorCount = FileBuilder.ParseFiles(m_serviceManagerAdmin.Manager, context.Logger);
                    }
                    catch (Exception ex)
                    {
                        m_lastParsingErrorCount = 1;        // At least one...
                        context.Logger.LogError("File Parsing", ex.ToString());
                    }
                    finally
                    {
                        context.UpdateStatus($"Finished parsing. {m_lastParsingErrorCount} parsing error(s).");
                        m_parsingInQueue = null;
                        ParsingCompleted?.Invoke(null, EventArgs.Empty);
                    }
                });
                return(m_parsingInQueue);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        public void TestFileParsingSimpleFileUsings()
        {
            var files = FileBuilder.ParseFiles((ILogger)null,
                                               new Tuple <string, string>("andrea.sbs", "using \"betty.sbs\"; namespace Anders; procedure int Absalon(){ int i = 0; i = Bethlehem(); return i; }"),
                                               new Tuple <string, string>("betty.sbs", "namespace Anders; public procedure int Bethlehem(){ return 7161; }"));

            Assert.AreEqual(2, files.Length);
            Assert.AreEqual("andrea.sbs", files.ElementAt(0).FileName);
            Assert.AreEqual("betty.sbs", files.ElementAt(1).FileName);
            var procedureA = files[0].ListElements().First(p => p.Name == "Absalon") as IFileProcedure;

            Assert.AreEqual("Absalon", procedureA.Name);
            var procedureB = files[1].ListElements().First(p => p.Name == "Bethlehem") as IFileProcedure;

            Assert.AreEqual("Bethlehem", procedureB.Name);

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

            var result = taskContext.CallProcedure(procedureA);

            Assert.AreEqual(7161L, result);
        }
Exemplo n.º 11
0
        public void TestFileVariableWithEmptyPropertyBlock()
        {
            var f = new StringBuilder();

            f.AppendLine("using " + typeof(DummyInstrumentClass).Namespace + ";");
            f.AppendLine("namespace ObjectUsing;");
            f.AppendLine("public DummyInstrumentClass myTool {}");
            f.AppendLine("procedure int Test1()");
            f.AppendLine("{");
            f.AppendLine("   myTool.BoolA = true;");
            f.AppendLine("   myTool.IntA = 44;");
            f.AppendLine("   return myTool.Fcn(\"Janse\", false);");
            f.AppendLine("}");
            f.AppendLine("procedure int Test2()");
            f.AppendLine("{");
            f.AppendLine("   myTool.BoolA = true;");
            f.AppendLine("   myTool.IntA = 44;");
            f.AppendLine("   return myTool.Fcn(\"Janse\", true);");
            f.AppendLine("}");
            var files = FileBuilder.ParseFiles((ILogger)null, this.GetType().Assembly,
                                               new Tuple <string, string>("myfile.sbs", f.ToString()));

            Assert.AreEqual("ObjectUsing", files[0].Namespace);

            var procedure = files[0].ListElements().First(p => p.Name == "Test1") as IFileProcedure;

            Assert.AreEqual("Test1", procedure.Name);
            var taskContext = ExecutionHelper.ExeContext();
            var result      = taskContext.CallProcedure(procedure);

            Assert.AreEqual(44L, result);

            procedure = files[0].ListElements().First(p => p.Name == "Test2") as IFileProcedure;
            Assert.AreEqual("Test2", procedure.Name);
            taskContext = ExecutionHelper.ExeContext();
            result      = taskContext.CallProcedure(procedure);
            Assert.AreEqual(77L, result);
        }
Exemplo n.º 12
0
        public void TestFileParsingWithReParsing()
        {
            var f = new StringBuilder();

            f.AppendLine("using " + typeof(DummyInstrumentClass).Namespace + ";");  // An object with the IResettable interface.
            f.AppendLine("namespace ObjectUsing;");
            f.AppendLine("public " + typeof(DummyInstrumentClass).Name + " myTool");
            f.AppendLine("{");
            f.AppendLine("   BoolA: true,");
            f.AppendLine("   IntA:  19");
            f.AppendLine("}");
            f.AppendLine("procedure " + typeof(DummyInstrumentClass).Name + " GetObject() { return myTool; }");

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

            Assert.AreEqual("myfile.sbs", files.ElementAt(0).FileName);
            var procGetObject = files[0].ListElements().First(p => p.Name == "GetObject") as IFileProcedure;

            Assert.AreEqual("GetObject", procGetObject.Name);

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

            var obj1 = taskContext.CallProcedure(procGetObject) as DummyInstrumentClass;

            Assert.IsNotNull(obj1);
            Assert.AreEqual(1, obj1.ResetCounts);
            Assert.AreEqual(10, obj1.ID);
            Assert.AreEqual(19, obj1.IntA);

            file.ResetBeforeParsing(true);
            file.SetParserFileStream(f.ToString());
            var errorCount = FileBuilder.ParseFiles(FileBuilder.LastServiceManager.Manager, null, file);

            procGetObject = file.ListElements().First(p => p.Name == "GetObject") as IFileProcedure;
            Assert.IsNotNull(procGetObject);
            var obj2 = taskContext.CallProcedure(procGetObject) as DummyInstrumentClass;

            Assert.IsNotNull(obj2);
            Assert.IsTrue(Object.ReferenceEquals(obj1, obj2));
            Assert.AreEqual(1, obj2.ResetCounts);
            Assert.AreEqual(10, obj2.ID);
            Assert.AreEqual(19, obj2.IntA);


            f = new StringBuilder();
            f.AppendLine("using " + typeof(DummyInstrumentClass).Namespace + ";");
            f.AppendLine("namespace ObjectUsing;");
            f.AppendLine("public " + typeof(DummyInstrumentClass).Name + " myTool");
            f.AppendLine("{");
            f.AppendLine("   BoolA: true,");
            f.AppendLine("   IntA:  37");
            f.AppendLine("}");
            f.AppendLine("procedure " + typeof(DummyInstrumentClass).Name + " GetObject() { return myTool; }");
            file.ResetBeforeParsing(true);
            file.SetParserFileStream(f.ToString());
            errorCount    = FileBuilder.ParseFiles(FileBuilder.LastServiceManager.Manager, null, file);
            procGetObject = file.ListElements().First(p => p.Name == "GetObject") as IFileProcedure;
            Assert.IsNotNull(procGetObject);
            var obj3 = taskContext.CallProcedure(procGetObject) as DummyInstrumentClass;

            Assert.IsNotNull(obj3);
            Assert.IsTrue(Object.ReferenceEquals(obj1, obj3));
            Assert.AreEqual(2, obj3.ResetCounts);
            Assert.AreEqual(10, obj3.ID);
            Assert.AreEqual(37, obj3.IntA);
        }
        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();
        }
        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 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();
        }
Exemplo n.º 16
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);
            }
        }