コード例 #1
0
        public void VectorChanged_AddWhileNotAttached_AttachNotCalled()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            StubBehavior stub = new StubBehavior();
            behaviorCollection.Add(stub);

            TestUtilities.AssertNotAttached(stub);
        }
コード例 #2
0
        public void VectorChanged_DuplicateAdd_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            StubBehavior stub = new StubBehavior();
            behaviorCollection.Add(stub);

            TestUtilities.AssertThrowsException(() => behaviorCollection.Add(stub));

        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void VectorChanged_RemoveWhileNotAttached_DetachNotCalled()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();

            StubBehavior behavior = new StubBehavior();
            behaviorCollection.Add(behavior);
            behaviorCollection.Remove(behavior);

            TestUtilities.AssertNotDetached(behavior);
        }
コード例 #5
0
        public void Attach_MultipleObjects_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            StubBehavior stub = new StubBehavior();
            behaviorCollection.Attach(new Button());

            TestUtilities.AssertThrowsException(() => behaviorCollection.Attach(new StackPanel()));
        }
コード例 #6
0
        public void VectorChanged_RemoveWhileAttached_Detached()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Attach(new ToggleSwitch());

            StubBehavior behavior = new StubBehavior();
            behaviorCollection.Add(behavior);
            behaviorCollection.Remove(behavior);

            TestUtilities.AssertDetached(behavior);
        }
コード例 #7
0
 public static void AssertNotAttached(StubBehavior behavior)
 {
     Assert.AreEqual(0, behavior.AttachCount, "The behavior should not be attached.");
     Assert.IsNull(behavior.AssociatedObject, "The AssociatedObject should be null for a non-attached Behavior.");
 }
コード例 #8
0
 public static void AssertAttached(StubBehavior behavior, DependencyObject associatedObject)
 {
     Assert.AreEqual(1, behavior.AttachCount, "The behavior should be attached.");
     Assert.AreEqual(associatedObject, behavior.AssociatedObject, "The AssociatedObject of the Behavior should be what it was attached to.");
 }
コード例 #9
0
 public static void AssertNotDetached(StubBehavior behavior)
 {
     Assert.AreEqual(0, behavior.DetachCount, "The Behavior should not be detached.");
 }
コード例 #10
0
 public static void AssertDetached(StubBehavior behavior)
 {
     Assert.AreEqual(1, behavior.DetachCount, "The Behavior should be detached.");
     Assert.IsNull(behavior.AssociatedObject, "A Detached Behavior should have a null AssociatedObject.");
 }