Beispiel #1
0
        /// <summary>
        /// Configures the spy to call-through to throw the given exception when
        /// the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw(Exception exception)
        {
            _spy.Behaviours.Clear();
            var behaviour = new ThrowBehaviour(exception);

            behaviour.UpdateLifetime(int.MaxValue);
            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }
Beispiel #2
0
        /// <summary>
        /// Configures the spy to call-through to throw an exception of the given type
        /// when the spied-on method is called.
        /// </summary>
        /// <returns>The spy.</returns>
        public SpyWithBehaviour Throw <TException>()
            where TException : Exception, new()
        {
            _spy.Behaviours.Clear();
            var behaviour = new ThrowBehaviour(typeof(TException));

            behaviour.UpdateLifetime(int.MaxValue);
            behaviour.ParameterChangesBeforeExecution = _parameterChanges;
            _spy.Behaviours.Enqueue(behaviour);
            return(new SpyWithBehaviour(_spy, behaviour));
        }