ReturnsLazily <TReturnType, T1>(this IReturnValueConfiguration <TReturnType> configuration, Func <T1, TReturnType> valueProducer)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.ReturnsLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, valueProducer.Method, NameOfReturnsLazilyFeature);

                return valueProducer(call.GetArgument <T1>(0));
            }));
        }
예제 #2
0
        /// <summary>
        /// Throws the specified exception when the currently configured
        /// call gets called.
        /// </summary>
        /// <param name="configuration">The configuration to use.</param>
        /// <param name="exceptionFactory">A function that returns the exception to throw when invoked.</param>
        /// <typeparam name="TInterface">The type of configuration interface to return.</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>
        /// <returns>Configuration object.</returns>
        /// <exception cref="FakeConfigurationException">The signatures of the faked method and the <paramref name="exceptionFactory"/> do not match.</exception>
        internal static IAfterCallConfiguredConfiguration <TInterface> Throws <TInterface, T1, T2>(this IExceptionThrowerConfiguration <TInterface> configuration, Func <T1, T2, Exception> exceptionFactory)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.Throws(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, exceptionFactory.GetMethodInfo(), NameOfThrowsFeature);

                return exceptionFactory(call.GetArgument <T1>(0), call.GetArgument <T2>(1));
            }));
        }
        ReturnsLazily <TReturnType, T1, T2, T3, T4>(this IReturnValueConfiguration <Task <TReturnType> > configuration, Func <T1, T2, T3, T4, TReturnType> valueProducer)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.ReturnsLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, valueProducer.Method, NameOfReturnsLazilyFeature);

                return TaskHelper.FromResult(valueProducer(call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2), call.GetArgument <T4>(3)));
            }));
        }
        /// <summary>
        /// Throws the specified exception when the currently configured
        /// call gets called.
        /// </summary>
        /// <param name="configuration">The configuration to use.</param>
        /// <param name="exceptionFactory">A function that returns the exception to throw when invoked.</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>
        /// <returns>Configuration object.</returns>
        /// <exception cref="FakeConfigurationException">The signatures of the faked method and the <paramref name="exceptionFactory"/> do not match.</exception>
        public static IAfterCallSpecifiedConfiguration Throws <T1, T2, T3>(this IExceptionThrowerConfiguration configuration, Func <T1, T2, T3, Exception> exceptionFactory)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.Throws(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, exceptionFactory.Method, NameOfThrowsFeature);

                return exceptionFactory(call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2));
            }));
        }
예제 #5
0
        ReturnsLazily <TReturnType, T1, T2, T3, T4, T5, T6, T7, T8>(this IReturnValueConfiguration <TReturnType> configuration, Func <T1, T2, T3, T4, T5, T6, T7, T8, TReturnType> valueProducer)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.ReturnsLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, valueProducer.GetMethodInfo(), NameOfReturnsLazilyFeature);

                return valueProducer(call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2), call.GetArgument <T4>(3), call.GetArgument <T5>(4), call.GetArgument <T6>(5), call.GetArgument <T7>(6), call.GetArgument <T8>(7));
            }));
        }
        /// <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));
            }));
        }
예제 #7
0
        ReturnsLazily <TReturnType, T1>(this IReturnValueConfiguration <Task <TReturnType> > configuration, Func <T1, TReturnType> valueProducer)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(valueProducer, nameof(valueProducer));

            return(configuration.ReturnsLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(call.Method, valueProducer.GetMethodInfo(), NameOfReturnsLazilyFeature);

                return TaskHelper.FromResult(valueProducer(call.GetArgument <T1>(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="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));
            }));
        }
예제 #9
0
        AssignsOutAndRefParametersLazily <T1, T2>(
            this IOutAndRefParametersConfiguration configuration, Func <T1, T2, object[]> valueProducer)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.AssignsOutAndRefParametersLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(
                    call.Method, valueProducer.GetMethodInfo(), NameOfOutRefLazilyFeature);

                return valueProducer(call.GetArgument <T1>(0), call.GetArgument <T2>(1));
            }));
        }
