Represents an assembly with Machine Specifications
Adapted from the MS Test Adaptor of the Gallio Project
Наследование: MachineGallioTest
    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;
    }
    TestResult RunContextTest(MachineAssemblyTest assemblyTest, MachineContextTest contextTest, ITestCommand command, TestStep parentTestStep)
    {
      ITestContext testContext = command.StartPrimaryChildStep(parentTestStep);

      GallioRunListener listener = new GallioRunListener(_listener, _progressMonitor, testContext, command.Children);

      IContextRunner runner = ContextRunnerFactory.GetContextRunnerFor(contextTest.Context);
      runner.Run(contextTest.Context, listener, _options, assemblyTest.GlobalCleanup, assemblyTest.SpecificationSupplements);

      return testContext.FinishStep(listener.Outcome, null);
    }
    TestResult RunAssembly(MachineAssemblyTest assemblyTest, ITestCommand command, TestStep parentTestStep)
    {
      ITestContext assemblyContext = command.StartPrimaryChildStep(parentTestStep);

      AssemblyInfo assemblyInfo = new AssemblyInfo(assemblyTest.Name, assemblyTest.AssemblyFilePath);
      TestOutcome outcome = TestOutcome.Passed;

      _listener.OnAssemblyStart(assemblyInfo);
      assemblyTest.AssemblyContexts.Each(context => context.OnAssemblyStart());
      
      foreach (ITestCommand contextCommand in command.Children)
      {
        MachineContextTest contextTest = contextCommand.Test as MachineContextTest;
        if (contextTest == null) 
          continue;

        var contextResult = RunContextTest( assemblyTest, contextTest, contextCommand, assemblyContext.TestStep);
        outcome = outcome.CombineWith(contextResult.Outcome);
        assemblyContext.SetInterimOutcome(outcome);
      }

      assemblyTest.AssemblyContexts.Reverse().Each(context => context.OnAssemblyComplete());
      _listener.OnAssemblyEnd(assemblyInfo);

      return assemblyContext.FinishStep( outcome, null);
    }