예제 #1
0
 public IMockBehavior BehaviorFor(IMockSetup setup)
 => setupBehaviorMap.GetOrAdd(setup, x =>
 {
     var behavior = new MockBehavior(x);
     Behaviors.Insert(1, behavior);
     return(behavior);
 });
예제 #2
0
        /// <summary>
        /// Inserts a behavior into the mock behavior pipeline at the specified
        /// index for the current <see cref="MockContext.CurrentSetup"/> setup.
        /// </summary>
        public static IMock InsertBehavior(this IMock mock, int index, ExecuteDelegate behavior, Lazy <string> displayName)
        {
            mock
            .GetPipeline(MockContext.CurrentSetup ?? throw new InvalidOperationException(Strings.NoCurrentSetup))
            .Behaviors
            .Insert(index, MockBehavior.Create(behavior, displayName));

            return(mock);
        }
예제 #3
0
        /// <summary>
        /// Inserts a behavior into the mock behavior pipeline at the specified
        /// index for the current <see cref="MockContext.CurrentSetup"/> setup.
        /// </summary>
        public static IMock InsertBehavior(this IMock mock, int index, InvokeBehavior behavior, Lazy <string> displayName)
        {
            mock
            .BehaviorFor(MockContext.CurrentSetup ?? throw new InvalidOperationException(Strings.NoCurrentSetup))
            .Behaviors
            .Insert(index, new Behavior(behavior, displayName));

            return(mock);
        }
예제 #4
0
 public IMockBehaviorPipeline GetPipeline(IMockSetup setup)
 => setupBehaviorMap.GetOrAdd(setup, x =>
 {
     var behavior = new MockBehaviorPipeline(x);
     // The tracking behavior must appear before the mock behaviors.
     var tracking = Behaviors.OfType <MockTrackingBehavior>().FirstOrDefault();
     // NOTE: latest setup wins, since it goes to the top of the list.
     var index = tracking == null ? 0 : (Behaviors.IndexOf(tracking) + 1);
     Behaviors.Insert(index, behavior);
     return(behavior);
 });
예제 #5
0
        /// <inheritdoc />
        public IMockBehaviorPipeline GetPipeline(IMockSetup setup)
        => setupBehaviorMap.GetOrAdd(setup, x =>
        {
            var behavior = new MockBehaviorPipeline(x);
            // The tracking behavior must appear before the mock behaviors.
            var context = Behaviors.OfType <MockContextBehavior>().FirstOrDefault();
            // If there is a recording behavior, it must be before mock behaviors too.
            var recording = Behaviors.OfType <MockRecordingBehavior>().FirstOrDefault();

            var index = context == null ? 0 : Behaviors.IndexOf(context);
            if (recording != null)
            {
                index = Math.Max(index, Behaviors.IndexOf(recording));
            }

            // NOTE: latest setup wins, since it goes to the top of the list.
            Behaviors.Insert(++index, behavior);
            return(behavior);
        });