コード例 #1
0
        public void DeattachingFromCommandDoesNotInvokeItWhenClickingIt()
        {
            var mockCommand = new MockCommand();
            MockClickableButton button = new MockClickableButton();
            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            button.SetValue(CommandProperties.CommandProperty, null);
            button.InvokeClick();

            Assert.IsFalse(mockCommand.ExecuteCalled);
        }
コード例 #2
0
        public void ButtonClickExecutesCommand()
        {
            var mockCommand = new MockCommand();
            MockClickableButton button = new MockClickableButton();
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            Assert.IsFalse(mockCommand.ExecuteCalled);

            button.InvokeClick();

            Assert.IsTrue(mockCommand.ExecuteCalled);
        }
コード例 #3
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void DeattachingFromCommandDoesNotInvokeItWhenClickingIt()
        {
            var mockCommand            = new MockCommand();
            MockClickableButton button = new MockClickableButton();

            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            button.SetValue(CommandProperties.CommandProperty, null);
            button.InvokeClick();

            Assert.IsFalse(mockCommand.ExecuteCalled);
        }
コード例 #4
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void ButtonClickExecutesCommand()
        {
            var mockCommand            = new MockCommand();
            MockClickableButton button = new MockClickableButton();

            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            Assert.IsFalse(mockCommand.ExecuteCalled);

            button.InvokeClick();

            Assert.IsTrue(mockCommand.ExecuteCalled);
        }
コード例 #5
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void InitialHookupSetButtonAsDisabledIfCanExecuteIsFalse()
        {
            var mockCommand = new MockCommand();
            var button      = new Button();

            button.IsEnabled = true;

            mockCommand.CanExecuteReturnValue = false;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            Assert.IsFalse(button.IsEnabled);
        }
コード例 #6
0
        public void CommandParameterIsPassedToCommandInvocation()
        {
            var mockCommand = new MockCommand();
            MockClickableButton button = new MockClickableButton();
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            object parameter = new object();
            button.SetValue(CommandProperties.CommandParameterProperty, parameter);

            button.InvokeClick();

            Assert.IsNotNull(mockCommand.ExecuteArgumentParameter);
            Assert.AreEqual(parameter, mockCommand.ExecuteArgumentParameter);
        }
コード例 #7
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void WhenDesubscribedDontCallCanExecute()
        {
            var mockCommand = new MockCommand();
            var button      = new Button();

            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            button.SetValue(CommandProperties.CommandProperty, null);

            mockCommand.CanExecuteCalled = false;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsFalse(mockCommand.CanExecuteCalled);
        }
コード例 #8
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void CommandParameterIsPassedToCommandInvocation()
        {
            var mockCommand            = new MockCommand();
            MockClickableButton button = new MockClickableButton();

            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            object parameter = new object();

            button.SetValue(CommandProperties.CommandParameterProperty, parameter);

            button.InvokeClick();

            Assert.IsNotNull(mockCommand.ExecuteArgumentParameter);
            Assert.AreEqual(parameter, mockCommand.ExecuteArgumentParameter);
        }
コード例 #9
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void BehaviorDoesNotPreventButtonFromBeingGarbageCollected()
        {
            var mockCommand = new MockCommand();
            var button      = new Button();

            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            WeakReference buttonReference = new WeakReference(button);

            button = null;
            GC.Collect();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.IsFalse(buttonReference.IsAlive);
        }
コード例 #10
0
        public void CanExecuteChangedMakesButtonRequeryCommandAndSetsIsEnabledAppropriately()
        {
            var mockCommand = new MockCommand();
            var button = new Button();
            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            mockCommand.CanExecuteReturnValue = false;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsFalse(button.IsEnabled);

            mockCommand.CanExecuteReturnValue = true;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsTrue(button.IsEnabled);
        }
コード例 #11
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void CanExecuteChangedGetsCalledPassingTheCommandParameter()
        {
            var mockCommand = new MockCommand();
            var button      = new Button();

            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            object parameter = new object();

            button.SetValue(CommandProperties.CommandParameterProperty, parameter);

            mockCommand.CanExecuteArgumentParameter = null;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsNotNull(mockCommand.CanExecuteArgumentParameter);
            Assert.AreSame(parameter, mockCommand.CanExecuteArgumentParameter);
        }
コード例 #12
0
ファイル: CommandsFixture.cs プロジェクト: eslahi/prism
        public void CanExecuteChangedMakesButtonRequeryCommandAndSetsIsEnabledAppropriately()
        {
            var mockCommand = new MockCommand();
            var button      = new Button();

            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            mockCommand.CanExecuteReturnValue = false;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsFalse(button.IsEnabled);

            mockCommand.CanExecuteReturnValue = true;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsTrue(button.IsEnabled);
        }
コード例 #13
0
        public void CanExecuteChangedGetsCalledPassingTheCommandParameter()
        {
            var mockCommand = new MockCommand();
            var button = new Button();
            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            object parameter = new object();
            button.SetValue(CommandProperties.CommandParameterProperty, parameter);

            mockCommand.CanExecuteArgumentParameter = null;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsNotNull(mockCommand.CanExecuteArgumentParameter);
            Assert.AreSame(parameter, mockCommand.CanExecuteArgumentParameter);
        }
コード例 #14
0
        public void InitialHookupSetButtonAsDisabledIfCanExecuteIsFalse()
        {
            var mockCommand = new MockCommand();
            var button = new Button();
            button.IsEnabled = true;

            mockCommand.CanExecuteReturnValue = false;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            Assert.IsFalse(button.IsEnabled);
        }
コード例 #15
0
        public void BehaviorDoesNotPreventButtonFromBeingGarbageCollected()
        {
            var mockCommand = new MockCommand();
            var button = new Button();

            button.SetValue(CommandProperties.CommandProperty, mockCommand);

            WeakReference buttonReference = new WeakReference(button);

            button = null;
            GC.Collect();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.IsFalse(buttonReference.IsAlive);
        }
コード例 #16
0
        public void WhenDesubscribedDontCallCanExecute()
        {
            var mockCommand = new MockCommand();
            var button = new Button();
            button.IsEnabled = true;
            button.SetValue(CommandProperties.CommandProperty, mockCommand);
            button.SetValue(CommandProperties.CommandProperty, null);

            mockCommand.CanExecuteCalled = false;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsFalse(mockCommand.CanExecuteCalled);
        }