//----< load libraries into child AppDomain and test >-----------

        /*
         * ToDo:
         * - refactor this function to make it more testable.
         */
        public ITestResults test(IRequestInfo testRequest)
        {
            TestResults testResults = new TestResults();

            foreach (ITestInfo test in testRequest.requestInfo)
            {
                TestResult testResult = new TestResult();
                testResult.testName = test.testName;
                try
                {
                    DLog.write("\n  -- \"" + test.testName + "\" --");

                    ITest  tdr            = null;
                    string testDriverName = "";

                    foreach (string file in test.files)
                    {
                        Assembly assem = null;
                        try
                        {
                            if (location.Count() > 0)
                            {
                                assem = Assembly.LoadFrom(location + "/" + file);
                            }
                            else
                            {
                                assem = Assembly.Load(file);
                            }
                        }
                        catch
                        {
                            testResult.testResult = "failed";
                            testResult.testLog    = "file not loaded";
                            DLog.write("\n    could not load \"" + file + "\"");
                            continue;
                        }
                        DLog.write("\n    loaded: \"" + file + "\"");
                        Type[] types = assem.GetExportedTypes();

                        foreach (Type t in types)
                        {
                            if (t.IsClass && typeof(ITest).IsAssignableFrom(t))      // does this type derive from ITest ?
                            {
                                tdr            = (ITest)Activator.CreateInstance(t); // create instance of test driver
                                testDriverName = file;
                                RLog.write("\n    " + testDriverName + " implements ITest interface - Req #5");
                            }
                        }
                    }
                    DLog.write("\n    testing " + testDriverName);
                    if (tdr != null && tdr.test() == true)
                    {
                        testResult.testResult = "passed";
                        testResult.testLog    = tdr.getLog();
                        DLog.write("\n    test passed");
                        DLog.flush();
                        if (cb_ != null)
                        {
                            cb_.sendMessage(new Message(testDriverName + " passed"));
                        }
                    }
                    else
                    {
                        testResult.testResult = "failed";
                        if (tdr != null)
                        {
                            testResult.testLog = tdr.getLog();
                        }
                        else
                        {
                            testResult.testLog = "file not loaded";
                        }
                        DLog.write("\n    test failed");
                        DLog.flush();
                        if (cb_ != null)
                        {
                            cb_.sendMessage(new Message(testDriverName + " failed"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    testResult.testResult = "failed";
                    testResult.testLog    = "exception thrown";
                    RLog.write("\n  " + ex.Message);
                }
                testResults_.testResults.Add(testResult);
            }

            testResults_.dateTime = DateTime.Now;
            return(testResults_);
        }
Ejemplo n.º 2
0
        //----< load libraries into child AppDomain and test >-----------

        /*
         * ToDo:
         * - refactor this function to make it more testable.
         */
        public ITestResults test(IRequestInfo testRequest)
        {
            TestResults testResults = new TestResults();

            foreach (ITestInfo test in testRequest.requestInfo)
            {
                TestResult testResult = new TestResult();
                testResult.testName = test.testName;
                try
                {
                    Console.Write("\n  TID" + Thread.CurrentThread.ManagedThreadId
                                  + ": -- \"" + test.testName + "\" --");

                    ITest  tdr            = null;
                    string testDriverName = "";
                    string fileName       = "";

                    foreach (string file in test.files)
                    {
                        fileName = file;
                        Assembly assem = null;
                        try
                        {
                            if (loadPath_.Count() > 0)
                            {
                                assem = Assembly.LoadFrom(loadPath_ + "/" + file);
                            }
                            else
                            {
                                assem = Assembly.Load(file);
                            }
                        }
                        catch
                        {
                            testResult.testResult = "failed";
                            testResult.testLog    = "file not loaded";
                            Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": can't load\"" + file + "\"");
                            "DLLs not available from the Repository, Test Harness sending error \"file not loaded\" to the client.- Req#3".title();
                            continue;
                        }
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": loaded \"" + file + "\"");
                        Type[] types = assem.GetExportedTypes();

                        foreach (Type t in types)
                        {
                            if (t.IsClass && typeof(ITest).IsAssignableFrom(t)) // does this type derive from ITest ?
                            {
                                "Found a Test Driver derived from ITest and executes test() to get the test status- Req#5".title();
                                try
                                {
                                    testDriverName = file;
                                    tdr            = (ITest)Activator.CreateInstance(t); // create instance of test driver
                                    Console.Write(
                                        "\n    TID" + Thread.CurrentThread.ManagedThreadId + ": " + testDriverName + " implements ITest interface - Req #4"
                                        );
                                }
                                catch
                                {
                                    //Console.Write("\n----" + file + " - exception thrown when created");
                                    continue;
                                }
                            }
                        }
                    }
                    Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": testing " + testDriverName);
                    bool testReturn;
                    try
                    {
                        testReturn = tdr.test();
                    }
                    catch
                    {
                        //Console.Write("\n----exception thrown in " + fileName);
                        testReturn = false;
                    }
                    if (tdr != null && testReturn == true)
                    {
                        testResult.testResult = "passed";
                        testResult.testLog    = tdr.getLog();
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": test passed");
                        if (cb_ != null)
                        {
                            cb_.sendCallbackMessage(new Message(testDriverName + " passed"));
                        }
                    }
                    else
                    {
                        testResult.testResult = "failed";
                        if (tdr != null)
                        {
                            testResult.testLog = tdr.getLog();
                        }
                        else
                        {
                            testResult.testLog = "file not loaded";
                        }
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": test failed");
                        if (cb_ != null)
                        {
                            cb_.sendCallbackMessage(new Message(testDriverName + ": failed"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    testResult.testResult = "failed";
                    testResult.testLog    = "exception thrown";
                    Console.Write("\n  TID" + Thread.CurrentThread.ManagedThreadId + ": " + ex.Message);
                }
                testResults_.testResults.Add(testResult);
            }

            testResults_.dateTime = DateTime.Now;
            testResults_.testKey  = System.IO.Path.GetFileName(loadPath_);
            return(testResults_);
        }
Ejemplo n.º 3
0
        //----< load libraries into child AppDomain and test >-----------

        /*
         * ToDo:
         * - refactor this function to make it more testable.
         */
        public ITestResults test(IRequestInfo testRequest)
        {
            TestResults testResults = new TestResults();

            foreach (ITestInfo test in testRequest.requestInfo)
            {
                TestResult testResult = new TestResult();
                testResult.testName = test.testName;
                try
                {
                    Console.Write("\n  TID" + Thread.CurrentThread.ManagedThreadId + ": -- \"" + test.testName + "\" --");

                    ITest  tdr            = null;
                    string testDriverName = "";
                    string fileName       = "";

                    foreach (string file in test.files)
                    {
                        fileName = file;
                        Assembly assem = null;
                        //load Files from Temp Dir into AppDomain
                        try
                        {
                            if (loadPath_.Count() > 0)
                            {
                                assem = Assembly.LoadFrom(loadPath_ + "/" + file);
                            }
                            else
                            {
                                assem = Assembly.Load(file);
                            }
                        }
                        catch
                        {
                            testResult.testResult = "failed";
                            testResult.testLog    = "file not loaded";
                            Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": can't load\"" + file + "\"");
                            continue;
                        }
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": loaded \"" + file + "\"");
                        Type[] types = assem.GetExportedTypes();
                        //find out test driver and make a instance
                        foreach (Type t in types)
                        {
                            if (t.IsClass && typeof(ITest).IsAssignableFrom(t)) // does this type derive from ITest ?
                            {
                                try
                                {
                                    testDriverName = file;
                                    tdr            = (ITest)Activator.CreateInstance(t); // create instance of test driver
                                    Console.Write(
                                        "\n    TID" + Thread.CurrentThread.ManagedThreadId + ": " + testDriverName + " implements ITest interface - Req #5"
                                        );
                                }
                                catch
                                {
                                    //Console.Write("\n----" + file + " - exception thrown when created");
                                    continue;
                                }
                            }
                        }
                    }
                    Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": testing " + testDriverName);
                    bool testReturn;
                    //run current test
                    try
                    {
                        testReturn = tdr.test();
                    }
                    catch
                    {
                        //Console.Write("\n----exception thrown in " + fileName);
                        testReturn = false;
                    }
                    //write current test result, send simple result through callback
                    if (tdr != null && testReturn == true)
                    {
                        testResult.testResult = "passed";
                        testResult.testLog    = tdr.getLog();
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": test passed");
                        if (cb_ != null)
                        {
                            Message msg = new Message(testDriverName + " passed");
                            msg.type = "TestResult";
                            cb_.sendMessage(msg);
                        }
                    }
                    else
                    {
                        testResult.testResult = "failed";
                        if (tdr != null)
                        {
                            testResult.testLog = tdr.getLog();
                        }
                        else
                        {
                            testResult.testLog = "file not loaded - Req #3";
                        }
                        Console.Write("\n    TID" + Thread.CurrentThread.ManagedThreadId + ": test failed");
                        if (cb_ != null)
                        {
                            Message msg = new Message(testDriverName + " failed");
                            msg.type = "TestResult";
                            cb_.sendMessage(msg);
                        }
                    }
                }
                catch (Exception ex)
                {
                    testResult.testResult = "failed";
                    testResult.testLog    = "exception thrown";
                    Console.Write("\n  TID" + Thread.CurrentThread.ManagedThreadId + ": " + ex.Message);
                }
                testResults_.testResults.Add(testResult);//add current result to results
            }

            testResults_.dateTime = DateTime.Now;
            testResults_.testKey  = System.IO.Path.GetFileName(loadPath_);
            return(testResults_);//resturn Test Results wo Primary AppDomain
        }