public void VectorChanged_AddWhileNotAttached_AttachNotCalled() { BehaviorCollection behaviorCollection = new BehaviorCollection(); StubBehavior stub = new StubBehavior(); behaviorCollection.Add(stub); TestUtilities.AssertNotAttached(stub); }
public void VectorChanged_DuplicateAdd_ExceptionThrown() { BehaviorCollection behaviorCollection = new BehaviorCollection(); StubBehavior stub = new StubBehavior(); behaviorCollection.Add(stub); TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Add(stub)); }
public void Attach_MultipleObjects_ExceptionThrown() { BehaviorCollection behaviorCollection = new BehaviorCollection(); StubBehavior stub = new StubBehavior(); behaviorCollection.Attach(new Button()); TestUtilities.AssertThrowsInvalidOperationException(() => behaviorCollection.Attach(new StackPanel())); }
public void VectorChanged_RemoveWhileNotAttached_DetachNotCalled() { BehaviorCollection behaviorCollection = new BehaviorCollection(); StubBehavior behavior = new StubBehavior(); behaviorCollection.Add(behavior); behaviorCollection.Remove(behavior); TestUtilities.AssertNotDetached(behavior); }
public void VectorChanged_RemoveWhileAttached_Detached() { BehaviorCollection behaviorCollection = new BehaviorCollection(); behaviorCollection.Attach(new ToggleButton()); StubBehavior behavior = new StubBehavior(); behaviorCollection.Add(behavior); behaviorCollection.Remove(behavior); TestUtilities.AssertDetached(behavior); }
public void VectorChanged_ReplaceWhileAttached_OldDetachedNewAttached() { BehaviorCollection behaviorCollection = new BehaviorCollection(); behaviorCollection.Attach(new Button()); StubBehavior first = new StubBehavior(); behaviorCollection.Add(first); StubBehavior second = new StubBehavior(); behaviorCollection[0] = second; TestUtilities.AssertDetached(first); TestUtilities.AssertAttached(second, behaviorCollection.AssociatedObject); }
public static void AssertNotAttached(StubBehavior behavior) { Assert.Equal(0, behavior.AttachCount); // "The behavior should not be attached." Assert.Null(behavior.AssociatedObject); // "The AssociatedObject should be null for a non-attached Behavior." }
public static void AssertAttached(StubBehavior behavior, IAvaloniaObject?associatedObject) { Assert.Equal(1, behavior.AttachCount); // "The behavior should be attached." Assert.Equal(associatedObject, behavior.AssociatedObject); // "The AssociatedObject of the Behavior should be what it was attached to." }
public static void AssertNotDetached(StubBehavior behavior) { Assert.Equal(0, behavior.DetachCount); // "The Behavior should not be detached." }
public static void AssertDetached(StubBehavior behavior) { Assert.Equal(1, behavior.DetachCount); // "The Behavior should be detached." Assert.Null(behavior.AssociatedObject); // "A Detached Behavior should have a null AssociatedObject." }