示例#1
0
 private object RunAsyncTestMethod(TestExecutionContext context)
 {
     TLogger.Write("##### RunAsyncTestMethod in TTestMethodCommand class #####");
     #region tronghieu.d - invoke async test method in application thread. This thread is blocked for waiting result.
     using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(testMethod.Method.MethodInfo))
     {
         TAsyncThreadMgr asyncThreadMgr = TAsyncThreadMgr.GetInstance();
         asyncThreadMgr.SetData(this, testMethod, arguments, context, true);
         asyncThreadMgr.GetMethodExecutionResetEvent().Set(); // release main thread to invoke method
         _testMethodRunComplete.WaitOne();                    // wait for result in current thread
         if (asyncThreadMgr.GetNonAsyncMethodException() != null)
         {
             throw asyncThreadMgr.GetNonAsyncMethodException();
         }
         try
         {
             if (asyncThreadMgr.GetResult() == null)
             {
                 return(asyncThreadMgr.GetResult());
             }
             return(region.WaitForPendingOperationsToComplete(asyncThreadMgr.GetResult()));
         }
         catch (Exception e)
         {
             throw new NUnitException("Rethrown", e);
         }
     }
     #endregion
 }
示例#2
0
        public void runTearDown()
        {
            TLogger.Write("##### runTearDown in TAsyncThreadMgr class #####");
            if (context?.ExecutionStatus == TestExecutionStatus.AbortRequested)
            {
                return;
            }

            try
            {
                foreach (var item in _teardownItem)
                {
                    // Even though we are only running one level at a time, we
                    // run the teardowns in reverse order to provide consistency.
                    if (item?._tearDownMethods != null)
                    {
                        int index = item._tearDownMethods.Count;
                        while (--index >= 0)
                        {
                            item.RunSetUpOrTearDownMethod(context, item._tearDownMethods[index]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                context.CurrentResult.RecordTearDownException(ex);
            }
        }
示例#3
0
        private bool SyncSessionIdRequest()
        {
            TLogger.Write("############### In SyncSessionIdRequest ###############");
            Console.WriteLine("[TUnitTest] - " + "In SyncSessionIdRequest");

            string result = RequestGET("init_session_id", _session_id);

            if (result == null)
            {
                return(false);
            }

            CheckServer();

            //string[] jobj = ResultParser (result);
            //if (jobj [1] == "OK" && jobj [2] == "1")
            //	return true;

            Dictionary <string, string> dic = parseJson(result);

            if (dic["OK"].Equals("1"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public bool AskNextStepRequest()
        {
            Console.WriteLine("[TUnitTest] - " + "In AskNextStepRequest");

            string result = RequestGET("ask_next_step", _session_id);

            TLogger.Write("############### In AskNextStepRequest ###############");

            if (result == null)
            {
                return(false);
            }

            Dictionary <string, string> dic = parseJson(result);

            if (dic == null)
            {
                return(false);
            }

            if (dic["step"].Equals("continue"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public void ConnectTestkitStub()
        {
            TLogger.Write("############### ConnectTestkitStub ###############");
            Random rnd = new Random();

            _session_id  = rnd.Next(1000, 9999);
            _server      = "http://127.0.0.1:8000";
            _isSlaveMode = SyncSessionIdRequest();
            Console.WriteLine("[TUnitTest] - " + "IsSlaveMode : " + _isSlaveMode);
        }
示例#6
0
        public void SubmitManualResult()
        {
            TLogger.Write("############### SubmitManualResult ###############");
            LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Manual test execution done.");

            if (_isSlaveMode == true)
            {
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Submit result to inform manual execution done.");
                RequestGET("generate_xml");
            }
        }
示例#7
0
 public void NextStepRequest()
 {
     TLogger.Write("############### NextStepRequest ###############");
     if (AskNextStepRequest())
     {
         CheckExecutionProgressRequest();
     }
     if (AskNextStepRequest())
     {
         Testcase_ID = AutoTestTaskRequest();
     }
 }
示例#8
0
        private string RequestGET(string key)
        {
            TLogger.Write("############### In RequestGET ###############");
            Console.WriteLine("[TUnitTest] - " + "In RequestGET");

            string result = null;
            string url    = _server + "/" + key;

            Console.WriteLine("[TUnitTest] - " + "RequestGET url : " + url);
            TLogger.Write("############### RequestGET url ###############");

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                //Reference
                // https://msdn.microsoft.com/en-us/library/czdt10d3(v=vs.110).aspx

                WebProxy proxyObject = new WebProxy(_server, true);
                request.Proxy = proxyObject;


                IWebProxy proxy = request.Proxy;

                if (proxy != null)
                {
                    Console.WriteLine("[TUnitTest] - Proxy is NOT null. Is ByPassed : " + proxy.IsBypassed(new Uri(url)));
                }
                else
                {
                    Console.WriteLine("[TUnitTest] - " + "Proxy is null; no proxy will be used");
                }

                Task <WebResponse> res = request.GetResponseAsync();
                res.Wait();
                WebResponse  response = res.Result;
                Stream       stream   = response.GetResponseStream();
                StreamReader reader   = new StreamReader(stream);
                result = reader.ReadToEnd();
                Console.WriteLine("[TUnitTest] - " + "RequestGET Result : " + result);
                TLogger.Write("############### RequestGET Result : " + result + " ###############");
                stream.Dispose();
                response.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("[TUnitTest] - " + "RequestGET error : " + e.ToString());
            }

            return(result);
        }
示例#9
0
 public void runSetup()
 {
     TLogger.Write("##### runSetup in TAsyncThreadMgr class #####");
     foreach (var item in _setupteardownItem)
     {
         if (item?._setUpMethods != null)
         {
             foreach (MethodInfo setUpMethod in item._setUpMethods)
             {
                 item.RunSetUpOrTearDownMethod(context, setUpMethod);
             }
         }
     }
 }
示例#10
0
 /* Invoke async test method in main thread*/
 public void RunTestMethod()
 {
     if (testCommand == null || testMethod == null || context == null)
     {
         return;
     }
     TLogger.Write("##### RunTestMethod in TAsyncThreadMgr class #####");
     if (IsAsyncOperation)
     {
         RunAsyncTestMethod();
     }
     else
     {
         RunNonAsyncTestMethod();
     }
 }
示例#11
0
 public void RunAsyncTestMethod()
 {
     TLogger.Write("##### RunAsyncTestMethod in TAsyncThreadMgr class #####");
     try
     {
         result = null;
         #region nguyen.vtan add Setup
         runSetup();
         #endregion
         result = Reflect.InvokeMethod(testMethod.Method.MethodInfo, context.TestObject, arguments);
     }
     catch (Exception e)
     {
         exception = e;
         // Console.WriteLine(e.Message);
     }
     finally
     {
         if (result == null)
         {
             #region nguyen.vtan add Setup
             runTearDown();
             Thread.Sleep(50);
             #endregion
             testCommand._testMethodRunComplete.Set();
             _methodExecutionResetEvent.Reset();
             _methodExecutionResetEvent.WaitOne();
             RunTestMethod();
         }
         else
         {
             ((Task)result).GetAwaiter().OnCompleted(() =>
             {
                 #region nguyen.vtan add TearDown
                 runTearDown();
                 Thread.Sleep(50);
                 #endregion
                 testCommand._testMethodRunComplete.Set();
                 _methodExecutionResetEvent.Reset();
                 _methodExecutionResetEvent.WaitOne();
                 RunTestMethod();
             });
         }
     }
 }
示例#12
0
        private object RunNonAsyncTestMethod(TestExecutionContext context)
        {
            TLogger.Write("##### RunNonAsyncTestMethod in TTestMethodCommand class #####");
            #region tronghieu.d - invoke async test method in application thread. This thread is blocked for waiting result.
            TAsyncThreadMgr asyncThreadMgr = TAsyncThreadMgr.GetInstance();
            asyncThreadMgr.SetData(this, testMethod, arguments, context, false);
            asyncThreadMgr.GetMethodExecutionResetEvent().Set(); // release main thread to invoke method
            _testMethodRunComplete.WaitOne();                    // wait for result in current thread

            if (asyncThreadMgr.GetNonAsyncMethodException() != null)
            {
                throw asyncThreadMgr.GetNonAsyncMethodException();
            }

            return(asyncThreadMgr.GetResult());

            #endregion
            //return testMethod.Method.Invoke(context.TestObject, arguments);
        }
示例#13
0
 public void RunNonAsyncTestMethod()
 {
     TLogger.Write("##### RunNonAsyncTestMethod in TAsyncThreadMgr class #####\n");
     try
     {
         runSetup();
         result = testMethod.Method.Invoke(context.TestObject, arguments);
     }
     catch (Exception ex)
     {
         exception = ex;
     }
     #region nguyen.vtan add TearDown
     runTearDown();
     #endregion
     testCommand._testMethodRunComplete.Set();
     _methodExecutionResetEvent.Reset();
     _methodExecutionResetEvent.WaitOne();
 }
示例#14
0
        private bool CheckServer()
        {
            TLogger.Write("############### In CheckServer ###############");
            Console.WriteLine("[TUnitTest] - " + "In CheckServer");
            string result = RequestGET("check_server");

            if (result == null)
            {
                return(false);
            }

            string[] jobj = ResultParser(result);
            if (jobj != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#15
0
        public string AutoTestTaskRequest()
        {
            Console.WriteLine("[TUnitTest] - " + "In AutoTestTaskRequest");

            string result = RequestGET("auto_test_task", _session_id);

            TLogger.Write("############### In AutoTestTaskRequest ###############");
            TLogger.Write("");
            TLogger.Write("");
            TLogger.Write("");

            if (result == null)
            {
                return("");
            }

            Dictionary <string, string> dic = parseJson(result);

            if (dic == null)
            {
                return("");
            }

            if (dic.ContainsKey("none"))
            {
                IsLastTC = true;
            }

            try
            {
                Console.WriteLine("[TUnitTest] - " + "TC name received:[" + dic["case_id"] + "]");
            }
            catch (Exception e)
            {
                Console.WriteLine("[TUnitTest] - " + "Json parsing Error : " + e.Message);
                return("");
            }

            return(dic["case_id"]);
        }
示例#16
0
        public string RequestPOST(string key, string json)
        {
            Console.WriteLine("[TUnitTest] - " + "In RequestPOST");
            string result = null;

            TLogger.Write("############### In RequestPOST ###############");
            string url = _server + "/" + key;

            json = json + "&session_id=" + _session_id;

            Console.WriteLine("[TUnitTest] - " + "RequestPOST url :" + url);

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); // WebRequest 객체 형성 및 HttpWebRequest 로 형변환


                //Reference
                // https://msdn.microsoft.com/en-us/library/czdt10d3(v=vs.110).aspx

                WebProxy proxyObject = new WebProxy(_server, true);
                request.Proxy = proxyObject;


                IWebProxy proxy = request.Proxy;

                if (proxy != null)
                {
                    Console.WriteLine("[TUnitTest] - Proxy is NOT null. Is ByPassed : " + proxy.IsBypassed(new Uri(url)));
                }
                else
                {
                    Console.WriteLine("[TUnitTest] - " + "Proxy is null; no proxy will be used");
                }

                request.Method      = "POST"; // 전송 방법 "GET" or "POST"
                request.ContentType = "application/json";

                byte[] byteArray = Encoding.UTF8.GetBytes(json);

                Task <Stream> dataAsync = request.GetRequestStreamAsync();
                dataAsync.Wait();
                Stream dataStream = dataAsync.Result;
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Dispose();

                Task <WebResponse> resAsync = request.GetResponseAsync();
                resAsync.Wait();

                WebResponse response = resAsync.Result;

                Stream       respPostStream = response.GetResponseStream();
                StreamReader reader         = new StreamReader(respPostStream);
                result = reader.ReadToEnd();

                Console.WriteLine("[TUnitTest] - " + "###############Asavin############### RequestPOST Result :" + result);
                reader.Dispose();

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine("[TUnitTest] - " + "RequestPOST ERROR :" + e.Message);
            }
            return(result);
        }