public void ConstructWithNullStageRunners(IList <IStageRunner> stageRunners, IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config.Should().BeNull());

            "When constructing with null stage runners"
            .x(() => e = Record.Exception(() => new RunnerConfiguration(stageRunners)));

            "Then the runner configuration constructor should throw an exception"
            .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("stageRunners"));
        }
Ejemplo n.º 2
0
        public void ConstructWithNullConfig(IRunState state, IRunnerConfiguration config, Exception e)
        {
            "Given the runner state"
            .x(() => state.Should().BeNull());

            "And null runner configuration"
            .x(() => config.Should().BeNull());

            "When constructing with null runner configuration"
            .x(() => e = Record.Exception(() => new RunState(config)));

            "Then the runner state constructor should throw an exception"
            .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("config"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a new instance of the <see cref="Runner" /> class with runner configuration and an application model.
        /// </summary>
        /// <param name="config">The configuration to be used for this runner instance.</param>
        /// <param name="model">The initialized application model state for the application being assessed, or null.</param>
        /// <param name="logger">The logger to use for tracing.</param>
        public Runner(IRunnerConfiguration config, IApplicationModel model, ILogger <Runner> logger)
        {
            // Validate and set state
            _runState = new RunState(config ?? throw new ArgumentNullException(nameof(config)), model);
            _logger   = logger ?? throw new ArgumentNullException(nameof(logger));

            // Set stage order of execution
            _stages.Enqueue(Stages.Discover);
            _stages.Enqueue(Stages.Parse);
            _stages.Enqueue(Stages.Analyze);
            _stages.Enqueue(Stages.Report);
            _stages.Enqueue(Stages.Convert);
            _stages.Enqueue(Stages.Verify);
        }
        public void SetStage(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config = new RunnerConfiguration());

            "When setting the Stages property to Assessment"
            .x(() => e = Record.Exception(() => config.Stages = Stages.Assessment));

            "Then the property set should succeed"
            .x(() => e.Should().BeNull());

            "And the Stages property should be set to Assessment"
            .x(() => config.Stages.Should().Be(Stages.Assessment));
        }
        public void DisableStage(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config = new RunnerConfiguration());

            "When disabling the Verify stage"
            .x(() => e = Record.Exception(() => config.Stages -= Stages.Verify));

            "Then the property set should succeed"
            .x(() => e.Should().BeNull());

            "And the Stages property should not have the Verify stage enabled"
            .x(() => config.Stages.Should().NotHaveFlag(Stages.Verify));
        }
        public void SetFailStageWithAllStages(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config = new RunnerConfiguration());

            "When enabling the fail fast flag for all stages"
            .x(() => e = Record.Exception(() => config.Stages |= Stages.All));

            "Then enabling all flags should succeed"
            .x(() => e.Should().BeNull());

            "And the FailStages property should have all stages enabled"
            .x(() => config.Stages.Should().HaveFlag(Stages.All));
        }
        public void EnableFailFast(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config = new RunnerConfiguration());

            "When setting the FailFast property to True"
            .x(() => e = Record.Exception(() => config.FailFast = true));

            "Then the property set should succeed"
            .x(() => e.Should().BeNull());

            "And the FailFast property should be set to True"
            .x(() => config.FailFast.Should().BeTrue());
        }
        /// <summary>
        /// Finds components by recursing one or more directories.
        /// </summary>
        /// <param name="config">The runner configuration.</param>
        /// <returns>A list of stage runners.</returns>
        public IEnumerable <IStageRunner> FindComponents(IRunnerConfiguration config)
        {
            _logger.LogInformation(InformationMessages.FindingStageRunners);

            if (_options.FindPath != null && _options.FindPath.Any())
            {
                var stageRunnerAssemblies = new List <FileInfo>();

                foreach (var path in _options.FindPath)
                {
                    // Find plugin assembly locations
                    var assemblies = _pluginFinder.FindPluginAssemblies(path.FullName, _sharedTypes);

                    // Remove duplicates (based on filename, without path), if any
                    var distinctAssemblies = assemblies.Select(a => new FileInfo(a)).GroupBy(f => f.Name).Select(f => f.First());

                    if (distinctAssemblies.Any())
                    {
                        _logger.LogInformation(InformationMessages.AssemblyCountInPath, distinctAssemblies.Count(), path.FullName);

                        foreach (var assembly in distinctAssemblies)
                        {
                            stageRunnerAssemblies.Add(assembly);
                        }
                    }
                    else
                    {
                        _logger.LogDebug(TraceMessages.StageRunnerAssembliesNotFoundInPath, path.FullName);
                    }
                }

                if (stageRunnerAssemblies.Count > 0)
                {
                    // Load stage runners into separate plugin host
                    var distinctStageRunnerAssemblies = stageRunnerAssemblies.GroupBy(f => f.Name).Select(f => f.First().FullName);
                    _pluginHost.LoadPlugins(distinctStageRunnerAssemblies, _sharedTypes);

                    return(_pluginHost.GetPlugins().Where(p => p is IStageRunner).Select(p => (IStageRunner)p));
                }
                else
                {
                    _logger.LogWarning(WarningMessages.StageRunnerAssembliesNotFound);
                }
            }

            return(Enumerable.Empty <IStageRunner>());
        }
