public void Assert(Type targetType, string memberName, Occurs occurs, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(targetType, typeof(void), memberName, ref args);
         MockingContext.CurrentRepository.AssertMethodInfo(null, method, args, occurs);
     });
 }
Exemple #2
0
 public void Assert(MethodBase method, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var message = GetAssertionMessage(args);
         MockingContext.CurrentRepository.AssertMethodInfo(message, null, method, args, null);
     });
 }
Exemple #3
0
 public int GetTimesCalled(Type type, string memberName, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(type, typeof(void), memberName, ref args);
         return MockingContext.CurrentRepository.GetTimesCalledFromMethodInfo(null, method, args);
     }));
 }
Exemple #4
0
 public FuncExpectation <TReturn> Arrange <T, TReturn>(string memberName, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(typeof(T), typeof(TReturn), memberName, ref args);
         return MockingContext.CurrentRepository.Arrange(null, method, args, () => new FuncExpectation <TReturn>());
     }));
 }
Exemple #5
0
 public ActionExpectation Arrange(Type targetType, string memberName, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(targetType, typeof(void), memberName, ref args);
         return MockingContext.CurrentRepository.Arrange(null, method, args, () => new ActionExpectation());
     }));
 }
 /// <summary>
 /// Specifies a condition on the invocation arguments. See <see cref="M:Telerik.JustMock.Args.Filter"/> for usage details.
 /// </summary>
 /// <typeparam name="T1">Type of the first parameter of the anonymous method that this delegate encapsulates</typeparam>
 public Args AndMatching <T1>(Func <T1, bool> predicate)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         this.Filter = predicate;
         return this;
     }));
 }
Exemple #7
0
 public void Assert(object target, MethodInfo method, Occurs occurs, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var message = GetAssertionMessage(args);
         MockingContext.CurrentRepository.AssertMethodInfo(message, target, method, args, occurs);
     });
 }
Exemple #8
0
 /// <summary>
 /// Defines the return value for a specific method expectation.
 /// </summary>
 /// <param name="value">any object value</param>
 /// <returns></returns>
 public IAssertable Returns(TReturn value)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         this.ProcessReturnsValue(value);
         return this;
     }));
 }
Exemple #9
0
 /// <summary>
 /// Specifies the delegate to evaluate and return for the expected method.
 /// </summary>
 /// <param name="delegate">Target delegate to evaluate.</param>
 /// <returns>Reference to <see cref="IAssertable"/> interface</returns>
 public IAssertable Returns(Delegate @delegate)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         this.ProcessDoInstead(@delegate ?? new Func <TReturn>(() => default(TReturn)), false);
         return this;
     }));
 }
 /// <summary>
 /// Gets the value of a field or property.
 /// </summary>
 /// <param name="name">Name of a field or property to get.</param>
 /// <returns>The value of the field or property.</returns>
 public object GetMember(string name)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var field = ResolveField(name);
         return field != null ? GetField(name) : GetProperty(name);
     }));
 }
 /// <summary>
 /// Raises the specified event passing the given arguments to the handlers.
 /// </summary>
 /// <param name="name">The name of the event to raise.</param>
 /// <param name="eventArgs">Arguments to pass to the event handlers. Must match the event handler signature exactly.</param>
 public void RaiseEvent(string name, params object[] eventArgs)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var evt = this.type.GetEvent(name, MockingUtil.AllMembers);
         MockingUtil.RaiseEventThruReflection(this.instance, evt, eventArgs);
     });
 }
 /// <summary>
 /// Sets the value of a property by name.
 /// </summary>
 /// <param name="name">The name of the property.</param>
 /// <param name="value">The value to set to the property.</param>
 /// <param name="indexArgs">Optional index arguments if the property has any.</param>
 public void SetProperty(string name, object value, params object[] indexArgs)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var prop = MockingUtil.ResolveProperty(this.type, name, false, indexArgs, this.instance != null, value, getter: false);
         ProfilerInterceptor.GuardExternal(() => SecuredReflectionMethods.SetProperty(prop, this.instance, value, indexArgs));
     });
 }
 /// <summary>
 /// Gets the value of a property by name.
 /// </summary>
 /// <param name="name">The name of the property.</param>
 /// <param name="indexArgs">Optional index arguments if the property has any.</param>
 /// <returns>The value of the property.</returns>
 public object GetProperty(string name, params object[] indexArgs)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var prop = MockingUtil.ResolveProperty(this.type, name, false, indexArgs, this.instance != null);
         return ProfilerInterceptor.GuardExternal(() => SecuredReflectionMethods.GetProperty(prop, this.instance, indexArgs));
     }));
 }
 void INonPublicExpectation.Assert <TReturn>(Type targetType, string memberName, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(targetType, typeof(TReturn), memberName, ref args);
         MockingContext.CurrentRepository.AssertMethodInfo(null, method, args, null);
     });
 }
