Example #1
0
        /// <summary>
        /// 获得step的ViewModel,如果在测试步骤信息中指定的ViewModel,使用该ViewModel,否则使用基类ViewModel
        /// </summary>
        /// <param name="step"></param>
        /// <returns></returns>
        public static TestStepVM GetTestStepVM(TestStep step)
        {
            if (ViewModelDict.Keys.Contains(step))
            {
                return(ViewModelDict[step] as TestStepVM);
            }
            else
            {
                TestStepVM vm     = GetViewModelFromModel(step.GetType()) as TestStepVM;
                TestStepVM vm2    = GetStepViewModelFromModel(step.GetType()) as TestStepVM;
                TestStepVM vmReal = new TestStepVM();
                if (vm != null)
                {
                    vm.TestStep = step;
                    vmReal      = vm;
                }
                else if (vm2 != null)
                {
                    vm2.TestStep = step;
                    vmReal       = vm2;
                }
                else
                {
                    vmReal          = new TestStepVM();
                    vmReal.TestStep = step;
                }
                ViewModelDict.Add(step, vmReal);
                return(vmReal);
                //if (vm != null)
                //{
                //    vm.TestStep = step;
                //    //vm.DisplayName = GetStepTypeName(step.GetType());
                //    ViewModelDict.Add(step, vm);
                //}
                //else if(vm2 !=null)
                //{
                //    vm2.TestStep = step;
                //    ViewModelDict.Add(step,vm2);
                //}
                //else
                //{
                //    vm = new TestStepVM();
                //    vm.TestStep = step;
                //    ViewModelDict.Add(step, null);
                //    //vm.DisplayName = GetStepTypeName(step.GetType());
                //}

                //return vm;
            }
        }
Example #2
0
        public static object GetStepViewModelFromModel(Type modelType)
        {
            var        stepInfo = TestStepInfoMgr.Instance.TestStepInfoList.Where(x => x.TypeName == modelType.Name).FirstOrDefault();
            TestStepVM stepVM   = null;

            if (stepInfo != null)
            {
                if (stepInfo.TestStepViewModelStr == null || string.IsNullOrWhiteSpace(stepInfo.TestStepViewModelStr))
                {
                    return(stepVM);
                }
                string   viewModelStr = stepInfo.TestStepViewModelStr;
                string[] strs         = viewModelStr.Split(';');
                string   fileName     = AppDomain.CurrentDomain.BaseDirectory + strs[0];
                viewModelStr = viewModelStr.Remove(0, strs[0].Length + 1);
                Assembly ass          = Assembly.LoadFile(fileName);
                Type     typeVieModel = ass.GetType(viewModelStr);
                stepVM = Activator.CreateInstance(typeVieModel) as TestStepVM;
            }
            return(stepVM);
        }
Example #3
0
        public static TestStepVM GetTestStepVMFromViewModel(TestStep step)
        {
            if (ViewModelDict.Keys.Contains(step))
            {
                return(ViewModelDict[step] as TestStepVM);
            }
            else
            {
                TestStepVM vm = GetViewModelFromModel(step.GetType()) as TestStepVM;
                if (vm != null)
                {
                    vm.TestStep = step;
                    ViewModelDict.Add(step, vm);
                }
                else
                {
                    vm          = new TestStepVM();
                    vm.TestStep = step;
                    ViewModelDict.Add(step, vm);
                }

                return(vm);
            }
        }