Ejemplo n.º 1
0
        protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement);

            if (assembly == null)
            {
                return;
            }

            try
            {
                MbUnit2TestExplorerEngine engine;
                if (!assemblyTestExplorerEngines.TryGetValue(assembly, out engine))
                {
                    Assembly loadedAssembly = assembly.Resolve(false);

                    if (Reflector.IsUnresolved(loadedAssembly))
                    {
                        engine = new MbUnit2ReflectiveTestExplorerEngine(TestModel, assembly);
                    }
                    else
                    {
                        engine = new MbUnit2NativeTestExplorerEngine(TestModel, loadedAssembly);
                    }

                    assemblyTestExplorerEngines.Add(assembly, engine);

                    bool skipChildren = !(codeElement is IAssemblyInfo);
                    engine.ExploreAssembly(skipChildren, unresolvedDependencies);

                    for (int i = 0; i < unresolvedDependencies.Count; i++)
                    {
                        foreach (var entry in assemblyTestExplorerEngines)
                        {
                            if (entry.Key.FullName == unresolvedDependencies[i].Value)
                            {
                                unresolvedDependencies[i].Key.AddDependency(entry.Value.GetAssemblyTest());
                                unresolvedDependencies.RemoveAt(i--);
                                break;
                            }
                        }
                    }
                }

                ITypeInfo type = ReflectionUtils.GetType(codeElement);
                if (type != null)
                {
                    engine.ExploreType(type);
                }
            }
            catch (Exception ex)
            {
                TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly,
                                                       "An exception was thrown while exploring an MbUnit v2 test assembly.", ex));
            }
        }
Ejemplo n.º 2
0
        protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement)
        {
            IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement);
            if (assembly == null)
                return;

            try
            {
                MbUnit2TestExplorerEngine engine;
                if (! assemblyTestExplorerEngines.TryGetValue(assembly, out engine))
                {
                    Assembly loadedAssembly = assembly.Resolve(false);

                    if (Reflector.IsUnresolved(loadedAssembly))
                        engine = new MbUnit2ReflectiveTestExplorerEngine(TestModel, assembly);
                    else
                        engine = new MbUnit2NativeTestExplorerEngine(TestModel, loadedAssembly);

                    assemblyTestExplorerEngines.Add(assembly, engine);

                    bool skipChildren = !(codeElement is IAssemblyInfo);
                    engine.ExploreAssembly(skipChildren, unresolvedDependencies);

                    for (int i = 0; i < unresolvedDependencies.Count; i++)
                    {
                        foreach (var entry in assemblyTestExplorerEngines)
                        {
                            if (entry.Key.FullName == unresolvedDependencies[i].Value)
                            {
                                unresolvedDependencies[i].Key.AddDependency(entry.Value.GetAssemblyTest());
                                unresolvedDependencies.RemoveAt(i--);
                                break;
                            }
                        }
                    }
                }

                ITypeInfo type = ReflectionUtils.GetType(codeElement);
                if (type != null)
                {
                    engine.ExploreType(type);
                }
            }
            catch (Exception ex)
            {
                TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly,
                    "An exception was thrown while exploring an MbUnit v2 test assembly.", ex));
            }
        }