Exemplo n.º 1
0
        public void CanExecuteChangedTest1()
        {
            int             canExecute             = 0;
            int             confirmationCanExecute = 0;
            DelegateCommand command = new DelegateCommand(
                () => { },
                () => {
                canExecute++;
                return(true);
            }
                );
            ConfirmationBehavior b = new ConfirmationBehavior();

            b.ConfirmationCommand.CanExecuteChanged += (d, e) => {
                confirmationCanExecute++;
            };
            b.Command = command;
            Assert.AreEqual(0, canExecute);
            Assert.AreEqual(1, confirmationCanExecute);
            Button control = new Button();

            Interaction.GetBehaviors(control).Add(b);
            Assert.AreEqual(1, canExecute);
            Assert.AreEqual(1, confirmationCanExecute);
            Assert.AreEqual(b.ConfirmationCommand, control.Command);
        }
Exemplo n.º 2
0
        public void ExecuteAndCommandParameterTest()
        {
            var    service = new TestMessageBoxService();
            object executeCommandParameter    = null;
            object canExecuteCommandParameter = null;
            DelegateCommand <object> command  = new DelegateCommand <object>(
                x => {
                executeCommandParameter = x;
            }, x => {
                canExecuteCommandParameter = x;
                return(true);
            });
            ConfirmationBehavior b = new ConfirmationBehavior();

            b.MessageBoxService = service;
            Button control = new Button();

            Interaction.GetBehaviors(control).Add(b);
            b.Command = command;
            object controlCommandParameter = new object();

            control.CommandParameter = controlCommandParameter;
            Assert.IsNull(executeCommandParameter);
            control.Command.Execute(controlCommandParameter);
            Assert.AreEqual(controlCommandParameter, executeCommandParameter);
            Assert.AreEqual(controlCommandParameter, canExecuteCommandParameter);
            object confirmationBehaviorCommandParameter = new object();

            b.CommandParameter = confirmationBehaviorCommandParameter;
            Assert.AreEqual(controlCommandParameter, executeCommandParameter);
            Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter);
            control.Command.Execute(controlCommandParameter);
            Assert.AreEqual(confirmationBehaviorCommandParameter, executeCommandParameter);
            Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter);
        }
Exemplo n.º 3
0
        public void GetActualServiceTest1()
        {
            var b       = new ConfirmationBehavior();
            var service = CreateMessageService();

            b.MessageBoxService = service;
            Assert.AreEqual(service, b.GetActualService());
        }
 public void SetAssociatedObjectCommandPropertyTest3() {
     TestControl1 control = new TestControl1();
     var b = new ConfirmationBehavior();
     Interaction.GetBehaviors(control).Add(b);
     var command = new DelegateCommand(() => { });
     var res = b.SetAssociatedObjectCommandProperty(command);
     Assert.IsTrue(res);
     Assert.AreEqual(command, control.Command);
 }
Exemplo n.º 5
0
        public void SetAssociatedObjectCommandPropertyTest3()
        {
            TestControl1 control = new TestControl1();
            var          b       = new ConfirmationBehavior();

            Interaction.GetBehaviors(control).Add(b);
            var command = new DelegateCommand(() => { });
            var res     = b.SetAssociatedObjectCommandProperty(command);

            Assert.IsTrue(res);
            Assert.AreEqual(command, control.Command);
        }
 public void GetActualServiceTest2() {
     UserControl root = new UserControl();
     var service = CreateMessageService();
     Interaction.GetBehaviors(root).Add(service);
     var viewModel = new TestViewModelBase();
     root.DataContext = viewModel;
     Button button = new Button();
     var b = new ConfirmationBehavior();
     Interaction.GetBehaviors(button).Add(b);
     root.Content = button;
     Assert.AreEqual(service, viewModel.MessageBoxService);
     Assert.AreEqual(service, b.GetActualService());
 }
Exemplo n.º 7
0
        public void ExecuteAndMessageBoxServiceTest()
        {
            int                   executeCount = 0;
            DelegateCommand       command      = new DelegateCommand(() => executeCount++, () => true);
            TestMessageBoxService service      = new TestMessageBoxService();
            Button                control      = new Button();
            ConfirmationBehavior  b            = new ConfirmationBehavior();

            b.Command = command;
            Interaction.GetBehaviors(control).Add(b);
            b.MessageBoxService = service;
            control.Command.Execute(null);
            Assert.AreEqual(1, executeCount);
            Assert.AreEqual(1, service.ShowCount);
            Assert.AreEqual("Confirmation", service.Caption);
            Assert.AreEqual("Do you want to perform this action?", service.MessageBoxTest);
#if !SILVERLIGHT
            Assert.AreEqual(MessageIcon.None, service.Icon);
            Assert.AreEqual(MessageButton.YesNo, service.Button);
#else
            Assert.AreEqual(MessageButton.OKCancel, service.Button);
#endif
            Assert.AreEqual(MessageResult.None, service.DefaultResult);

            b.MessageText  = "MessageText";
            b.MessageTitle = "MessageTitle";
#if !SILVERLIGHT
            b.MessageIcon = MessageBoxImage.Hand;
#endif
            b.MessageButton        = MessageBoxButton.OKCancel;
            b.MessageDefaultResult = MessageBoxResult.Cancel;
            service.Result         = MessageResult.OK;
            control.Command.Execute(null);
            Assert.AreEqual(2, executeCount);
            Assert.AreEqual(2, service.ShowCount);
            Assert.AreEqual("MessageTitle", service.Caption);
            Assert.AreEqual("MessageText", service.MessageBoxTest);
#if !SILVERLIGHT
            Assert.AreEqual(MessageIcon.Hand, service.Icon);
#endif
            Assert.AreEqual(MessageButton.OKCancel, service.Button);
            Assert.AreEqual(MessageResult.Cancel, service.DefaultResult);

            service.Result = MessageResult.Cancel;
            control.Command.Execute(null);
            Assert.AreEqual(2, executeCount);
            Assert.AreEqual(3, service.ShowCount);
        }
