Exemplo n.º 1
0
        /// <summary>
        /// Throws an <paramref name="exception"/> when the <paramref name="affectedMethod" /> is called.
        /// </summary>
        /// <param name="affectedMethod">The method to affect.</param>
        /// <param name="exception">The <see cref="Exception"/> that should be thrown.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="exception"/> is a null reference.</exception>
        public static Affector Throw(this IAffectedMethod affectedMethod, Exception exception)
        {
            if (exception == null)
            {
                throw new ArgumentNullException(nameof(exception));
            }

            return((Affector)affectedMethod.AddAffector(new ExceptionThrower(exception)));
        }
Exemplo n.º 2
0
        // Affectors

        /// <summary>
        /// Slows the <paramref name="affectedMethod"/> down by the given <paramref name="time"/>.
        /// </summary>
        /// <param name="affectedMethod">The method to affect.</param>
        /// <param name="time">A <see cref="TimeSpan"/> value indicating the amount of time used to slow down the call.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="time"/> equals zero or a negative amount of time.</exception>
        public static Affector SlowItDownBy(this IAffectedMethod affectedMethod, TimeSpan time)
        {
            if (time.Ticks <= 0)
            {
                // TODO Needs explanation
                throw new ArgumentOutOfRangeException(); // we can't speed up things
            }

            return((Affector)affectedMethod.AddAffector(new Delayer(time)));
        }