コード例 #1
0
ファイル: Context.cs プロジェクト: devsaurabh/NSpec
        public void RunActs(nspec instance)
        {
            // parent chain

            RecurseAncestors(c => c.RunActs(instance));

            // class (method-level)

            if (ActInstance != null && ActInstanceAsync != null)
            {
                throw new ArgumentException("A single class cannot have both a sync and an async class-level 'act_each' set, please pick one of the two");
            }

            ActInstance.SafeInvoke(instance);

            ActInstanceAsync.SafeInvoke(instance);

            // context-level

            if (Act != null && ActAsync != null)
            {
                throw new ArgumentException("A single context cannot have both an 'act' and an 'actAsync' set, please pick one of the two");
            }

            Act.SafeInvoke();

            ActAsync.SafeInvoke();
        }
コード例 #2
0
ファイル: Context.cs プロジェクト: qipa/NSpec
        public void RunActs(nspec instance)
        {
            // parent chain

            RecurseAncestors(c => c.RunActs(instance));

            // class (method-level)

            if (ActInstance != null && ActInstanceAsync != null)
            {
                throw new AsyncMismatchException(
                          "A spec class with all its ancestors cannot set both sync and async class-level 'act_each' hooks, they should either be all sync or all async");
            }

            ActInstance.SafeInvoke(instance);

            ActInstanceAsync.SafeInvoke(instance);

            // context-level

            if (Act != null && ActAsync != null)
            {
                throw new AsyncMismatchException(
                          "A single context cannot set both an 'act' and an 'actAsync', please pick one of the two");
            }

            if (Act != null && Act.IsAsync())
            {
                throw new AsyncMismatchException(
                          "'act' cannot be set to an async delegate, please use 'actAsync' instead");
            }

            Act.SafeInvoke();

            ActAsync.SafeInvoke();
        }
コード例 #3
0
        public void Add <TEvent>(Act <TEvent> act) where TEvent : Event
        {
            ActAsync <TEvent> asyncAct = (e, context) => Task.Run(() => act(e, context));

            Add(asyncAct);
        }