Exemple #15
0
 public void Raise(Type type, string eventName, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         RaiseEventBehavior.RaiseEventImpl(null, type.GetEvent(eventName,
                                                               BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static), args);
     });
 }
Exemple #16
0
 /// <summary>
 /// Specifies the delegate that will execute and return the value for the expected member.
 /// </summary>
 /// <returns>Reference to <see cref="IAssertable"/> interface.</returns>
 public IAssertable Returns(Func <TReturn, TReturn> func)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         this.ProcessDoInstead(func, false);
         return this;
     }));
 }
 /// <summary>
 /// Specifies a condition on the invocation arguments. See <see cref="M:Telerik.JustMock.Args.Filter"/> for usage details.
 /// </summary>
 /// <typeparam name="T1">Type of the first parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T2">Type of the second parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T3">Type of the third parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T4">Type of the fourth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T5">Type of the fifth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T6">Type of the sixth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T7">Type of the seventh parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T8">Type of the eighth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T9">Type of the ninth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T10">Type of the tenth parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T11">Type of the eleventh parameter of the anonymous method that this delegate encapsulates</typeparam>
 /// <typeparam name="T12">Type of the twelveth parameter of the anonymous method that this delegate encapsulates</typeparam>
 public Args AndMatching <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool> predicate)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         this.Filter = predicate;
         return this;
     }));
 }
Exemple #18
0
 public void Raise(object instance, string eventName, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         RaiseEventBehavior.RaiseEventImpl(instance, MockingUtil.GetUnproxiedType(instance).GetEvent(eventName,
                                                                                                     BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance), args);
     });
 }
 public void Assert <T, TReturn>(string memberName, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var method = GetMethodByName(typeof(T), typeof(TReturn), memberName, ref args);
         MockingContext.CurrentRepository.AssertMethodInfo(null, method, args, null);
     });
 }
Exemple #20
0
 public T Call <T>(object target, MethodInfo method, string localFunctionName, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var resObject = this.Call(target, method, localFunctionName, args);
         T res = (T)resObject;
         return res;
     }));
 }
Exemple #21
0
        public void Assert(object target, string methodName, Type[] methodParamTypes, string localFunctionName, Occurs occurs, params object[] args)
        {
            ProfilerInterceptor.GuardInternal(() =>
            {
                MethodInfo method = MockingUtil.GetMethodWithLocalFunction(target, methodName, methodParamTypes);

                this.Assert(target, method, localFunctionName, occurs, args);
            });
        }
Exemple #22
0
 /// <summary>
 /// Marks that Mock.Assert should ignore the instance match.
 /// </summary>
 /// <returns>Returns Args configuration.</returns>
 public static Args IgnoreInstance()
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         return new Args {
             IsInstanceIgnored = true
         };
     }));
 }
Exemple #23
0
 public object Call(object target, MethodInfo method, string localFunctionName, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         Type type = target.GetType();
         MethodInfo localFunction = MockingUtil.GetLocalFunction(type, method, localFunctionName);
         return Mock.NonPublic.MakePrivateAccessor(target).CallMethod(localFunction, args);
     }));
 }
