FindAssemblyContextsIn() public method

public FindAssemblyContextsIn ( Assembly assembly ) : IEnumerable
assembly System.Reflection.Assembly
return IEnumerable
    Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
    {
      MachineAssemblyTest assemblyTest;
      if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
      {
        assemblyTest = new MachineAssemblyTest(assembly.Name, assembly, frameworkVersion);
        assemblyTest.Kind = TestKinds.Assembly;

        ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata);

        string frameworkName = String.Format("Machine Specifications v{0}", frameworkVersion);
        assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
        assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
        assemblyTest.Kind = TestKinds.Assembly;

        parentTest.AddChild(assemblyTest);
        assemblyTests.Add(assembly, assemblyTest);
      }

      if (populateRecursively)
      {
        AssemblyExplorer explorer = new AssemblyExplorer();
        Assembly resolvedAssembly = assembly.Resolve(false);

        assemblyTest.AssemblyContexts = explorer.FindAssemblyContextsIn( resolvedAssembly).ToList();
        assemblyTest.GlobalCleanup = explorer.FindAssemblyWideContextCleanupsIn(resolvedAssembly).ToList();
        assemblyTest.SpecificationSupplements = explorer.FindSpecificationSupplementsIn(resolvedAssembly).ToList();
        
        explorer.FindContextsIn(resolvedAssembly)
          .Select( context => GetContextTest( context))
          .Each( test => assemblyTest.AddChild( test));
      }

      return assemblyTest;
    }
    public void Run(Assembly assembly, IEnumerable<Context> contexts)
    {
      bool hasExecutableSpecifications = contexts.Where(x => x.HasExecutableSpecifications).Any();

      var explorer = new AssemblyExplorer();
      var assemblyContexts = new List<IAssemblyContext>(explorer.FindAssemblyContextsIn(assembly));

      _listener.OnAssemblyStart(assembly.GetInfo());

      var executedAssemblyContexts = new List<IAssemblyContext>();

      try
      {
        if (hasExecutableSpecifications)
        {
          assemblyContexts.ForEach(assemblyContext =>
          {
            assemblyContext.OnAssemblyStart();
            executedAssemblyContexts.Add(assemblyContext);
          });
        }

        foreach (var context in contexts)
        {
          RunContext(context);
        }
      }
      catch (Exception err)
      {
        _listener.OnFatalError(new ExceptionResult(err));
      }
      finally
      {
        if (hasExecutableSpecifications)
        {
          try
          {
            executedAssemblyContexts.Reverse();
            executedAssemblyContexts.ForEach(assemblyContext => assemblyContext.OnAssemblyComplete());
          }
          catch (Exception err)
          {
            _listener.OnFatalError(new ExceptionResult(err));
            throw;
          }
        }
      }

      _listener.OnAssemblyEnd(assembly.GetInfo());
    }