Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static T ParseAndRun <T>(
            string returnValueExpression = "0",
            string statements            = "",
            bool varGeneration           = true,
            bool varDummyClass           = false)
        {
            var builder = Parse <T>(returnValueExpression, statements, varGeneration, varDummyClass);

            DummyClass.ResetTestData();
            var    taskContext = ExecutionHelper.ExeContext();
            var    before      = DateTime.Now;
            object result      = taskContext.CallProcedure(builder.Listener.LastParsedProcedure);

            LastExecutionTime = DateTime.Now - before;
            if (taskContext.ExecutionExeception == null)
            {
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(T));
                return((T)result);
            }
            else
            {
                return(default(T));
            }
        }
Ejemplo n.º 4
0
        public void TestFileWithTypedSimpleVariables()
        {
            var procedure = this.CreateTestFile("return i2;");

            var taskContext = ExecutionHelper.ExeContext();

            var result = taskContext.CallProcedure(procedure);

            Assert.AreEqual(20, (long)result);
        }
Ejemplo n.º 5
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();
        }
        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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        public void TestProcedureReferenceCasting()
        {
            var f = new StringBuilder();

            f.AppendLine("namespace MyFile;");
            f.AppendLine("int ProcA(int i) { return i * 10; }");
            f.AppendLine("int ProcB() { int i = 0; procedure ref1 = ProcA; ProcA ref2 = ref1; return ref2(4); }");
            var file = FileBuilder.ParseFile(null, f.ToString());

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

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

            var taskContext = ExecutionHelper.ExeContext();

            var result = taskContext.CallProcedure(procedure);

            Assert.AreEqual(40, (long)result);
        }
Ejemplo n.º 11
0
        public void TestTestListPartnerDirectCall()
        {
            var f = new StringBuilder();

            f.AppendLine("int ParkProc() { return 752; }");
            f.AppendLine("testlist Anton :");
            f.AppendLine("    partner Park : ParkProc;");
            f.AppendLine("int Moskus() {");
            f.AppendLine("   int n = 0;");
            f.AppendLine("   n = Anton.Park();");
            f.AppendLine("   return n;");
            f.AppendLine("}");
            var file      = FileBuilder.ParseFile(null, f.ToString());
            var procedure = file["Moskus"] as IFileProcedure;

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

            Assert.AreEqual(752, (long)result);
        }
Ejemplo n.º 12
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.º 13
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);
        }
Ejemplo n.º 14
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.º 15
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);
        }
Ejemplo n.º 16
0
        public void TestTestListPartnerOverrideCall()
        {
            var f = new StringBuilder();

            f.AppendLine("int ParkProc1() { return 543; }");
            f.AppendLine("int ParkProc2() { return 432; }");
            f.AppendLine("testlist Anton :");
            f.AppendLine("    partner Park : ParkProc1;");
            f.AppendLine("testlist Benny : Anton,");
            f.AppendLine("    partner override Park : ParkProc2;");
            f.AppendLine("int Moskus() {");
            f.AppendLine("   int n = 0;");
            f.AppendLine("   n = Benny.Park();");
            f.AppendLine("   return n;");
            f.AppendLine("}");
            var file      = FileBuilder.ParseFile(null, f.ToString());
            var procedure = file["Moskus"] as IFileProcedure;

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

            Assert.AreEqual(432, (long)result);
        }
Ejemplo n.º 17
0
        public void TestProcedureReferencePartnerOverrideCall()
        {
            var f = new StringBuilder();

            f.AppendLine("int ParkProc1() { return 7722; }");
            f.AppendLine("int ParkProc2() { return 6633; }");
            f.AppendLine("function int Anton() :");
            f.AppendLine("    partner Park : ParkProc1;");
            f.AppendLine("function int Benny() : Anton,");
            f.AppendLine("    partner override Park : ParkProc2;");
            f.AppendLine("int Moskus() {");
            f.AppendLine("   Anton proc = Benny;");
            f.AppendLine("   int n = 0;");
            f.AppendLine("   n = proc.Park();");
            f.AppendLine("   return n;");
            f.AppendLine("}");
            var file      = FileBuilder.ParseFile(null, f.ToString());
            var procedure = file["Moskus"] as IFileProcedure;

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

            Assert.AreEqual(6633, (long)result);
        }
Ejemplo n.º 18
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 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.º 20
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 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 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();
        }