Exemple #24
0
 /// <summary>
 /// Setups the target mock call with user expectation.
 /// </summary>
 /// <typeparam name="T">Target type</typeparam>
 /// <param name="obj">
 /// Target instance.
 /// </param>
 /// <param name="func">
 /// Expression delegate to the target call
 /// </param>
 /// <returns>
 /// Reference to <see cref="ActionExpectation"/> to setup the mock.
 /// </returns>
 public static ActionExpectation Arrange <T>(T obj, Action <T> action)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var repo = MockingContext.CurrentRepository;
         repo.EnableInterception(typeof(T));
         return repo.Arrange(() => action(obj), () => new ActionExpectation());
     }));
 }
Exemple #25
0
 /// <summary>
 /// Setups the target mock call with user expectation.
 /// </summary>
 /// <typeparam name="T">Target type</typeparam>
 /// <typeparam name="TResult">
 /// Return type for the target setup.
 /// </typeparam>
 /// <param name="obj">
 /// Target instance.
 /// </param>
 /// <param name="func">
 /// Expression delegate to the target call
 /// </param>
 /// <returns>
 /// Reference to <see cref="FuncExpectation{TResult}"/> to setup the mock.
 /// </returns>
 public static FuncExpectation <TResult> Arrange <T, TResult>(T obj, Func <T, TResult> func)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var repo = MockingContext.CurrentRepository;
         repo.EnableInterception(typeof(T));
         return repo.Arrange(() => func(obj), () => new FuncExpectation <TResult>());
     }));
 }
Exemple #26
0
 /// <summary>
 /// Raises the specified event. If the event is not mocked and is declared on a C# or VB class
 /// and has the default implementation for add/remove, then that event can also be raised using this
 /// method, even with the profiler off.
 /// </summary>
 /// <typeparam name="T">Type of the object.</typeparam>
 /// <param name="obj">Target instance.</param>
 /// <param name="eventExpression">Event expression.</param>
 /// <param name="args">Delegate arguments.</param>
 public static void Raise <T>(this T obj, Action <T> eventExpression, params object[] args)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var repo = MockingContext.CurrentRepository;
         var evt  = repo.ParseAddHandlerAction(obj, eventExpression);
         RaiseEventBehavior.RaiseEventImpl(obj, evt, args);
     });
 }
Exemple #27
0
 /// <summary>
 /// Gets the value of a dynamic private accessor expression. Use this when the value to get
 /// is of type Object, otherwise cast the expression to the desired type.
 /// </summary>
 /// <param name="privateAccessor">A PrivateAccessor expression built from a dynamic variable.</param>
 /// <returns>The value of the private accessor expression</returns>
 public static object Unwrap(dynamic privateAccessor)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var obj = (object)privateAccessor;
         var acc = obj as PrivateAccessor;
         return acc != null ? acc.Instance : obj;
     }));
 }
Exemple #28
0
 /// <summary>
 /// Sets the value of a field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="value">The new value of the field.</param>
 public void SetField(string name, object value)
 {
     ProfilerInterceptor.GuardInternal(() =>
     {
         var field = ResolveField(name);
         CheckMemberInfo("field", name, field);
         SecuredReflectionMethods.SetField(field, this.instance, value);
     });
 }
Exemple #29
0
 /// <summary>
 /// Gets the value of a field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <returns>The value of the field</returns>
 public object GetField(string name)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var field = ResolveField(name);
         CheckMemberInfo("field", name, field);
         return SecuredReflectionMethods.GetField(field, this.instance);
     }));
 }
 public T Call <T>(object target, string methodName, Type[] methodParamTypes, string localFunctionName, Type[] methodGenericTypes, Type[] localFunctionGenericTypes, params object[] args)
 {
     return(ProfilerInterceptor.GuardInternal(() =>
     {
         var resObject = this.Call(target, methodName, methodParamTypes, localFunctionName, methodGenericTypes, localFunctionGenericTypes, args);
         T res = (T)resObject;
         return res;
     }));
 }