public async Task It_Creates_From_Action() { var isExecuted = false; var factory = new DynamicCommandBuilderFactory(); var command = factory.CreateFromAction(DefaultCommandName, () => isExecuted = true).Build(); await command.Execute(); isExecuted.Should().BeTrue(); }
public async Task It_Creates_From_Action_T() { var receivedParameter = default(TestParameter); var factory = new DynamicCommandBuilderFactory(); var command = factory.CreateFromAction <TestParameter>(DefaultCommandName, p => receivedParameter = p).Build(); var parameter = new TestParameter(); await command.Execute(parameter); receivedParameter.Should().Be(parameter); }
public async Task It_Decorates_Using_Global() { var decoratorCalled = false; var factory = new DynamicCommandBuilderFactory(Configure); var command = factory.CreateFromAction(DefaultCommandName, () => { }).Build(); await command.Execute(); decoratorCalled.Should().BeTrue(); IDynamicCommandBuilder Configure(IDynamicCommandBuilder builder) { decoratorCalled = true; return(builder); } }
public async Task It_Decorates_Using_Local() { var testString = ""; var s1 = new TestStrategy(() => testString += "1"); var s2 = new TestStrategy(() => testString += "2"); var s3 = new TestStrategy(() => testString += "3"); var factory = new DynamicCommandBuilderFactory(); var command = factory.CreateFromAction(DefaultCommandName, () => { }) .WithStrategy(s1) .WithStrategy(s2) .WithStrategy(s3) .Build(); await command.Execute(); testString.Should().Be("123"); }
public async Task It_applies_strategies_in_order2() { var testString = ""; var s1 = new TestStrategy(() => testString += "1"); var s2 = new TestStrategy(() => testString += "2"); var s3 = new TestStrategy(() => testString += "3"); var factory = new DynamicCommandBuilderFactory(b => b .WithStrategy(s2) ); var command = factory.CreateFromAction(DefaultCommandName, () => { }) .WithStrategy(s3) .WithStrategy(s1, wrapExisting: true) .Build(); await command.Execute(); testString.Should().Be("123"); }