示例#1
0
 public BettingSystemFixture()
 {
     Behaviors.OfType <ThrowingRecursionBehavior>().ToList()
     .ForEach(b => Behaviors.Remove(b));
     Behaviors.Add(new OmitOnRecursionBehavior());
     Customizations.Add(new PropertyNameOmitter("Id"));
 }
        public Explosion()
            : base("Explosion", new Vector2(32, 32))
        {
            Sprite.Animations.Add(new Animation("exploding", 0, 0, 1));
            Sprite.ChangeAnimation("exploding");
            var bh = Behaviors.OfType <PickableBehavior>().FirstOrDefault();

            Behaviors.Remove(bh);
        }
示例#3
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);
 });
示例#4
0
        public CustomAutoFixture()
        {
            Customize(new AutoNSubstituteCustomization
            {
                ConfigureMembers = true
            });

            Behaviors.OfType <ThrowingRecursionBehavior>()
            .ToList()
            .ForEach(b => Behaviors.Remove(b));

            Behaviors.Add(new OmitOnRecursionBehavior());
        }
示例#5
0
        void OnBehaviorsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                // Can't have more than one of MockContextBehavior, since that causes problems.
                if (Behaviors.OfType <MockContextBehavior>().Skip(1).Any())
                {
                    throw new InvalidOperationException(Resources.DuplicateContextBehavior);
                }
                // Can't have more than one of MockRecordingBehavior, since that causes problems.
                if (Behaviors.OfType <MockRecordingBehavior>().Skip(1).Any())
                {
                    throw new InvalidOperationException(Resources.DuplicateRecordingBehavior);
                }

                foreach (var behavior in e.NewItems.OfType <IMockBehaviorPipeline>())
                {
                    setupBehaviorMap.TryAdd(behavior.Setup, behavior);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var behavior in e.OldItems.OfType <IMockBehaviorPipeline>())
                {
                    setupBehaviorMap.TryRemove(behavior.Setup, out _);
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                foreach (var behavior in e.NewItems.OfType <IMockBehaviorPipeline>())
                {
                    setupBehaviorMap.TryAdd(behavior.Setup, behavior);
                }
                foreach (var behavior in e.OldItems.OfType <IMockBehaviorPipeline>())
                {
                    setupBehaviorMap.TryRemove(behavior.Setup, out _);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                setupBehaviorMap.Clear();
                break;
            }
        }
示例#6
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);
        });
示例#7
0
        void OnBehaviorsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var behavior in e.NewItems.OfType <IMockBehavior>())
                {
                    setupBehaviorMap.TryAdd(behavior.Setup, behavior);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var behavior in e.OldItems.OfType <IMockBehavior>())
                {
                    setupBehaviorMap.TryRemove(behavior.Setup, out _);
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                foreach (var behavior in e.NewItems.OfType <IMockBehavior>())
                {
                    setupBehaviorMap.TryAdd(behavior.Setup, behavior);
                }
                foreach (var behavior in e.OldItems.OfType <IMockBehavior>())
                {
                    setupBehaviorMap.TryRemove(behavior.Setup, out _);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                setupBehaviorMap.Clear();
                foreach (var behavior in Behaviors.OfType <IMockBehavior>())
                {
                    setupBehaviorMap.TryAdd(behavior.Setup, behavior);
                }
                break;

            default:
                break;
            }
        }
示例#8
0
 public NoRecursionFixture()
 {
     Behaviors.OfType <ThrowingRecursionBehavior>().ToList().ForEach(b => Behaviors.Remove(b));
     Behaviors.Add(new OmitOnRecursionBehavior());
 }
示例#9
0
 public TBehavior GetBehavior <TBehavior>() where TBehavior : IBehavior
 {
     return(Behaviors.OfType <TBehavior>().FirstOrDefault());
 }
示例#10
0
 public BehaviorChain FindHomeChain()
 {
     return(Behaviors.OfType <RoutedChain>().FirstOrDefault(x => x.Route.Pattern == string.Empty));
 }
示例#11
0
 /// <summary>
 /// Gets behavior by type.
 /// </summary>
 /// <typeparam name="T">Behavior type</typeparam>
 /// <returns>Behavior of type or null.</returns>
 public T GetBehavior <T>() where T : Behavior
 {
     return(Behaviors.OfType <T>().FirstOrDefault());
 }