Example #1
0
        public void Install(object o)
        {
            Type type = o.GetType();

            var methos = type.GetMethods();

            Type tasktype = typeof(Task);


            foreach (var method in methos)
            {
                var attr = method.GetCustomAttributes(typeof(MethodRun), true);

                foreach (var att in attr)
                {
                    MethodRun attrcmdtype = att as MethodRun;

                    if (attrcmdtype != null)
                    {
                        if ((method.ReturnType == tasktype || (Common.IsTypeOfBaseTypeIs(method.ReturnType, tasktype) && method.ReturnType.IsConstructedGenericType && method.ReturnType.GenericTypeArguments[0] == typeof(ReturnResult))))
                        {
                            if (method.GetParameters().Length > 0 && method.GetParameters()[0].ParameterType == typeof(AsyncCalls))
                            {
                                if (!ModuleDiy.ContainsKey(attrcmdtype.CmdType))
                                {
                                    AsyncMethodDef tmp = new AsyncMethodDef(method, o);
                                    ModuleDiy.Add(attrcmdtype.CmdType, tmp);
                                }
                                else
                                {
                                    AsyncMethodDef tmp = new AsyncMethodDef(method, o);
                                    ModuleDiy[attrcmdtype.CmdType] = tmp;
                                }
                            }
                        }
                        else if (method.GetParameters().Length > 0 && method.GetParameters()[0].ParameterType == typeof(CloudClient))
                        {
                            if (!ModuleDiy.ContainsKey(attrcmdtype.CmdType))
                            {
                                AsyncMethodDef tmp = new AsyncMethodDef(method, o);
                                ModuleDiy.Add(attrcmdtype.CmdType, tmp);
                            }
                            else
                            {
                                AsyncMethodDef tmp = new AsyncMethodDef(method, o);
                                ModuleDiy[attrcmdtype.CmdType] = tmp;
                            }
                        }


                        break;
                    }
                }
            }
        }
