示例#1
0
        public void NotifyCommand()
        {
            var          callbackRaised = false;
            EventHandler eventHandler   = (s, a) =>
            {
                callbackRaised = true;
            };

            this.TestCommand.CanExecuteChanged += eventHandler;

            try
            {
                this.Property = "Alter Wert";

                var monitor = IListenerHostExtensions.Listen(this, v => v.Property)
                              .Notify(() => this.TestCommand);

                this.Property = "Neuer Wert";
                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Property)));

                Assert.IsTrue(callbackRaised);
            }
            finally
            {
                this.TestCommand.CanExecuteChanged -= eventHandler;
            }
        }
示例#2
0
        public void NotifyViewModel()
        {
            var callbackRaised = false;
            PropertyChangedEventHandler eventHandler = (s, a) =>
            {
                if (a.PropertyName == nameof(this.ViewModel.Property))
                {
                    callbackRaised = true;
                }
            };

            this.ViewModel.PropertyChanged += eventHandler;
            try
            {
                this.Property = "Alter Wert";

                var monitor = IListenerHostExtensions.Listen(this, v => v.Property)
                              .Notify(() => this.ViewModel.Property);

                this.Property = "Neuer Wert";

                Assert.IsFalse(callbackRaised);
                this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Property)));

                Assert.IsTrue(callbackRaised);
            }
            finally
            {
                this.ViewModel.PropertyChanged -= eventHandler;
            }
        }
示例#3
0
        public void NotifyViewModel_Fail_Type()
        {
            var target = new List <string>();

            var monitor = IListenerHostExtensions
                          .Listen(this, v => v.Property)
                          .Notify(() => target.Count);
        }
示例#4
0
        public void ListenExpression()
        {
            var monitor1 = IListenerHostExtensions.Listen(this, v => v.Property);

            Assert.IsNotNull(monitor1);

            var monitor2 = IListenerHostExtensions.Monitor(this, this.ViewModel, v => v.Property);

            Assert.IsNotNull(monitor2);

            Assert.AreNotEqual(monitor1, monitor2);
        }
示例#5
0
        public void CallBack()
        {
            var    callbackRaised = false;
            Action a = () => callbackRaised = true;

            this.Property = "Alter Wert";

            var monitor = IListenerHostExtensions.Listen(this, v => v.Property)
                          .Call(a);

            this.Property = "Neuer Wert";

            Assert.IsFalse(callbackRaised);
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Property)));

            Assert.IsTrue(callbackRaised);
        }
示例#6
0
 public void ListenExpression_Fail_Expression()
 {
     var monitor1 = IListenerHostExtensions.Listen(this, v => 42);
 }
示例#7
0
 public void NotifyViewModel_Fail_Expression()
 {
     var monitor = IListenerHostExtensions
                   .Listen(this, v => v.Property)
                   .Notify(() => 42);
 }