Esempio n. 1
0
        public static ISetup <T> InSequence <T>(this ISetup <T> setup, MoqSequence sequence) where T : class
        {
            var seqId = sequence.Index(setup.ToString());

            setup.Callback(() => sequence.Callback(seqId));

            return(setup);
        }
Esempio n. 2
0
 public TimesBuilder <int, FluentMock <T> > IsCalled(int num)
 {
     return(new TimesBuilder <int, FluentMock <T> >(num, (val) => {
         var counter = new InvocationCounter(val, m_expression);
         m_setup.Callback(counter.Increment);
         RunOnVerify(counter);
         return this;//return the fluent method builder
     }));
 }
    private static void CallbackSequence <T, TResult, TArg>(this ISetup <T, TResult> setup, params Action <TArg>[] callbacks) where T : class
    {
        var queue = new ConcurrentQueue <Action <TArg> >(callbacks);

        setup.Callback((TArg arg) =>
        {
            Action <TArg> callback;
            if (!queue.TryDequeue(out callback))
            {
                Assert.Fail("More callbacks were invoked than defined in sequence");
            }
            callback(arg);
        });
    }
Esempio n. 4
0
        public void Add <T>(ISetup <T> setup) where T : class
        {
            var methodInfo = (MethodInfo)setup
                             .GetType()
                             .GetRuntimeProperty("Method")
                             .GetValue(setup);

            _methodInfoSequence.Add(methodInfo);
            setup.Callback(() =>
            {
                var currentMethod = _methodInfoSequence.ElementAt(0);
                if (currentMethod != methodInfo)
                {
                    throw new Exception($"Expected {methodInfo} to be called but {currentMethod} has been called.");
                }
                _methodInfoSequence.RemoveAt(0);
            });
        }
 public void Callback(Action callback)
 {
     _methodOptions.Callback(callback);
 }
Esempio n. 6
0
        public DbSetReturnsThrows <TDbContext, TSource, TResult> Callback <T>(Action <T> action)
        {
            var returnsThrows = new DbSetReturnsThrows <TDbContext, TSource, TResult>(SetUp.Callback(action), MockDbSet);

            return(returnsThrows);
        }
Esempio n. 7
0
 public static ICallBaseResult Callback <T>(
     this ISetup <ILogger <T> > loggerMockSetup,
     Action <LogLevel, EventId, object, Exception, Func <object, Exception, string> > action
     ) => loggerMockSetup.Callback(action);
        internal static void AddStep <T, TResult>(ISetup <T, TResult> setup, Times expectedCalls) where T : class
        {
            var step = Sequence.Step(setup, expectedCalls);

            setup.Callback(() => Sequence.Record(step));
        }
 protected sealed override void ApplyCallback(ISetup <TMock, TReturn> wrapped, Action callback)
 {
     wrapped.Callback(callback);
 }
Esempio n. 10
0
 protected sealed override void RegisterForCallback(ISetup <TMock, TReturn> wrapped, Action invokedAction)
 {
     wrapped.Callback(invokedAction);
 }
 public static IReturnsThrows <HttpMessageHandler, Task <HttpResponseMessage> > Callback(this ISetup <HttpMessageHandler, Task <HttpResponseMessage> > setup, Action <HttpRequestMessage, CancellationToken> action)
 => setup.Callback(action);
Esempio n. 12
0
 public static IReturnsThrows <TMock, TResult> InSequence <TMock, TResult>(this ISetup <TMock, TResult> setup, SetupSequence sequence)
     where TMock : class
 {
     return(setup.Callback(sequence.GetCallback(setup.ToString())));
 }
Esempio n. 13
0
 public static ICallbackResult InSequence <TMock>(this ISetup <TMock> setup, SetupSequence sequence)
     where TMock : class
 {
     return(setup.Callback(sequence.GetCallback(setup.ToString())));
 }
Esempio n. 14
0
 public FluentMethodReturns <T, TResult> Executes(Action action)
 {
     m_setup.Callback(action);
     return(this);
 }