Example #1
0
        private IBehavior GetBehavior()
        {
            foreach (var behavior in Behaviors)
            {
                if (behavior == _currentBehavior)
                {
                    if (behavior.CanContinue())
                    {
                        return(behavior);
                    }

                    behavior.OnEnd();
                    _currentBehavior = null;
                }

                if (behavior.ShouldStart())
                {
                    if (_currentBehavior == null || Behaviors.IndexOf(_currentBehavior) > Behaviors.IndexOf(behavior))
                    {
                        _currentBehavior?.OnEnd();
                        return(behavior);
                    }
                }
            }

            return(null);
        }
Example #2
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);
 });
Example #3
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);
        });