Ejemplo n.º 1
0
        /// <summary>
        /// Executes the specified action when a matching call is being made. This overload can also be used to fake calls with arguments when they don't need to be accessed.
        /// </summary>
        /// <typeparam name="TInterface">The type of configuration interface to return.</typeparam>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action" /> to invoke.</param>
        /// <returns>The fake object.</returns>
        public static TInterface Invokes <TInterface>(this ICallbackConfiguration <TInterface> configuration, Action actionToInvoke)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(actionToInvoke, nameof(actionToInvoke));

            return(configuration.Invokes(call => actionToInvoke()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the specified action when a matching call is being made.
        /// </summary>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action{T1,T2,T3,T4}"/> to invoke</param>
        /// <typeparam name="T1">Type of the first argument of the faked method call</typeparam>
        /// <typeparam name="T2">Type of the second argument of the faked method call</typeparam>
        /// <typeparam name="T3">Type of the third argument of the faked method call</typeparam>
        /// <typeparam name="T4">Type of the fourth argument of the faked method call</typeparam>
        /// <typeparam name="TFake">The type of fake object.</typeparam>
        /// <exception cref="FakeConfigurationException"> when the signatures of the faked method and the <paramref name="actionToInvoke"/> do not match</exception>
        public static TFake Invokes <TFake, T1, T2, T3, T4>(this ICallbackConfiguration <TFake> configuration, Action <T1, T2, T3, T4> actionToInvoke)
        {
            return(configuration.Invokes(call =>
            {
                AssertThatSignaturesAreEqual(call.Method, actionToInvoke.Method, NameOfInvokesFeature);

                actionToInvoke(call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2), call.GetArgument <T4>(3));
            }));
        }
        /// <summary>
        /// Executes the specified action when a matching call is being made.
        /// </summary>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action{T1,T2,T3}"/> to invoke.</param>
        /// <typeparam name="TFake">The type of fake object.</typeparam>
        /// <typeparam name="T1">Type of the first argument of the faked method call.</typeparam>
        /// <typeparam name="T2">Type of the second argument of the faked method call.</typeparam>
        /// <typeparam name="T3">Type of the third argument of the faked method call.</typeparam>
        /// <exception cref="FakeConfigurationException">The signatures of the faked method and the <paramref name="actionToInvoke"/> do not match.</exception>
        /// <returns>The fake object.</returns>
        public static TFake Invokes <TFake, T1, T2, T3>(this ICallbackConfiguration <TFake> configuration, Action <T1, T2, T3> actionToInvoke)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.Invokes(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, actionToInvoke.Method, NameOfInvokesFeature);

                actionToInvoke(call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2));
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the specified action when a matching call is being made.
        /// </summary>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action{T1,T2}"/> to invoke.</param>
        /// <typeparam name="TFake">The type of fake object.</typeparam>
        /// <typeparam name="T1">Type of the first argument of the faked method call.</typeparam>
        /// <typeparam name="T2">Type of the second argument of the faked method call.</typeparam>
        /// <exception cref="FakeConfigurationException">The signatures of the faked method and the <paramref name="actionToInvoke"/> do not match.</exception>
        /// <returns>The fake object.</returns>
        public static TFake Invokes <TFake, T1, T2>(this ICallbackConfiguration <TFake> configuration, Action <T1, T2> actionToInvoke)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.Invokes(call =>
            {
                AssertThatSignaturesAreEqual(call.Method, actionToInvoke.Method, NameOfInvokesFeature);

                actionToInvoke(call.GetArgument <T1>(0), call.GetArgument <T2>(1));
            }));
        }
        /// <summary>
        /// Executes the specified action when a matching call is being made.
        /// </summary>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action{T1, T2}"/> to invoke.</param>
        /// <typeparam name="TInterface">The type of configuration interface to return.</typeparam>
        /// <typeparam name="T1">The type of the first argument of the faked method call.</typeparam>
        /// <typeparam name="T2">The type of the second argument of the faked method call.</typeparam>
        /// <exception cref="FakeConfigurationException">The signatures of the faked method and the <paramref name="actionToInvoke"/> do not match.</exception>
        /// <returns>The configuration object.</returns>
        public static TInterface Invokes <TInterface, T1, T2>(this ICallbackConfiguration <TInterface> configuration, Action <T1, T2> actionToInvoke)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(actionToInvoke, nameof(actionToInvoke));

            return(configuration.Invokes(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, actionToInvoke.GetMethodInfo(), NameOfInvokesFeature);

                actionToInvoke(call.GetArgument <T1>(0), call.GetArgument <T2>(1));
            }));
        }
        /// <summary>
        /// Executes the specified action when a matching call is being made. This overload can also be used to fake calls with arguments when they don't need to be accessed.
        /// </summary>
        /// <typeparam name="TFake">The type of fake object.</typeparam>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action" /> to invoke.</param>
        /// <returns>The fake object.</returns>
        public static TFake Invokes <TFake>(this ICallbackConfiguration <TFake> configuration, Action actionToInvoke)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.Invokes(call => actionToInvoke()));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Executes the specified action when a matching call is being made. This overload can also be used to fake calls with arguments when they don't need to be accessed.
 /// </summary>
 /// <param name="configuration">The configuration that is extended.</param>
 /// <param name="actionToInvoke">The <see cref="Action"/> to invoke</param>
 /// <typeparam name="TFake">The type of fake object.</typeparam>
 public static TFake Invokes <TFake>(this ICallbackConfiguration <TFake> configuration, Action actionToInvoke)
 {
     return(configuration.Invokes(call => actionToInvoke()));
 }