Beispiel #1
0
 /// <summary>
 /// 注册对象的消息响应。
 /// 请及时调用UnRegister以取消注册,否则<paramref name="target"/>对象将不会被GC!
 /// </summary>
 public void Register(object target)
 {
     foreach (var method in ExecuteAttribute.GetInstanceExecuteMethod(target.GetType()))
     {
         RegisterMethod(method, target);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 静态消息响应函数
 /// </summary>
 public void StaticRegister()
 {
     foreach (var method in ExecuteAttribute.GetStaticExecuteMethod(Assembly.GetExecutingAssembly()))
     {
         RegisterMethod(method);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Is testClass executable
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private bool IsExecutable(Type type)
        {
            bool             isExecute = false;
            ExecuteAttribute attribute = Attribute.GetCustomAttribute(type, typeof(ExecuteAttribute)) as ExecuteAttribute;

            if (attribute != null)
            {
                if (attribute.ExecuteType == ExecuteType.Execute)
                {
                    isExecute = true;
                }

                return(isExecute);
            }
            else
            {
                return(isExecute);
            }
        }
        /// <summary>
        /// Get testcase list
        /// </summary>
        /// <param name="testClasses"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        public dynamic GetTestCaseList(List <string> testClasses, Assembly sender)
        {
            IList <TestCaseModel> testCaseList = new List <TestCaseModel>();

            foreach (string testClass in testClasses)
            {
                //string moduleType = TestModuleService.GetModuleType(testClass, sender);
                //ObjectId objectId = mongoRepository.GetTestModuleRepository.GetId(moduleType);
                ObjectId objectId = mongoRepository.GetTestClassRepository.GetId(testClass);
                //Get test methods
                Type type = sender.GetType(testClass);
                IEnumerable <MethodInfo> methods = type.GetMethods()
                                                   .Where(t => t.IsDefined(typeof(TestInfoAttribute), false) &&
                                                          t.IsDefined(typeof(ExecuteAttribute), false));
                foreach (MethodInfo method in methods)
                {
                    IList <Type>       attributes         = GetAvailableAttributes(method);
                    TestInfoAttribute  testAttrInfo       = null;
                    TestOrderAttribute orderAttrInfo      = null;
                    DependentAttribute dependentAttribute = null;

                    bool isExecute = false;
                    if (attributes.Count != 0)
                    {
                        foreach (Type attribute in attributes)
                        {
                            if (attribute.Name.Equals("ExecuteAttribute") ||
                                attribute.Name.Equals("Execute"))
                            {
                                ExecuteAttribute executeTestCaseAttribute = method.GetExecuteAttribute();
                                isExecute = executeTestCaseAttribute.ExecuteType == ExecuteType.Execute ? true : false;
                            }
                            else if (attribute.Name.Equals("TestInfoAttribute") ||
                                     attribute.Name.Equals("TestInfo"))
                            {
                                testAttrInfo = method.GetTestInfoAttribute();
                            }
                            else if (attribute.Name.Equals("TestOrderAttribute") ||
                                     attribute.Name.Equals("TestOrder"))
                            {
                                orderAttrInfo = method.GetTestOrderAttribute();
                            }
                            else if (attribute.Name.Equals("DependentAttribute") ||
                                     attribute.Name.Equals("Dependent"))
                            {
                                dependentAttribute = method.GetDependentAttribute();
                            }
                        }

                        testCaseList.Add(new TestCaseModel()
                        {
                            TestClass_id        = objectId,
                            TestCaseName        = method.Name,
                            TestCaseDescription = method.Name,
                            TestCaseType        = testAttrInfo.TestCaseType.ToString(),
                            //CreatedDTM = DateTime.UtcNow,
                            TestCasePriority      = testAttrInfo.Priority.ToString(),
                            TestCategory          = testAttrInfo.TestCategory.ToString(),
                            Version               = testAttrInfo.Version.ToString(),
                            DependentTestCaseName = dependentAttribute?.TestMethodName,
                            Order    = orderAttrInfo.Order,
                            IsActive = isExecute
                        });
                    }
                }
            }

            return(testCaseList);
        }