Ejemplo n.º 9
0
        public void ConstructWithJustConfigWithSuccess(IRunState state, IRunnerConfiguration config, Exception e)
        {
            "Given the runner state"
            .x(() => state.Should().BeNull());

            "And the runner configuration"
            .x(() => config = _mockConfig.Object);

            "When constructing the runner state"
            .x(() => e = Record.Exception(() => state = new RunState(config)));

            "Then the runner state constructor should succeed"
            .x(() => e.Should().BeNull());

            "And the config should be available"
            .x(() => state.Configuration.Should().NotBeNull().And.BeSameAs(config));
        }
        public void ConstructWithSuccess(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config.Should().BeNull());

            "When constructing the runner configuration"
            .x(() => e = Record.Exception(() => config = new RunnerConfiguration()));

            "Then the runner configuration constructor should succeed"
            .x(() => e.Should().BeNull());

            "And configuration should be available"
            .x(() =>
            {
                config.Stages.Should().Be(Stages.All);
                config.StageRunners.Should().NotBeNull().And.HaveCount(0);
                config.Args.Count.Should().Be(0);
                config.FailFast.Should().BeFalse();
                config.FailStages.Should().Be(Stages.None);
            });
        }
        public void SetFailStageWithSingleStage(IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config = new RunnerConfiguration());

            "When enabling the fail fast flag for a single stage"
            .x(() => e = Record.Exception(() => config.FailStages |= Stages.Verify));

            "Then enabling the flag should succeed"
            .x(() => e.Should().BeNull());

            "And the FailStages property should have the single stage enabled"
            .x(() =>
            {
                config.FailStages.Should().HaveFlag(Stages.Verify);
                config.FailStages.Should().NotHaveFlag(Stages.Discover);
                config.FailStages.Should().NotHaveFlag(Stages.Parse);
                config.FailStages.Should().NotHaveFlag(Stages.Analyze);
                config.FailStages.Should().NotHaveFlag(Stages.Report);
                config.FailStages.Should().NotHaveFlag(Stages.Convert);
            });
        }
Ejemplo n.º 12
0
        public void ConstructWithNullModel(IRunState state, IRunnerConfiguration config, IApplicationModel model, Exception e)
        {
            "Given the runner state"
            .x(() => state.Should().BeNull());

            "And runner configuration"
            .x(() => config = _mockConfig.Object);

            "And null model state"
            .x(() => model.Should().BeNull());

            "When constructing with null model state"
            .x(() => e = Record.Exception(() => state = new RunState(config, model)));

            "Then the runner state constructor should throw an exception"
            .x(() => e.Should().BeNull());

            "And the config should be available"
            .x(() => state.Configuration.Should().NotBeNull().And.BeSameAs(config));

            "And the model should be null"
            .x(() => state.Model.Should().BeNull());
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructs a new instance of the <see cref="RunState" /> class with runner configuration and an application model.
 /// </summary>
 /// <param name="config">The configuration to be used for this runner instance.</param>
 /// <param name="model">The application model state, or null.</param>
 public RunState(IRunnerConfiguration config, IApplicationModel model)
 {
     // Validate and set state
     _config = config ?? throw new ArgumentNullException(nameof(config));
     _model  = model;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructs a new instance of the <see cref="RunState" /> class with runner configuration.
 /// </summary>
 /// <param name="config">The configuration to be used for this runner instance.</param>
 public RunState(IRunnerConfiguration config)
     : this(config, null)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructs a new instance of the <see cref="Runner" /> class with runner configuration.
 /// </summary>
 /// <param name="config">The configuration to be used for this runner instance.</param>
 /// <param name="logger">The logger to use for tracing.</param>
 public Runner(IRunnerConfiguration config, ILogger <Runner> logger)
     : this(config, null, logger)
 {
 }
        public void ConstructWithStageRunnersSuccess(IList <IStageRunner> stageRunners, IRunnerConfiguration config, Exception e)
        {
            "Given runner configuration"
            .x(() => config.Should().BeNull());

            "And a list of stage runners"
            .x(() => stageRunners = _mockStageRunners.ConvertAll(m => m.Object));

            "When constructing the runner configuration"
            .x(() => e = Record.Exception(() => config = new RunnerConfiguration(stageRunners)));

            "Then the runner configuration constructor should succeed"
            .x(() => e.Should().BeNull());

            "And configuration should be available"
            .x(() =>
            {
                config.Stages.Should().Be(Stages.All);
                config.StageRunners.Should().NotBeNull().And.HaveCount(4);
                config.Args.Count.Should().Be(0);
                config.FailFast.Should().BeFalse();
                config.FailStages.Should().Be(Stages.None);
            });
        }