Ejemplo n.º 1
0
        public async Task GeneralExecutionTest()
        {
            bool executed = false;

            void Nothing()
            {
            }

            Task NothingAsync() => Task.CompletedTask;
            void Execute() => executed = true;

            Task ExecuteAsync()
            {
                executed = true;
                return(Task.CompletedTask);
            }

            int[] choice = { Normal, Async };
            IEnumerable <IEnumerable <int> > options = choice.Select(x => new[] { x });

            ProgressOptions  progressOptions  = ops => Generator.GenerateOptions(ops, choice);
            ProgressSequence progressSequence = (gwts, option, _, isLast) =>
            {
                switch (option)
                {
                case Normal:
                    gwts = isLast
                            ? gwts.SelectMany(x => Generator.GenerateCalls(x, Execute))
                            : gwts.SelectMany(x => Generator.GenerateCalls(x, Nothing));
                    break;

                case Async:
                    gwts = isLast
                            ? gwts.SelectMany(x => Generator.GenerateCalls(x, ExecuteAsync))
                            : gwts.SelectMany(x => Generator.GenerateCalls(x, NothingAsync));
                    break;
                }
                return(gwts);
            };
            ExecuteCheck executeCheck = async seq =>
            {
                executed = false;
                var cont = seq();
                if (cont is IAsyncContinuation asyncCont)
                {
                    await asyncCont;
                }
                executed.Should().BeTrue();
            };

            await Test(options, progressOptions, progressSequence, executeCheck);
        }
Ejemplo n.º 2
0
        public async Task SequentialExecutionTest()
        {
            List <int> numbers = new List <int>();

            Action DoCount(int x) => () => numbers.Add(x);

            AsyncAction DoCountAsync(int x) => () =>
            {
                numbers.Add(x);
                return(Task.CompletedTask);
            };

            var              choice           = new[] { Count, CountAsync };
            var              options          = choice.Select(x => new[] { x });
            ProgressOptions  progressOptions  = ops => Generator.GenerateOptions(ops, choice);
            ProgressSequence progressSequence = (gwts, option, i, _) =>
            {
                switch (option)
                {
                case Count:
                    gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCount(i)));
                    break;

                case CountAsync:
                    gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCountAsync(i)));
                    break;
                }
                return(gwts);
            };
            ExecuteCheck executeCheck = async seq =>
            {
                numbers.Clear();
                var cont = seq();
                if (cont is IAsyncContinuation asyncCont)
                {
                    await asyncCont;
                }
                numbers.Should().BeInAscendingOrder();
            };

            await Test(options, progressOptions, progressSequence, executeCheck);
        }
Ejemplo n.º 3
0
        private async Task TestSequence(Func <GivenWhenThen> start, int level, int[] option, ProgressSequence progress, ExecuteCheck executeCheck)
        {
            IEnumerable <Func <object> > gwts = new Func <object>[] { start };

            for (int i = 0; i < level; i += 1)
            {
                gwts = progress(gwts, option[i], i, false);
            }
            gwts = progress(gwts, option[level], level, true);

            foreach (var e in gwts)
            {
                await executeCheck(e);
            }
        }
Ejemplo n.º 4
0
        public async Task Test(IEnumerable <IEnumerable <int> > initialOptions, ProgressOptions progressOptions, ProgressSequence progressSequence, ExecuteCheck executeCheck)
        {
            var options = initialOptions;

            for (int level = 0; level < 7; level += 1)
            {
                var ops = options.Select(x => x.ToArray()).ToList();
                foreach (var option in ops)
                {
                    Func <GivenWhenThen> start = () => this;
                    await TestSequence(start, level, option, progressSequence, executeCheck);
                }
                options = progressOptions(ops);
            }
        }