Example #2
0
        protected virtual object Call(MethodInfo method, object[] args)
        {
            var attr = method.GetCustomAttribute(typeof(MethodRun), true);

            if (attr == null)
            {
                throw new FormatException(method.Name + " Is Not MethodRun Attribute");
            }


            MethodRun run = attr as MethodRun;

            if (run != null)
            {
                int cmd = run.CmdType;

                if (method.ReturnType != typeof(void))
                {
                    if (!Common.IsTypeOfBaseTypeIs(method.ReturnType, typeof(FiberThreadAwaiterBase)))
                    {
                        if (method.ReturnType == typeof(ReturnResult))
                        {
                            return(CR(cmd, args));
                        }
                        else
                        {
                            try
                            {
                                return(CR(cmd, args)?.First?.Value(method.ReturnType));
                            }
                            catch (Exception er)
                            {
                                throw new Exception(string.Format("Return Type of {0} Error", method.ReturnType), er);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Sync Call Not Use Return Type Of ResultAwatier");
                    }
                }
                else
                {
                    CV(cmd, args);

                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// Creates the run order for the collection
        /// </summary>
        /// <returns>An object derived from <see cref="IRun" /> (a <see cref="SequenceRun" /> object that contains the order of execution</returns>
        public override IRun GetRun()
        {
            SequenceRun runs = new SequenceRun();

            // set up
            OptionalMethodRun setup = new OptionalMethodRun(typeof(SetUpAttribute), false);

            runs.Runs.Add(setup);

            // collection providers
            MethodRun provider = new MethodRun(
                typeof(ProviderAttribute),
                typeof(ArgumentFeederRunInvoker),
                false,
                true
                );

            runs.Runs.Add(provider);


            // fill
            MethodRun fill = new MethodRun(typeof(FillAttribute),
                                           false,
                                           true
                                           );

            runs.Runs.Add(fill);

            // add tester for the order
            CustomRun orderTest = new CustomRun(
                typeof(CollectionOrderTester),
                typeof(TestAttribute),
                true,       // it test
                this.order, // constructor arguments
                comparer
                );

            runs.Runs.Add(orderTest);

            // tear down
            OptionalMethodRun tearDown = new OptionalMethodRun(typeof(TearDownAttribute), false);

            runs.Runs.Add(tearDown);


            return(runs);
        }
        /// <summary>
        /// Gets the test runner class defining all the test to be run within the tagged fixture class.
        /// </summary>
        /// <returns>A <see cref="SequenceRun"/> object</returns>
        public override IRun GetRun()
        {
            SequenceRun runs = new SequenceRun();

            // set up
            OptionalMethodRun setup = new OptionalMethodRun(typeof(SetUpAttribute), false);

            runs.Runs.Add(setup);

            // create data
            MethodRun dataProvider = new MethodRun(
                typeof(DataProviderAttribute),
                typeof(ArgumentFeederRunInvoker),
                false,
                true
                );

            runs.Runs.Add(dataProvider);

            // collection providers	for collection
            MethodRun copyTo = new MethodRun(
                typeof(CopyToProviderAttribute),
                typeof(ArgumentFeederRunInvoker),
                false,
                true
                );

            runs.Runs.Add(copyTo);

            // add tester for the order
            CustomRun test = new CustomRun(
                typeof(EnumerationTester),
                typeof(TestAttribute),
                true // it is a test
                );

            runs.Runs.Add(test);


            // tear down
            OptionalMethodRun tearDown = new OptionalMethodRun(typeof(TearDownAttribute), false);

            runs.Runs.Add(tearDown);

            return(runs);
        }
Example #5
0
        /// <summary>
        /// Gets the test runner class defining all the tests to be run and the test logic to be used within the tagged fixture class.
        /// </summary>
        /// <returns>A <see cref="SequenceRun"/> object</returns>
        public override IRun GetRun()
        {
            SequenceRun runs = new SequenceRun();

            // creating parallel
            ParallelRun para = new ParallelRun();

            para.AllowEmpty = false;
            runs.Runs.Add(para);

            // method providers
            MethodRun provider = new MethodRun(
                typeof(ProviderAttribute),
                typeof(ArgumentFeederRunInvoker),
                false,
                true
                );

            para.Runs.Add(provider);

            // fixture class provider
            FixtureDecoratorRun providerFactory = new FixtureDecoratorRun(
                typeof(ProviderFixtureDecoratorPatternAttribute)
                );

            para.Runs.Add(providerFactory);

            // setup
            OptionalMethodRun setup = new OptionalMethodRun(typeof(SetUpAttribute), false);

            runs.Runs.Add(setup);

            // tests
            MethodRun test = new MethodRun(typeof(TestPatternAttribute), true, true);

            runs.Runs.Add(test);

            // tear down
            OptionalMethodRun tearDown = new OptionalMethodRun(typeof(TearDownAttribute), false);

            runs.Runs.Add(tearDown);

            return(runs);
        }
Example #6
0
        public void Install(Type packHandlerType)
        {
            var methods = packHandlerType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            Type tasktype = typeof(Task);

            foreach (var method in methods)
            {
                var attr = method.GetCustomAttributes(typeof(MethodRun), true);


                foreach (var att in attr)
                {
                    MethodRun attrcmdtype = att as MethodRun;

                    if (attrcmdtype != null)
                    {
                        if ((method.ReturnType == tasktype || (Common.IsTypeOfBaseTypeIs(method.ReturnType, tasktype) && method.ReturnType.IsConstructedGenericType && method.ReturnType.GenericTypeArguments[0] == typeof(ReturnResult))))
                        {
                            if (method.GetParameters().Length > 0 && method.GetParameters()[0].ParameterType == typeof(AsyncCalls))
                            {
                                if (!CallsMethods.ContainsKey(attrcmdtype.CmdType))
                                {
                                    AsyncStaticMethodDef tmp = new AsyncStaticMethodDef(method);
                                    CallsMethods.Add(attrcmdtype.CmdType, tmp);
                                }
                            }
                        }

                        else if (method.GetParameters().Length > 0 && method.GetParameters()[0].ParameterType == typeof(ASyncToken))
                        {
                            if (!CallsMethods.ContainsKey(attrcmdtype.CmdType))
                            {
                                AsyncStaticMethodDef tmp = new AsyncStaticMethodDef(method);
                                CallsMethods.Add(attrcmdtype.CmdType, tmp);
                            }
                        }

                        break;
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="methodRunData"></param>
        /// <param name="iColection">0. Product, 1. Keywords</param>
        public FrmReloadData(MethodRun methodRunData, int iColection)
        {
            InitializeComponent();
            this._methodRun  = methodRunData;
            this.iCollection = iColection;

            this.mongoDbAdapter = new MongoDbRaoVat();
            if (this.iCollection == 0)
            {
                this.collection = this.mongoDbAdapter.colProduct;
            }
            else if (this.iCollection == 1)
            {
                this.collection = this.mongoDbAdapter.colKeyWord;
            }
            else if (this.iCollection == 2)
            {
                this.collection = this.mongoDbAdapter.colHtml;
            }
        }
Example #8
0
        protected virtual object Call(MethodInfo method, object[] args)
        {
            var attr = method.GetCustomAttribute(typeof(MethodRun), true);

            if (attr == null)
            {
                throw new FormatException(method.Name + " Is Not MethodRun Attribute");
            }


            MethodRun run = attr as MethodRun;

            if (run != null)
            {
                int cmd = run.CmdType;

                if (method.ReturnType != typeof(void))
                {
                    if (!Common.IsTypeOfBaseTypeIs(method.ReturnType, typeof(FiberThreadAwaiterBase)))
                    {
                        throw new Exception(string.Format("Async Call Not Use Sync Mehhod"));
                    }
                    else
                    {
                        return(CR(cmd, args));
                    }
                }
                else
                {
                    CV(cmd, args);

                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }