Exemplo n.º 1
0
        public void RunAfters(nspec instance)
        {
            // context-level

            if (After != null && AfterAsync != null)
            {
                throw new ArgumentException("A single context cannot have both an 'after' and an 'afterAsync' set, please pick one of the two");
            }

            After.SafeInvoke();

            AfterAsync.SafeInvoke();

            // class (method-level)

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

            AfterInstance.SafeInvoke(instance);

            AfterInstanceAsync.SafeInvoke(instance);

            // parent chain

            RecurseAncestors(c => c.RunAfters(instance));
        }
Exemplo n.º 2
0
        public void RunAfters(nspec instance)
        {
            After.SafeInvoke();

            AfterInstance.SafeInvoke(instance);

            RecurseAncestors(c => c.RunAfters(instance));
        }
Exemplo n.º 3
0
 public static void AfterInstance <TTarget>(AfterInstance <TTarget> action)
 {
     if (action == null)
     {
         throw new Exception("cannot set nul value of action!");
     }
     DefaultAfterInstanceSystem[typeof(TTarget)] = (obj, parent) =>
     {
         action((TTarget)obj, parent);
     };
 }
Exemplo n.º 4
0
        public void RunAfters(nspec instance)
        {
            // context-level

            if (After != null && AfterAsync != null)
            {
                throw new AsyncMismatchException(
                          "A single context cannot set both an 'after' and an 'afterAsync', please pick one of the two");
            }

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

            After.SafeInvoke();

            AfterAsync.SafeInvoke();

            // class (method-level)

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

            AfterInstance.SafeInvoke(instance);

            AfterInstanceAsync.SafeInvoke(instance);

            // parent chain

            RecurseAncestors(c => c.RunAfters(instance));
        }