internal static void AddConstructor <T>(this CodeTypeDeclaration @class, T stages) where T : IPipelineStageList { if (@class == null) { throw new ArgumentNullException(nameof(@class)); } if (stages == null) { throw new ArgumentNullException(nameof(stages)); } var constructor = new CodeConstructor { Name = @class.Name, Attributes = MemberAttributes.Public }; var compId = 0; foreach (var stage in ((StageList)(IPipelineStageList)stages).Where(stage => stage.Components.Count > 0)) { constructor.AddStage(stage); foreach (var component in (ComponentList)stage.Components) { var componentDeclaration = constructor.DeclareComponent(component, $"comp{compId++}"); constructor.ConfigureComponent(componentDeclaration, component.PropertyContents.Select(pc => new PropertyContents(pc.Name, pc.Value))); constructor.AddComponent(componentDeclaration); } } @class.Members.Add(constructor); }
public void AddStageThrowsForUnsupportedStageExecutionMethod() { var pipelinePolicy = new PipelinePolicy { Stages = { new StagePolicy { StageIdGuid = StageCategory.Any.Id.ToString(), ExecutionMethod = ExecMethod.None } } }; var stage = new Stage(StageCategory.Any.Id, pipelinePolicy) { StagePolicy = { ExecutionMethod = ExecMethod.None } }; var sut = new CodeConstructor(); Action(() => sut.AddStage(stage)) .Should().Throw <ArgumentOutOfRangeException>() .WithMessage("Stage 'Any' Execution Method is not supported; only All and FirstMatch are supported.*"); }