public async Task Should_execute_steps_in_the_same_order_as_they_were_added()
        {
            var count    = 1;
            var sequence = _factory.CreateSequence(builder =>
            {
                builder
                .AddStep(async(context, next) =>
                {
                    Assert.AreEqual(1, count++);

                    await next(context);
                })
                .AddStep(async(context, next) =>
                {
                    Assert.AreEqual(2, count++);

                    await next(context);
                })
                .AddStep(async(context, next) =>
                {
                    Assert.AreEqual(3, count++);

                    await next(context);
                });
            });

            await sequence.ExecuteAsync();
        }
Пример #2
0
        public async Task Should_not_swallow_unhandle_exception_in_async_execution_step()
        {
            var sequence = _factory.CreateSequence(builder =>
            {
                builder.AddStep(async(context, next) =>
                {
                    await Task.FromResult(0);

                    throw new InvalidOperationException();
                });
            });

            Assert.ThrowsAsync <InvalidOperationException>(async() => await sequence.ExecuteAsync());
        }
Пример #3
0
        public async Task Should_be_able_to_read_object_that_set_in_previous_step_from_context()
        {
            var sequence = _factory.CreateSequence(builder =>
            {
                builder
                .AddStep <TestSteps.AddArgumentsToContextStep>("1", "step 1")
                .AddStep(async(context, next) =>
                {
                    Assert.AreEqual(context.Data["1"], "step 1");
                    await next(context);
                });
                var obj = new object();
                builder.AddStep <TestSteps.AddArgumentsToContextStep>("2", obj);
                builder.AddStep(async(context, next) =>
                {
                    Assert.AreEqual(context.Data["1"], "step 1");
                    Assert.AreSame(context.Data["2"], obj);

                    await next(context);
                });
            });

            await sequence.ExecuteAsync();
        }
Пример #4
0
        public ISequence Build()
        {
            CodeContract.PreCondition <ArgumentException>(_sequenceTypeSet);
            CodeContract.PreCondition <ArgumentException>(_tasksSet);
            CodeContract.PreCondition <ArgumentException>(_sequenceFailActionSet);

            var recovery = _sequenceRecoverySet
                ? new RecoveryOptionsDto(true, _recoveryFunc)
                : new RecoveryOptionsDto();

            return(_sequenceFactory.CreateSequence(
                       _sequenceType,
                       _tasks,
                       recovery,
                       _failAction,
                       _runCount
                       ));
        }