示例#1
0
    public static void Main()
    {
        AsyncClass ao = new AsyncClass();

        AsyncFunc af = new AsyncFunc(ao.LongRunningFunc);

        AsyncCallback cb = new AsyncCallback(ao.FuncCallback);

        IAsyncResult iar = af.BeginInvoke(10, 20, 30, cb, af);

        Console.WriteLine("Inicializando processamento");

        while (!iar.IsCompleted)
        {
            ;
        }
    }
示例#2
0
        /// <summary>
        /// Method that creates the various task using the FRomAsync methods
        /// </summary>
        /// <returns></returns>
        private AsyncWork RunAPMTest()
        {
            switch (_api)
            {
            case API.APM:
                if (_sourceType == TaskType.Task)
                {
                    if (_fromAsyncType == TaskType.Task)
                    {
                        AsyncAction action = new AsyncAction(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync((Func <AsyncCallback, object, IAsyncResult>)null, action.EndInvoke, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync(action.BeginInvoke, null, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync(action.BeginInvoke, action.EndInvoke, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync(action.BeginInvoke, action.EndInvoke, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                            }
                        }

                        return(action);
                    }
                    else     // must be FromAsync type of TaskType_FromAsync.TaskT
                    {
                        AsyncFunc func = new AsyncFunc(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync <ReadOnlyCollection <object> >((Func <AsyncCallback, object, IAsyncResult>)null, func.EndInvoke, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke, null, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                            }
                        }

                        return(func);
                    }
                }
                else     // must be TaskType_FromAsync.TaskT
                {
                    AsyncFunc func = new AsyncFunc(_errorCase == ErrorCase.Throwing);

                    if (_errorCase == ErrorCase.NullBegin)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync((Func <AsyncCallback, object, IAsyncResult>) null, func.EndInvoke, null);
                    }
                    else if (_errorCase == ErrorCase.NullEnd)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke, null, null);
                    }
                    else
                    {
                        switch (_overloadChoice)
                        {
                        case OverloadChoice.None:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });

                            break;

                        case OverloadChoice.WithTaskOption:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                        }
                    }

                    return(func);
                }

            case API.APM_T:

                _expectedInputs.Add(TestInteger);

                if (_sourceType == TaskType.Task)
                {
                    if (_fromAsyncType == TaskType.Task)
                    {
                        AsyncAction <int> action1 = new AsyncAction <int>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync((Func <int, AsyncCallback, object, IAsyncResult>)null, action1.EndInvoke, TestInteger, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync(action1.BeginInvoke, null, TestInteger, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync(action1.BeginInvoke, action1.EndInvoke, TestInteger, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync(action1.BeginInvoke, action1.EndInvoke, TestInteger, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                            }
                        }

                        return(action1);
                    }
                    else     // must be FromAsync type of TaskType_FromAsync.TaskT
                    {
                        AsyncFunc <int> func1 = new AsyncFunc <int>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync <int, ReadOnlyCollection <object> >((Func <int, AsyncCallback, object, IAsyncResult>)null, func1.EndInvoke, TestInteger, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync <int, ReadOnlyCollection <object> >(func1.BeginInvoke, null, TestInteger, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync <int, ReadOnlyCollection <object> >(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync <int, ReadOnlyCollection <object> >(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                            }
                        }

                        return(func1);
                    }
                }
                else     // must be TaskType_FromAsync.TaskT
                {
                    AsyncFunc <int> func1 = new AsyncFunc <int>(_errorCase == ErrorCase.Throwing);

                    if (_errorCase == ErrorCase.NullBegin)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync((Func <int, AsyncCallback, object, IAsyncResult>) null, func1.EndInvoke, TestInteger, null);
                    }
                    else if (_errorCase == ErrorCase.NullEnd)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync(func1.BeginInvoke, null, TestInteger, null);
                    }
                    else
                    {
                        switch (_overloadChoice)
                        {
                        case OverloadChoice.None:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });

                            break;

                        case OverloadChoice.WithTaskOption:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                        }
                    }

                    return(func1);
                }


            case API.APM_T2:     //Two variables

                _expectedInputs.Add(TestInteger);
                _expectedInputs.Add(TestDouble);

                if (_sourceType == TaskType.Task)
                {
                    if (_fromAsyncType == TaskType.Task)
                    {
                        AsyncAction <int, double> action2 = new AsyncAction <int, double>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync((Func <int, double, AsyncCallback, object, IAsyncResult>)null, action2.EndInvoke, TestInteger, TestDouble, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync(action2.BeginInvoke, null, TestInteger, TestDouble, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync(action2.BeginInvoke, action2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync(action2.BeginInvoke, action2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                            }
                        }

                        return(action2);
                    }
                    else     // must be FromAsync type of TaskType_FromAsync.TaskT
                    {
                        AsyncFunc <int, double> func2 = new AsyncFunc <int, double>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync <int, double, ReadOnlyCollection <object> >((Func <int, double, AsyncCallback, object, IAsyncResult>)null, func2.EndInvoke, TestInteger, TestDouble, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync <int, double, ReadOnlyCollection <object> >(func2.BeginInvoke, null, TestInteger, TestDouble, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync <int, double, ReadOnlyCollection <object> >(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync <int, double, ReadOnlyCollection <object> >(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                            }
                        }

                        return(func2);
                    }
                }
                else     // must be TaskType_FromAsync.TaskT
                {
                    AsyncFunc <int, double> func2 = new AsyncFunc <int, double>(_errorCase == ErrorCase.Throwing);

                    if (_errorCase == ErrorCase.NullBegin)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync((Func <int, double, AsyncCallback, object, IAsyncResult>) null, func2.EndInvoke, TestInteger, TestDouble, null);
                    }
                    else if (_errorCase == ErrorCase.NullEnd)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync(func2.BeginInvoke, null, TestInteger, TestDouble, null);
                    }
                    else
                    {
                        switch (_overloadChoice)
                        {
                        case OverloadChoice.None:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });

                            break;

                        case OverloadChoice.WithTaskOption:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                        }
                    }

                    return(func2);
                }


            case API.APM_T3:

                _expectedInputs.Add(TestInteger);
                _expectedInputs.Add(TestDouble);
                _expectedInputs.Add(TestBoolean);

                if (_sourceType == TaskType.Task)
                {
                    if (_fromAsyncType == TaskType.Task)
                    {
                        AsyncAction <int, double, bool> action3 = new AsyncAction <int, double, bool>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync((Func <int, double, bool, AsyncCallback, object, IAsyncResult>)null, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync(action3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync(action3.BeginInvoke, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync(action3.BeginInvoke, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                            }
                        }

                        return(action3);
                    }
                    else     // must be FromAsync type of TaskType_FromAsync.TaskT
                    {
                        AsyncFunc <int, double, bool> func3 = new AsyncFunc <int, double, bool>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync <int, double, bool, ReadOnlyCollection <object> >((Func <int, double, bool, AsyncCallback, object, IAsyncResult>)null, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync <int, double, bool, ReadOnlyCollection <object> >(func3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync <int, double, bool, ReadOnlyCollection <object> >(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                });
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync <int, double, bool, ReadOnlyCollection <object> >(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                            }
                        }

                        return(func3);
                    }
                }
                else     // must be TaskType_FromAsync.TaskT
                {
                    AsyncFunc <int, double, bool> func3 = new AsyncFunc <int, double, bool>(_errorCase == ErrorCase.Throwing);

                    if (_errorCase == ErrorCase.NullBegin)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync((Func <int, double, bool, AsyncCallback, object, IAsyncResult>) null, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                    }
                    else if (_errorCase == ErrorCase.NullEnd)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync(func3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                    }
                    else
                    {
                        switch (_overloadChoice)
                        {
                        case OverloadChoice.None:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });

                            break;

                        case OverloadChoice.WithTaskOption:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                        }
                    }

                    return(func3);
                }

            case API.IAsyncResult:

                // put the current params into the expectedInputs
                object[] inputs = new object[] { _api, _sourceType, _errorCase };
                _expectedInputs.AddRange(inputs);

                if (_sourceType == TaskType.Task)
                {
                    if (_fromAsyncType == TaskType.Task)
                    {
                        AsyncAction action = new AsyncAction(inputs, _errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync((IAsyncResult)null, action.EndInvoke);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync(action.BeginInvoke(null, null), null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync(action.BeginInvoke(null, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                }), action.EndInvoke);
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync(action.BeginInvoke(null, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }), action.EndInvoke, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                            }
                        }

                        return(action);
                    }
                    else     // must be FromAsync type of TaskType_FromAsync.TaskT
                    {
                        AsyncFunc func = new AsyncFunc(inputs, _errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                        {
                            Task.Factory.FromAsync <ReadOnlyCollection <object> >((IAsyncResult)null, func.EndInvoke);
                        }
                        else if (_errorCase == ErrorCase.NullEnd)
                        {
                            Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke(null, null), null);
                        }
                        else
                        {
                            switch (_overloadChoice)
                            {
                            case OverloadChoice.None:
                                _task = Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke(null, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                                }), func.EndInvoke);
                                break;

                            case OverloadChoice.WithTaskOption:
                                _task = Task.Factory.FromAsync <ReadOnlyCollection <object> >(func.BeginInvoke(null, new TaskOptionAndScheduler {
                                    Scheduler = TaskScheduler.Default, Option = TestOption
                                }), func.EndInvoke, TestOption);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                            }
                        }

                        return(func);
                    }
                }
                else     // must be TaskType_FromAsync.TaskT
                {
                    AsyncFunc func = new AsyncFunc(inputs, _errorCase == ErrorCase.Throwing);

                    if (_errorCase == ErrorCase.NullBegin)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync((IAsyncResult)null, func.EndInvoke);
                    }
                    else if (_errorCase == ErrorCase.NullEnd)
                    {
                        Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke(null, null), null);
                    }
                    else
                    {
                        switch (_overloadChoice)
                        {
                        case OverloadChoice.None:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke(null, new TaskOptionAndScheduler {
                                Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None
                            }), func.EndInvoke);

                            break;

                        case OverloadChoice.WithTaskOption:
                            _task = Task <ReadOnlyCollection <object> > .Factory.FromAsync(func.BeginInvoke(null, new TaskOptionAndScheduler {
                                Scheduler = TaskScheduler.Default, Option = TestOption
                            }), func.EndInvoke, TestOption);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                        }
                    }

                    return(func);
                }


            default:
                throw new ArgumentException("unknown api to test");
            }
        }
