예제 #1
0
    public static void SetupDefault(Expression <Action> methodGetExpression, Action action)
    {
        if (methodGetExpression == null)
        {
            throw new ArgumentNullException(nameof(methodGetExpression));
        }

        if (action == null)
        {
            throw new ArgumentNullException(nameof(action));
        }

        if (!(methodGetExpression.Body is MethodCallExpression methodExpression))
        {
            throw new Exception("Get expression not contains method to setup");
        }

        var originalMethodInfo = methodExpression.Method;

        if (originalMethodInfo.ReturnType != typeof(void))
        {
            throw new Exception("Default setup supported only for void methods");
        }

        SetupMockHelper.SetupDefault(methodExpression.Method, action);
    }
예제 #2
0
    public static IAsyncFuncMockService <TReturnValue> Setup <TReturnValue>(Expression <Func <Task <TReturnValue> > > methodGetExpression, Action action)
    {
        if (action == null)
        {
            throw new ArgumentNullException(nameof(action));
        }

        var originalMethodInfo = SetupMockHelper.ValidateAndGetOriginalMethodInfo(methodGetExpression);

        return(new AsyncFuncMockService <TReturnValue>(new HookServiceFactory(), new HookBuilder(), originalMethodInfo, action));
    }
예제 #3
0
 public static void SetupDefault(Type type, string methodName, SetupProperties setupProperties, Action action) =>
 SetupMockHelper.SetupDefaultInternal(type, methodName, action, setupProperties);
예제 #4
0
 public static void SetupDefault(Type type, string methodName, BindingFlags bindingFlags, Action action) =>
 SetupMockHelper.SetupDefaultInternal(type, methodName, action, new SetupProperties
 {
     BindingFlags = bindingFlags
 });
예제 #5
0
 public static IVoidMockService SetupVoid(Type type, string methodName, SetupProperties setupProperties, Action action) =>
 SetupMockHelper.SetupVoidInternal(type, methodName, action, setupProperties);
예제 #6
0
 public static IVoidMockService SetupVoid(Type type, string methodName, BindingFlags bindingFlags, Action action) =>
 SetupMockHelper.SetupVoidInternal(type, methodName, action, new SetupProperties
 {
     BindingFlags = bindingFlags
 });
예제 #7
0
 public static IFuncMockService SetupProperty(Type type, string propertyName, BindingFlags bindingFlags, Action action) =>
 SetupMockHelper.SetupPropertyInternal(type, propertyName, action, bindingFlags);
예제 #8
0
 public static IFuncMockService Setup(Type type, string methodName, Action action) => SetupMockHelper.SetupInternal(type, methodName, action);