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); }
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); });
public CustomAutoFixture() { Customize(new AutoNSubstituteCustomization { ConfigureMembers = true }); Behaviors.OfType <ThrowingRecursionBehavior>() .ToList() .ForEach(b => Behaviors.Remove(b)); Behaviors.Add(new OmitOnRecursionBehavior()); }
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; } }
/// <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); });
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; } }
public NoRecursionFixture() { Behaviors.OfType <ThrowingRecursionBehavior>().ToList().ForEach(b => Behaviors.Remove(b)); Behaviors.Add(new OmitOnRecursionBehavior()); }
public TBehavior GetBehavior <TBehavior>() where TBehavior : IBehavior { return(Behaviors.OfType <TBehavior>().FirstOrDefault()); }
public BehaviorChain FindHomeChain() { return(Behaviors.OfType <RoutedChain>().FirstOrDefault(x => x.Route.Pattern == string.Empty)); }
/// <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()); }