Can Pex and Moq work together?

Has anyone tried this?

I like moq and I like what pex does, but have not tried them together. I would prefer to use moq on top of moles in most cases, I think, but I'm curious to find out if anyone got into the roadblocks?

Do they play well?

+3
source share
2 answers

Although I have not tried, Pex and Moq should get along like old friends.

Pex Moq (Pex ProfilerAPI MSIL, Moq DynamicProxy ), Moq , , Pex Moq.

Pex, , Pex- .

Moq:

internal static MethodCall<T> Setup<T>(Mock mock, Expression<Action<T>> expression, Func<bool> condition) where T : class
{
    return PexProtector.Invoke(() =>
    {
       var methodCall = expression.ToMethodCall();
       var method = methodCall.Method;
       var args = methodCall.Arguments.ToArray();
       ThrowIfNotMember(expression, method);
       ThrowIfCantOverride(expression, method);

       var call = new MethodCall<T>(mock, condition, expression, method, args);
       var targetInterceptor = GetInterceptor(methodCall.Object, mock);
       targetInterceptor.AddCall(call, SetupKind.Other);

       return call;
     });   
 }

PexProtector :

 internal sealed class __ProtectAttribute : Attribute
 {
 }

 namespace Moq
 {
    [__Protect]
    [DebuggerStepThrough]
    internal static class PexProtector
    {
        public static void Invoke(Action action)
        {
           action();
        }

        public static T Invoke<T>(Func<T> function)
        {
           return function();
        }
    }
 }
+2

pex amd moq, , . Pex, , Reflection.Emit/dynamic proxy, moq.

Moles, pex. pex

0

Source: https://habr.com/ru/post/1781022/


All Articles