コード例 #1
0
ファイル: UnitTestSupport.cs プロジェクト: pusp/o2platform
 public static IEnumerable<ILoadedXRule> getXRulesWithUnitTests_FromAssemblies(IEnumerable<string> assembliesWithUnitTests)
 {
     var xRuleSource = "from Unit Tests";
     var xLoadedXRules = new List<ILoadedXRule>();
     try
     {                
         foreach (var file in assembliesWithUnitTests)
         {
             var reflectionAssembly = PublicDI.reflection.getAssembly(file);     // we will need the reflection assembly object below
             if (reflectionAssembly != null)
             {
                 var nUnit_testFixtures = CecilCodeSearch.getTypesWithAttribute(file, nUnit_ClassAttribute);
                 foreach (var nUnit_testFixture in nUnit_testFixtures)
                 {
                     var reflectionType = PublicDI.reflection.getType(reflectionAssembly, nUnit_testFixture.FullName);
                     if (reflectionType != null)
                     {
                         var nUnit_tests = CecilCodeSearch.getMethodsWithAttribute(nUnit_testFixture,nUnit_MethodAttribute);
                         if (nUnit_tests.Count > 0)
                         {
                             var xRule = new KXRule {Name = nUnit_testFixture.Name};
                             var loadedXRule = new KLoadedXRule(xRule,xRuleSource );
                             foreach (var nUnit_test in nUnit_tests)
                             {
                                 var methodInfo = CecilConvert.getMethodInfoFromMethodDefinition(reflectionType, nUnit_test);
                                 if (methodInfo != null)
                                 {
                                     var xRuleAttribute = new XRuleAttribute {Name = nUnit_test.Name};
                                     loadedXRule.methods.Add(xRuleAttribute, methodInfo);
                                 }
                                 //    loadedXRule.methods.Add(xRuleAttribute,test.);
                             }
                             xLoadedXRules.Add(loadedXRule);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         PublicDI.log.error("In getXRulesWithUnitTests_FromAssemblies: {0}", ex.Message);
     }
     return xLoadedXRules;
 }
コード例 #2
0
        private void executeXRuleMethod(ILoadedXRule xLoadedRule, XRuleAttribute attribute)
        {
            if (xLoadedRule.methods.ContainsKey(attribute))
            {
                //var _loadedArtifacts = getLoadedArtifacts();

                var methodToExecute = xLoadedRule.methods[attribute];
                var methodParameters = new List<Object>();
                foreach(var parameter in methodToExecute.GetParameters())
                    if (loadedArtifacts.ContainsKey(parameter.ParameterType))
                        methodParameters.Add(loadedArtifacts[parameter.ParameterType]);
                DI.reflection.invokeASync(xLoadedRule.XRule, methodToExecute, methodParameters.ToArray(), onXRuleExecutionCompletion);
            }
        }