Exemplo n.º 8
0
        public void GetActualServiceTest2()
        {
            UserControl root    = new UserControl();
            var         service = CreateMessageService();

            Interaction.GetBehaviors(root).Add(service);
            var viewModel = new TestViewModelBase();

            root.DataContext = viewModel;
            Button button = new Button();
            var    b      = new ConfirmationBehavior();

            Interaction.GetBehaviors(button).Add(b);
            root.Content = button;
            Assert.AreEqual(service, viewModel.MessageBoxService);
            Assert.AreEqual(service, b.GetActualService());
        }
Exemplo n.º 9
0
        public void CanExecuteChangedTest2()
        {
            Button          control          = new Button();
            bool            isCommandEnabled = true;
            DelegateCommand command          = DelegateCommandFactory.Create(
                () => { },
                () => {
                return(isCommandEnabled);
            }, false);
            ConfirmationBehavior b = new ConfirmationBehavior();

            b.Command = command;
            Interaction.GetBehaviors(control).Add(b);
            Assert.IsTrue(control.IsEnabled);
            isCommandEnabled = false;
            command.RaiseCanExecuteChanged();
            Assert.IsFalse(control.IsEnabled);
        }
Exemplo n.º 10
0
        public void DisableConfirmationMessage()
        {
            int                   executeCount = 0;
            DelegateCommand       command      = new DelegateCommand(() => executeCount++, () => true);
            TestMessageBoxService service      = new TestMessageBoxService();
            Button                control      = new Button();
            ConfirmationBehavior  b            = new ConfirmationBehavior();

            b.Command = command;
            Interaction.GetBehaviors(control).Add(b);
            b.MessageBoxService         = service;
            b.EnableConfirmationMessage = false;
            control.Command.Execute(null);
            Assert.AreEqual(1, executeCount);
            Assert.AreEqual(0, service.ShowCount);
            Assert.IsNull(service.Caption);
            Assert.IsNull(service.MessageBoxTest);
        }
 public void GetActualServiceTest1() {
     var b = new ConfirmationBehavior();
     var service = CreateMessageService();
     b.MessageBoxService = service;
     Assert.AreEqual(service, b.GetActualService());
 }
 public void DisableConfirmationMessage() {
     int executeCount = 0;
     DelegateCommand command = new DelegateCommand(() => executeCount++, () => true);
     TestMessageBoxService service = new TestMessageBoxService();
     Button control = new Button();
     ConfirmationBehavior b = new ConfirmationBehavior();
     b.Command = command;
     Interaction.GetBehaviors(control).Add(b);
     b.MessageBoxService = service;
     b.EnableConfirmationMessage = false;
     control.Command.Execute(null);
     Assert.AreEqual(1, executeCount);
     Assert.AreEqual(0, service.ShowCount);
     Assert.IsNull(service.Caption);
     Assert.IsNull(service.MessageBoxTest);
 }
        public void ExecuteAndMessageBoxServiceTest() {
            int executeCount = 0;
            DelegateCommand command = new DelegateCommand(() => executeCount++, () => true);
            TestMessageBoxService service = new TestMessageBoxService();
            Button control = new Button();
            ConfirmationBehavior b = new ConfirmationBehavior();
            b.Command = command;
            Interaction.GetBehaviors(control).Add(b);
            b.MessageBoxService = service;
            control.Command.Execute(null);
            Assert.AreEqual(1, executeCount);
            Assert.AreEqual(1, service.ShowCount);
            Assert.AreEqual("Confirmation", service.Caption);
            Assert.AreEqual("Do you want to perform this action?", service.MessageBoxTest);
#if !SILVERLIGHT
            Assert.AreEqual(MessageIcon.None, service.Icon);
            Assert.AreEqual(MessageButton.YesNo, service.Button);
#else
            Assert.AreEqual(MessageButton.OKCancel, service.Button);
#endif
            Assert.AreEqual(MessageResult.None, service.DefaultResult);

            b.MessageText = "MessageText";
            b.MessageTitle = "MessageTitle";
#if !SILVERLIGHT
            b.MessageIcon = MessageBoxImage.Hand;
#endif
            b.MessageButton = MessageBoxButton.OKCancel;
            b.MessageDefaultResult = MessageBoxResult.Cancel;
            service.Result = MessageResult.OK;
            control.Command.Execute(null);
            Assert.AreEqual(2, executeCount);
            Assert.AreEqual(2, service.ShowCount);
            Assert.AreEqual("MessageTitle", service.Caption);
            Assert.AreEqual("MessageText", service.MessageBoxTest);
#if !SILVERLIGHT
            Assert.AreEqual(MessageIcon.Hand, service.Icon);
#endif
            Assert.AreEqual(MessageButton.OKCancel, service.Button);
            Assert.AreEqual(MessageResult.Cancel, service.DefaultResult);

            service.Result = MessageResult.Cancel;
            control.Command.Execute(null);
            Assert.AreEqual(2, executeCount);
            Assert.AreEqual(3, service.ShowCount);
        }
 public void ExecuteAndCommandParameterTest() {
     var service = new TestMessageBoxService();
     object executeCommandParameter = null;
     object canExecuteCommandParameter = null;
     DelegateCommand<object> command = new DelegateCommand<object>(
         x => {
             executeCommandParameter = x;
         }, x => {
             canExecuteCommandParameter = x;
             return true;
         });
     ConfirmationBehavior b = new ConfirmationBehavior();
     b.MessageBoxService = service;
     Button control = new Button();
     Interaction.GetBehaviors(control).Add(b);
     b.Command = command;
     object controlCommandParameter = new object();
     control.CommandParameter = controlCommandParameter;
     Assert.IsNull(executeCommandParameter);
     control.Command.Execute(controlCommandParameter);
     Assert.AreEqual(controlCommandParameter, executeCommandParameter);
     Assert.AreEqual(controlCommandParameter, canExecuteCommandParameter);
     object confirmationBehaviorCommandParameter = new object();
     b.CommandParameter = confirmationBehaviorCommandParameter;
     Assert.AreEqual(controlCommandParameter, executeCommandParameter);
     Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter);
     control.Command.Execute(controlCommandParameter);
     Assert.AreEqual(confirmationBehaviorCommandParameter, executeCommandParameter);
     Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter);
 }
 public void CanExecuteChangedTest2() {
     Button control = new Button();
     bool isCommandEnabled = true;
     DelegateCommand command = DelegateCommandFactory.Create(
         () => { },
         () => {
             return isCommandEnabled;
         }, false);
     ConfirmationBehavior b = new ConfirmationBehavior();
     b.Command = command;
     Interaction.GetBehaviors(control).Add(b);
     Assert.IsTrue(control.IsEnabled);
     isCommandEnabled = false;
     command.RaiseCanExecuteChanged();
     Assert.IsFalse(control.IsEnabled);
 }
 public void CanExecuteChangedTest1() {
     int canExecute = 0;
     int confirmationCanExecute = 0;
     DelegateCommand command = new DelegateCommand(
         () => { },
         () => {
             canExecute++;
             return true;
         }
     );
     ConfirmationBehavior b = new ConfirmationBehavior();
     b.ConfirmationCommand.CanExecuteChanged += (d, e) => {
         confirmationCanExecute++;
     };
     b.Command = command;
     Assert.AreEqual(0, canExecute);
     Assert.AreEqual(1, confirmationCanExecute);
     Button control = new Button();
     Interaction.GetBehaviors(control).Add(b);
     Assert.AreEqual(1, canExecute);
     Assert.AreEqual(1, confirmationCanExecute);
     Assert.AreEqual(b.ConfirmationCommand, control.Command);
 }
 public void GetActualServiceTest3() {
     UserControl root = new UserControl();
     var viewModel = new TestViewModelBase();
     root.DataContext = viewModel;
     Button button = new Button();
     var b = new ConfirmationBehavior();
     Interaction.GetBehaviors(button).Add(b);
     root.Content = button;
     var service = b.GetActualService();
     var service2 = b.GetActualService();
     var service3 = Interaction.GetBehaviors(button).First(x => x is IMessageBoxService);
     Assert.AreEqual(service, service2);
     Assert.AreEqual(service, service3);
 }
 public void GetActualServiceTest4() {
     UserControl root = new UserControl();
     var service = CreateMessageService();
     Interaction.GetBehaviors(root).Add(service);
     Button button = new Button();
     var b = new ConfirmationBehavior();
     Interaction.GetBehaviors(button).Add(b);
     root.DataContext = new object();
     root.Content = button;
     var viewModel = new TestViewModelBase();
     button.DataContext = viewModel;
     var service2 = b.GetActualService();
     var service3 = b.GetActualService();
     Assert.IsNotNull(viewModel.MessageBoxService);
     Assert.AreNotEqual(service, service2);
     Assert.AreEqual(service2, service3);
     b.MessageBoxService = service;
     Assert.AreEqual(service, b.GetActualService());
 }