Ejemplo n.º 1
0
		public void Execute()
		{
			try
			{
				mCaseQueue = new ConcurrentQueue<ITestCase>();
				Handler = Case.Handler;
				if (Handler == null)
					Handler = new TestProcessHandler();
				Started = true;
				this.StatisticalInfo.Reset();
				this.StatisticalInfo.Success.Result();
				this.StatisticalInfo.Error.Result();
				GetDelayTimes();
				Type caseType = Case.GetType();
				object config = null;
				System.Reflection.PropertyInfo property = caseType.GetProperty("Config", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
				if (property != null)
				{
					if (property.PropertyType.IsEnum || property.PropertyType.IsValueType || property.PropertyType == typeof(string))
					{
						Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(Config);
						config = jobj["Value"].ToObject(property.PropertyType);

					}
					else
					{
						config = Newtonsoft.Json.JsonConvert.DeserializeObject(Config, property.PropertyType);
					}

				}
				for (int i = 0; i < Users; i++)
				{
					ITestCase item = (ITestCase)Activator.CreateInstance(caseType);
					if (property != null)
					{
						property.SetValue(item, config);
					}
					try
					{
						item.Init();
					}
					catch (Exception e_)
					{
						AddError(new Exception(string.Format("test case init error {0}", e_.Message)));
						return;
					}
					item.Error = OnError;
					item.Success = OnSuccess;
					mCaseQueue.Enqueue(item);
				}

				System.Threading.ThreadPool.QueueUserWorkItem(OnExecute);
			}
			catch (Exception e_)
			{
				AddError(e_);
			}
		}
Ejemplo n.º 2
0
        public void Execute()
        {
            mCaseQueue = new ConcurrentQueue <ITestCase>();
            Handler    = Case.Handler;
            if (Handler == null)
            {
                Handler = new TestProcessHandler();
            }
            Started = true;
            this.StatisticalInfo.Reset();
            this.StatisticalInfo.Success.Result();
            this.StatisticalInfo.Error.Result();
            GetDelayTimes();
            Type   caseType = Case.GetType();
            object config   = null;

            System.Reflection.PropertyInfo property = caseType.GetProperty("Config", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            if (property != null)
            {
                config = Newtonsoft.Json.JsonConvert.DeserializeObject(Config, property.PropertyType);
            }
            for (int i = 0; i < Users; i++)
            {
                ITestCase item = (ITestCase)Activator.CreateInstance(caseType);
                if (property != null)
                {
                    property.SetValue(item, config);
                }
                item.Init();
                item.Error   = OnError;
                item.Success = OnSuccess;
                mCaseQueue.Enqueue(item);
            }

            System.Threading.ThreadPool.QueueUserWorkItem(OnExecute);
        }