/// <summary> /// Registers a new step behavior or replaces the existing one with the same id with a new one. /// </summary> /// <param name="stepId">The identifier of the step to replace its implementation.</param> /// <param name="behavior">The new <see cref="Behavior{TContext}" /> to use.</param> /// <param name="description">The description of the new behavior.</param> public void RegisterOrReplace(string stepId, Type behavior, string description = null) { BehaviorTypeChecker.ThrowIfInvalid(behavior, nameof(behavior)); Guard.AgainstNullAndEmpty(nameof(stepId), stepId); EnsureWriteEnabled(stepId, nameof(Replace)); EnsureWriteEnabled(stepId, nameof(Register)); modifications.AdditionsOrReplacements.Add(RegisterOrReplaceStep.Create(stepId, behavior, description)); }
/// <summary> /// Registers a new step behavior or replaces the existing one with the same id with a new one. /// </summary> /// <param name="stepId">The identifier of the step to replace its implementation.</param> /// <param name="behavior">The new <see cref="Behavior{TContext}" /> to use.</param> /// <param name="description">The description of the new behavior.</param> public void RegisterOrReplace <T>(string stepId, T behavior, string description = null) where T : IBehavior { BehaviorTypeChecker.ThrowIfInvalid(typeof(T), nameof(behavior)); Guard.AgainstNullAndEmpty(nameof(stepId), stepId); EnsureWriteEnabled(stepId, nameof(Replace)); EnsureWriteEnabled(stepId, nameof(Register)); modifications.AdditionsOrReplacements.Add(RegisterOrReplaceStep.Create(stepId, typeof(T), description, builder => behavior)); }
/// <summary> /// Registers a new step behavior or replaces the existing one with the same id with a new one. /// </summary> /// <param name="stepId">The identifier of the step to replace its implementation.</param> /// <param name="factoryMethod">The factory method to create new instances of the behavior.</param> /// <param name="description">The description of the new behavior.</param> public void RegisterOrReplace <T>(string stepId, Func <IServiceProvider, T> factoryMethod, string description = null) where T : IBehavior { BehaviorTypeChecker.ThrowIfInvalid(typeof(T), "behavior"); Guard.AgainstNullAndEmpty(nameof(stepId), stepId); EnsureWriteEnabled(stepId, nameof(Replace)); EnsureWriteEnabled(stepId, nameof(Register)); modifications.AdditionsOrReplacements.Add(RegisterOrReplaceStep.Create(stepId, typeof(T), description, b => factoryMethod(b))); }
public void Registrations_AddOrReplace_WhenDoesNotExist() { addOrReplacements.Add(RegisterOrReplaceStep.Create("1", typeof(ReplacedBehavior), "new")); var model = coordinator.BuildPipelineModelFor <IRootContext>().ToList(); Assert.AreEqual(1, model.Count); Assert.AreEqual(typeof(ReplacedBehavior).FullName, model[0].BehaviorType.FullName); Assert.AreEqual("new", model[0].Description); }
public void ShouldAddWhenAddingOrReplacingABehaviorThatDoesntExist() { var builder = ConfigurePipelineModelBuilder.Setup() .Register(RegisterStep.Create("Root1", typeof(RootBehavior), "desc")) .RegisterOrReplace(RegisterOrReplaceStep.Create("SomeBehaviorOfParentContext", typeof(SomeBehaviorOfParentContext), "desc")) .Build(typeof(IParentContext)); var model = builder.Build(); Assert.That(model.Count, Is.EqualTo(2)); var addedBehavior = model.FirstOrDefault(x => x.StepId == "SomeBehaviorOfParentContext"); Assert.That(addedBehavior, Is.Not.Null); Assert.That(addedBehavior.BehaviorType, Is.EqualTo(typeof(SomeBehaviorOfParentContext))); }
public ConfigurePipelineModelBuilder RegisterOrReplace(RegisterOrReplaceStep registration) { registerOrReplacements.Add(registration); return(this); }