예제 #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);
 }