public void VectorChanged_NonBehaviorAdded_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());

            TestUtilities.AssertThrowsException(() => behaviorCollection.Add(new TextBlock()));
        }
        public void VectorChanged_DuplicateAdd_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            StubBehavior stub = new StubBehavior();
            behaviorCollection.Add(stub);

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

        }
        public void VectorChanged_AddWhileAttached_AllAttached()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Attach(new Button());

            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            foreach (StubBehavior stub in behaviorCollection)
            {
                TestUtilities.AssertAttached(stub, behaviorCollection.AssociatedObject);
            }
        }
예제 #4
0
        private void ConfigureOrCreateSearchContract( BehaviorCollection behaviors )
        {
            Contract.Requires( behaviors != null );

            if ( !searchOptions.IsValueCreated )
                return;

            var options = searchOptions.Value;
            var searchContract = behaviors.OfType<SearchContractBehavior>().FirstOrDefault();

            if ( searchContract == null )
            {
                searchContract = new SearchContractBehavior();
                behaviors.Add( searchContract );
            }

            searchContract.SearchHistoryEnabled = options.SearchHistoryEnabled;
            searchContract.ShowOnKeyboardInput = options.ShowOnKeyboardInput;

            if ( !string.IsNullOrEmpty( options.PlaceholderText ) )
                searchContract.PlaceholderText = options.PlaceholderText;

            if ( !string.IsNullOrEmpty( options.SearchHistoryContext ) )
                searchContract.SearchHistoryContext = options.SearchHistoryContext;
        }
예제 #5
0
        private void ConfigureOrCreateSettingsContract( BehaviorCollection behaviors )
        {
            Contract.Requires( behaviors != null );

            var settingsContract = behaviors.OfType<SettingsContractBehavior>().FirstOrDefault();

            if ( settingsContract == null )
            {
                settingsContract = new SettingsContractBehavior();
                behaviors.Add( settingsContract );
            }

            foreach ( var appSetting in appSettings )
            {
                var setting = new ApplicationSetting()
                {
                    Name = appSetting.Item2,
                    ViewTypeName = appSetting.Item3
                };

                if ( !string.IsNullOrEmpty( appSetting.Item1 ) )
                    setting.Id = appSetting.Item1;

                settingsContract.ApplicationSettings.Add( setting );
            }
        }
        public void VectorChanged_BehaviorChangedToNonBehavior_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());

            TestUtilities.AssertThrowsException(() => behaviorCollection[0] = new ToggleSwitch());
        }
예제 #7
0
        public void SetBehaviors_MultipleBehaviors_AllAttached()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            Button button = new Button();
            Interaction.SetBehaviors(button, behaviorCollection);

            foreach (StubBehavior behavior in behaviorCollection)
            {
                Assert.AreEqual(1, behavior.AttachCount, "Should only have called Attach once.");
                Assert.AreEqual(0, behavior.DetachCount, "Should not have called Detach.");
                Assert.AreEqual(button, behavior.AssociatedObject, "Should be attached to the host of the BehaviorCollection.");
            }
        }
        public void VectorChanged_AddWhileNotAttached_AttachNotCalled()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            StubBehavior stub = new StubBehavior();
            behaviorCollection.Add(stub);

            TestUtilities.AssertNotAttached(stub);
        }
예제 #9
0
        public void SetBehaviors_ManualDetachThenNull_DoesNotDoubleDetach()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            Button button = new Button();
            Interaction.SetBehaviors(button, behaviorCollection);

            foreach (StubBehavior behavior in behaviorCollection)
            {
                behavior.Detach();
            }

            Interaction.SetBehaviors(button, null);

            foreach (StubBehavior behavior in behaviorCollection)
            {
                Assert.AreEqual(1, behavior.DetachCount, "Setting BehaviorCollection to null should not call Detach on already Detached Behaviors.");
                Assert.IsNull(behavior.AssociatedObject, "AssociatedObject should be null after Detach.");
            }
        }
        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 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);
        }
        public void VectorChanged_RemoveWhileNotAttached_DetachNotCalled()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();

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

            TestUtilities.AssertNotDetached(behavior);
        }
        public void Attach_MultipleBehaviors_AllAttached()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            Button button = new Button();
            behaviorCollection.Attach(button);

            Assert.AreEqual(button, behaviorCollection.AssociatedObject, "Attach should set the AssociatedObject to the given parameter.");

            foreach (StubBehavior stub in behaviorCollection)
            {
                TestUtilities.AssertAttached(stub, button);
            }
        }
        public void VectorChanged_ResetWhileAttached_AllDetached()
        {
            StubBehavior[] behaviorArray = { new StubBehavior(), new StubBehavior(), new StubBehavior() };

            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Attach(new Button());

            foreach (StubBehavior behavior in behaviorArray)
            {
                behaviorCollection.Add(behavior);
            }

            behaviorCollection.Clear();

            foreach (StubBehavior behavior in behaviorArray)
            {
                TestUtilities.AssertDetached(behavior);
            }
        }
        public void Detach_Attached_AllItemsDetached()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            behaviorCollection.Attach(new Button());
            behaviorCollection.Detach();

            Assert.IsNull(behaviorCollection.AssociatedObject, "The AssociatedObject should be null after Detach.");

            foreach (StubBehavior behavior in behaviorCollection)
            {
                TestUtilities.AssertDetached(behavior);
            }
        }
        public void Attach_NonNullThenNull_ExceptionThrown()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());

            behaviorCollection.Attach(new Button());

            TestUtilities.AssertThrowsException(() => behaviorCollection.Attach(null));
        }
        public void Attach_Null_AttachNotCalledOnItems()
        {
            BehaviorCollection behaviorCollection = new BehaviorCollection();
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());
            behaviorCollection.Add(new StubBehavior());

            behaviorCollection.Attach(null);

            foreach (StubBehavior stub in behaviorCollection)
            {
                TestUtilities.AssertNotAttached(stub);
            }
        }