示例#3
0
        /// <summary>
        /// Method that creates the various task using the FRomAsync methods
        /// </summary>
        /// <returns></returns>
        private AsyncWork RunAPMTest()
        {
            switch (_api)
            {
                case API.APM:
                    if (_sourceType == TaskType.Task)
                    {
                        if (_fromAsyncType == TaskType.Task)
                        {
                            AsyncAction action = new AsyncAction(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync((Func<AsyncCallback, object, IAsyncResult>)null, action.EndInvoke, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync(action.BeginInvoke, null, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync(action.BeginInvoke, action.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync(action.BeginInvoke, action.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                                }
                            }

                            return action;
                        }
                        else // must be FromAsync type of TaskType_FromAsync.TaskT
                        {
                            AsyncFunc func = new AsyncFunc(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync<ReadOnlyCollection<object>>((Func<AsyncCallback, object, IAsyncResult>)null, func.EndInvoke, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke, null, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                                }
                            }

                            return func;
                        }
                    }
                    else // must be TaskType_FromAsync.TaskT
                    {
                        AsyncFunc func = new AsyncFunc(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync((Func<AsyncCallback, object, IAsyncResult>)null, func.EndInvoke, null);
                        else if (_errorCase == ErrorCase.NullEnd)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke, null, null);
                        else
                        {
                            switch (_overloadChoice)
                            {
                                case OverloadChoice.None:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                    break;

                                case OverloadChoice.WithTaskOption:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke, func.EndInvoke, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException("invalid overloadChoice for APM");
                            }
                        }

                        return func;
                    }

                case API.APM_T:

                    _expectedInputs.Add(TestInteger);

                    if (_sourceType == TaskType.Task)
                    {
                        if (_fromAsyncType == TaskType.Task)
                        {
                            AsyncAction<int> action1 = new AsyncAction<int>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync((Func<int, AsyncCallback, object, IAsyncResult>)null, action1.EndInvoke, TestInteger, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync(action1.BeginInvoke, null, TestInteger, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync(action1.BeginInvoke, action1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync(action1.BeginInvoke, action1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                                }
                            }

                            return action1;
                        }
                        else // must be FromAsync type of TaskType_FromAsync.TaskT
                        {
                            AsyncFunc<int> func1 = new AsyncFunc<int>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync<int, ReadOnlyCollection<object>>((Func<int, AsyncCallback, object, IAsyncResult>)null, func1.EndInvoke, TestInteger, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync<int, ReadOnlyCollection<object>>(func1.BeginInvoke, null, TestInteger, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync<int, ReadOnlyCollection<object>>(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync<int, ReadOnlyCollection<object>>(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                                }
                            }

                            return func1;
                        }
                    }
                    else // must be TaskType_FromAsync.TaskT
                    {
                        AsyncFunc<int> func1 = new AsyncFunc<int>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync((Func<int, AsyncCallback, object, IAsyncResult>)null, func1.EndInvoke, TestInteger, null);
                        else if (_errorCase == ErrorCase.NullEnd)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync(func1.BeginInvoke, null, TestInteger, null);
                        else
                        {
                            switch (_overloadChoice)
                            {
                                case OverloadChoice.None:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                    break;

                                case OverloadChoice.WithTaskOption:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func1.BeginInvoke, func1.EndInvoke, TestInteger, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T");
                            }
                        }

                        return func1;
                    }


                case API.APM_T2: //Two variables

                    _expectedInputs.Add(TestInteger);
                    _expectedInputs.Add(TestDouble);

                    if (_sourceType == TaskType.Task)
                    {
                        if (_fromAsyncType == TaskType.Task)
                        {
                            AsyncAction<int, double> action2 = new AsyncAction<int, double>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync((Func<int, double, AsyncCallback, object, IAsyncResult>)null, action2.EndInvoke, TestInteger, TestDouble, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync(action2.BeginInvoke, null, TestInteger, TestDouble, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync(action2.BeginInvoke, action2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync(action2.BeginInvoke, action2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                                }
                            }

                            return action2;
                        }
                        else // must be FromAsync type of TaskType_FromAsync.TaskT
                        {
                            AsyncFunc<int, double> func2 = new AsyncFunc<int, double>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync<int, double, ReadOnlyCollection<object>>((Func<int, double, AsyncCallback, object, IAsyncResult>)null, func2.EndInvoke, TestInteger, TestDouble, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync<int, double, ReadOnlyCollection<object>>(func2.BeginInvoke, null, TestInteger, TestDouble, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync<int, double, ReadOnlyCollection<object>>(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync<int, double, ReadOnlyCollection<object>>(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                                }
                            }

                            return func2;
                        }
                    }
                    else // must be TaskType_FromAsync.TaskT
                    {
                        AsyncFunc<int, double> func2 = new AsyncFunc<int, double>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync((Func<int, double, AsyncCallback, object, IAsyncResult>)null, func2.EndInvoke, TestInteger, TestDouble, null);
                        else if (_errorCase == ErrorCase.NullEnd)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync(func2.BeginInvoke, null, TestInteger, TestDouble, null);
                        else
                        {
                            switch (_overloadChoice)
                            {
                                case OverloadChoice.None:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                    break;

                                case OverloadChoice.WithTaskOption:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func2.BeginInvoke, func2.EndInvoke, TestInteger, TestDouble, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T2");
                            }
                        }

                        return func2;
                    }


                case API.APM_T3:

                    _expectedInputs.Add(TestInteger);
                    _expectedInputs.Add(TestDouble);
                    _expectedInputs.Add(TestBoolean);

                    if (_sourceType == TaskType.Task)
                    {
                        if (_fromAsyncType == TaskType.Task)
                        {
                            AsyncAction<int, double, bool> action3 = new AsyncAction<int, double, bool>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync((Func<int, double, bool, AsyncCallback, object, IAsyncResult>)null, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync(action3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync(action3.BeginInvoke, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync(action3.BeginInvoke, action3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                                }
                            }

                            return action3;
                        }
                        else // must be FromAsync type of TaskType_FromAsync.TaskT
                        {
                            AsyncFunc<int, double, bool> func3 = new AsyncFunc<int, double, bool>(_errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync<int, double, bool, ReadOnlyCollection<object>>((Func<int, double, bool, AsyncCallback, object, IAsyncResult>)null, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync<int, double, bool, ReadOnlyCollection<object>>(func3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync<int, double, bool, ReadOnlyCollection<object>>(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync<int, double, bool, ReadOnlyCollection<object>>(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                                }
                            }

                            return func3;
                        }
                    }
                    else // must be TaskType_FromAsync.TaskT
                    {
                        AsyncFunc<int, double, bool> func3 = new AsyncFunc<int, double, bool>(_errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync((Func<int, double, bool, AsyncCallback, object, IAsyncResult>)null, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, null);
                        else if (_errorCase == ErrorCase.NullEnd)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync(func3.BeginInvoke, null, TestInteger, TestDouble, TestBoolean, null);
                        else
                        {
                            switch (_overloadChoice)
                            {
                                case OverloadChoice.None:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None });
                                    break;

                                case OverloadChoice.WithTaskOption:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func3.BeginInvoke, func3.EndInvoke, TestInteger, TestDouble, TestBoolean, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }, TestOption);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException("invalid overloadChoice for APM_T3");
                            }
                        }

                        return func3;
                    }

                case API.IAsyncResult:

                    // put the current params into the expectedInputs
                    object[] inputs = new object[] { _api, _sourceType, _errorCase };
                    _expectedInputs.AddRange(inputs);

                    if (_sourceType == TaskType.Task)
                    {
                        if (_fromAsyncType == TaskType.Task)
                        {
                            AsyncAction action = new AsyncAction(inputs, _errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync((IAsyncResult)null, action.EndInvoke);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync(action.BeginInvoke(null, null), null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync(action.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None }), action.EndInvoke);
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync(action.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }), action.EndInvoke, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                                }
                            }

                            return action;
                        }
                        else // must be FromAsync type of TaskType_FromAsync.TaskT
                        {
                            AsyncFunc func = new AsyncFunc(inputs, _errorCase == ErrorCase.Throwing);

                            if (_errorCase == ErrorCase.NullBegin)
                                Task.Factory.FromAsync<ReadOnlyCollection<object>>((IAsyncResult)null, func.EndInvoke);
                            else if (_errorCase == ErrorCase.NullEnd)
                                Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke(null, null), null);
                            else
                            {
                                switch (_overloadChoice)
                                {
                                    case OverloadChoice.None:
                                        _task = Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None }), func.EndInvoke);
                                        break;

                                    case OverloadChoice.WithTaskOption:
                                        _task = Task.Factory.FromAsync<ReadOnlyCollection<object>>(func.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }), func.EndInvoke, TestOption);
                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                                }
                            }

                            return func;
                        }
                    }
                    else // must be TaskType_FromAsync.TaskT
                    {
                        AsyncFunc func = new AsyncFunc(inputs, _errorCase == ErrorCase.Throwing);

                        if (_errorCase == ErrorCase.NullBegin)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync((IAsyncResult)null, func.EndInvoke);
                        else if (_errorCase == ErrorCase.NullEnd)
                            Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke(null, null), null);
                        else
                        {
                            switch (_overloadChoice)
                            {
                                case OverloadChoice.None:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TaskCreationOptions.None }), func.EndInvoke);
                                    break;

                                case OverloadChoice.WithTaskOption:
                                    _task = Task<ReadOnlyCollection<object>>.Factory.FromAsync(func.BeginInvoke(null, new TaskOptionAndScheduler { Scheduler = TaskScheduler.Default, Option = TestOption }), func.EndInvoke, TestOption);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException("invalid overloadChoice for IAsyncResult");
                            }
                        }

                        return func;
                    }


                default:
                    throw new ArgumentException("unknown api to test");
            }
        }