public void RunBefores(nspec instance) { // parent chain RecurseAncestors(c => c.RunBefores(instance)); // class (method-level) if (BeforeInstance != null && BeforeInstanceAsync != null) { throw new ArgumentException("A single class cannot have both a sync and an async class-level 'before_each' set, please pick one of the two"); } BeforeInstance.SafeInvoke(instance); BeforeInstanceAsync.SafeInvoke(instance); // context-level if (Before != null && BeforeAsync != null) { throw new ArgumentException("A single context cannot have both a 'before' and an 'beforeAsync' set, please pick one of the two"); } Before.SafeInvoke(); BeforeAsync.SafeInvoke(); }
public void RunBefores(nspec instance) { // parent chain RecurseAncestors(c => c.RunBefores(instance)); // class (method-level) if (BeforeInstance != null && BeforeInstanceAsync != null) { throw new AsyncMismatchException( "A spec class with all its ancestors cannot set both sync and async " + "class-level 'before_each' hooks, they should either be all sync or all async"); } BeforeInstance.SafeInvoke(instance); BeforeInstanceAsync.SafeInvoke(instance); // context-level if (Before != null && BeforeAsync != null) { throw new AsyncMismatchException( "A single context cannot set both a 'before' and an 'beforeAsync', please pick one of the two"); } if (Before != null && Before.IsAsync()) { throw new AsyncMismatchException( "'before' cannot be set to an async delegate, please use 'beforeAsync' instead"); } Before.SafeInvoke(); BeforeAsync.SafeInvoke(); }