コード例 #1
0
 public BettingSystemFixture()
 {
     Behaviors.OfType <ThrowingRecursionBehavior>().ToList()
     .ForEach(b => Behaviors.Remove(b));
     Behaviors.Add(new OmitOnRecursionBehavior());
     Customizations.Add(new PropertyNameOmitter("Id"));
 }
コード例 #2
0
        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
ファイル: MockInfo.cs プロジェクト: zhangwenquan/moq
        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
ファイル: GameObject.cs プロジェクト: alex-fomin/Game
 public TBehavior GetBehavior <TBehavior>() where TBehavior : IBehavior
 {
     return(Behaviors.OfType <TBehavior>().FirstOrDefault());
 }
コード例 #10
0
ファイル: BehaviorGraph.cs プロジェクト: xeno3/fubumvc
 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());
 }