Ejemplo n.º 1
0
        /// <summary>
        /// Verifies that the method represented by the <paramref name="matchExpression"/> has
        /// been invoked the specified number of <paramref name="invoked"/>.
        /// </summary>
        /// <param name="matchExpression">The <see cref="Expression{TDelegate}"/> that represents
        /// the method invocation to be verified.</param>
        /// <param name="invoked">Specifies the number of times we expect the mocked method to be invoked.</param>
        public void Assert(Expression <Action <TMock> > matchExpression, Invoked invoked)
        {
            var matchInfo = matchExpression.ToMatchInfo();
            var callCount = invocations.Count(matchInfo.Matches);

            if (!invoked.Verify(callCount))
            {
                throw new InvalidOperationException(string.Format("The method {0} was called {1} times", matchExpression.Simplify(), callCount));
            }
        }
        public void AssertInternal(LambdaExpression matchExpression, Invoked invoked)
        {
            var matchInfo   = matchExpression.ToMatchInfo();
            var invocations = this.invocations.InvokeLocked(c => c.Where(matchInfo.Matches).ToArray());

            if (invoked.Verify(invocations.Length))
            {
                verifiedInvocations.AddRange(invocations);
            }
            else
            {
                throw new MockException(string.Format("The method {0} was called {1} times", matchExpression.Simplify(), invocations.Length));
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Verifies that the method represented by the <paramref name="matchExpression"/> has
 /// been invoked.
 /// </summary>
 /// <param name="matchExpression">The <see cref="Expression{TDelegate}"/> that represents
 /// the method invocation to be verified.</param>
 public void Assert(Expression <Action <TMock> > matchExpression)
 {
     Assert(matchExpression, Invoked.AtLeast(1));
 }
 /// <summary>
 /// Verifies that the method represented by the <paramref name="matchExpression"/> has
 /// been invoked the specified number of <paramref name="invoked"/>.
 /// </summary>
 /// <param name="matchExpression">The <see cref="Expression{TDelegate}"/> that represents
 /// the method invocation to be verified.</param>
 /// <param name="invoked">Specifies the number of times we expect the mocked method to be invoked.</param>
 public void Assert(Expression <Action <TMock> > matchExpression, Invoked invoked)
 {
     AssertInternal(matchExpression, invoked);
 }