예제 #10
0
        /// <summary>
        /// Specifies a function used to produce output values for out and ref parameters.
        /// The values should appear in the same order as the out and ref parameters in the configured call.
        /// Any non out and ref parameters are ignored.
        /// The function will be called each time this call is made and can return different values.
        /// </summary>
        /// <typeparam name="T1">Type of the first argument of the faked method call.</typeparam>
        /// <param name="configuration">The configuration to extend.</param>
        /// <param name="valueProducer">A function that produces the output values.</param>
        /// <returns>A configuration object.</returns>
        /// <exception cref="FakeConfigurationException">
        /// The signatures of the faked method and the <paramref name="valueProducer"/> do not match.
        /// </exception>
        public static IAfterCallSpecifiedConfiguration AssignsOutAndRefParametersLazily <T1>(
            this IOutAndRefParametersConfiguration configuration, Func <T1, object[]> valueProducer)
        {
            Guard.AgainstNull(configuration, "configuration");

            return(configuration.AssignsOutAndRefParametersLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(
                    call.Method, valueProducer.Method, NameOfOutRefLazilyFeature);

                return valueProducer(call.GetArgument <T1>(0));
            }));
        }
        /// <summary>
        /// Specifies a function used to produce output values for out and ref parameters.
        /// The values should appear in the same order as the out and ref parameters in the configured call.
        /// Any non out and ref parameters are ignored.
        /// The function will be called each time this call is made and can return different values.
        /// </summary>
        /// <typeparam name="TInterface">The type of configuration interface to return.</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>
        /// <typeparam name="T4">Type of the fourth argument of the faked method call.</typeparam>
        /// <param name="configuration">The configuration to extend.</param>
        /// <param name="valueProducer">A function that produces the output values.</param>
        /// <returns>A configuration object.</returns>
        /// <exception cref="FakeConfigurationException">
        /// The signatures of the faked method and the <paramref name="valueProducer"/> do not match.
        /// </exception>
        internal static IAfterCallConfiguredConfiguration <TInterface> AssignsOutAndRefParametersLazily <TInterface, T1, T2, T3, T4>(
            this IOutAndRefParametersConfiguration <TInterface> configuration, Func <T1, T2, T3, T4, object[]> valueProducer)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.AssignsOutAndRefParametersLazily(call =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(
                    call.Method, valueProducer.GetMethodInfo(), NameOfOutRefLazilyFeature);

                return valueProducer(
                    call.GetArgument <T1>(0), call.GetArgument <T2>(1), call.GetArgument <T3>(2), call.GetArgument <T4>(3));
            }));
        }
예제 #12
0
        /// <summary>
        /// Configures the call to be accepted when the specified predicate returns true.
        /// </summary>
        /// <typeparam name="TInterface">The type of the interface.</typeparam>
        /// <typeparam name="T1">The type of the first argument.</typeparam>
        /// <typeparam name="T2">The type of the second argument.</typeparam>
        /// <typeparam name="T3">The type of the third argument.</typeparam>
        /// <param name="configuration">The configuration.</param>
        /// <param name="argumentsPredicate">The argument predicate.</param>
        /// <returns>A configuration object.</returns>
        public static TInterface WhenArgumentsMatch <TInterface, T1, T2, T3>(
            this IArgumentValidationConfiguration <TInterface> configuration,
            Func <T1, T2, T3, bool> argumentsPredicate)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(argumentsPredicate, nameof(argumentsPredicate));

            return(configuration.WhenArgumentsMatch(args =>
            {
                ValueProducerSignatureHelper.AssertThatValueProducerSignatureSatisfiesCallSignature(
                    args.Method,
                    argumentsPredicate.GetMethodInfo(),
                    NameOfWhenArgumentsMatchFeature);

                return argumentsPredicate(args.Get <T1>(0), args.Get <T2>(1), args.Get <T3>(2));
            }));
        }