Example #1
0
        /// <summary>
        /// Adds a behavior to a mock.
        /// </summary>
        public static TMock AddBehavior <TMock>(this TMock mock, Func <IMethodInvocation, bool> appliesTo, InvokeBehavior behavior, string name = null)
        {
            // We can't just add a constraint to the method signature, because this is
            // implemented internally for Moq.Sdk to consume.
            if (mock is IMocked mocked)
            {
                mocked.Mock.Behaviors.Add(MockBehavior.Create(appliesTo, behavior, name));
            }
            else
            {
                throw new ArgumentException(nameof(mock));
            }

            return(mock);
        }
Example #2
0
 /// <summary>
 /// Inserts a behavior into the mock behasvior pipeline at the specified
 /// index.
 /// </summary>
 public static IMock InsertBehavior(this IMock mock, int index, Func <IMethodInvocation, bool> appliesTo, InvokeBehavior behavior, string name = null)
 {
     mock.Behaviors.Insert(index, MockBehavior.Create(appliesTo, behavior, name));
     return(mock);
 }
Example #3
0
 /// <summary>
 /// Inserts a behavior into the mock behavior pipeline at the specified
 /// index.
 /// </summary>
 public static void InsertMockBehavior(this IMocked mock, int index, Func <IMethodInvocation, bool> appliesTo, InvokeBehavior behavior)
 {
     mock.Mock.Behaviors.Insert(index, MockBehavior.Create(appliesTo, behavior));
 }
Example #4
0
 /// <summary>
 /// Adds a behavior to a mock.
 /// </summary>
 public static IMock AddBehavior(this IMock mock, Func <IMethodInvocation, bool> appliesTo, InvokeBehavior behavior, string name = null)
 {
     mock.Behaviors.Add(MockBehavior.Create(appliesTo, behavior, name));
     return(mock);
 }
Example #5
0
 /// <summary>
 /// Adds a behavior to a mock.
 /// </summary>
 public static void AddMockBehavior(this IMocked mock, Func <IMethodInvocation, bool> appliesTo, InvokeBehavior behavior)
 {
     mock.Mock.Behaviors.Add(MockBehavior.Create(appliesTo, behavior));
 }