Beispiel #1
0
        public void WhenMemberChainContainsCastingOperator_ThenBuildProperListener()
        {
            var target = new NotifyingSampleObject();

            var listener = new PropertyChangedHelper().BuildListener(target, x => (x.Child as NotifyingSampleObject2).Child, _dummyCallback);

            Assert.IsTrue(listener != null);
        }
Beispiel #2
0
        public void WhenMemberChainContainsMethod_ThenThrowNotSupportedExceptionOnBuilding()
        {
            var target = new NotifyingSampleObject();

            Assert.ThrowsException <NotSupportedException>(() =>
            {
                var listener = new PropertyChangedHelper().BuildListener(target, x => x.SampleMethod().NotNotifyingChild, _dummyCallback);
            });
        }
Beispiel #3
0
        public void ExecutionContext_ExecutionState()
        {
            GeneticAlgorithm algorithm = Mock.Of <GeneticAlgorithm>();
            ExecutionContext context   = new ExecutionContext(algorithm);

            PropertyChangedHelper.VerifyPropertyChangedEvent(
                context, nameof(ExecutionContext.ExecutionState), ExecutionState.Running,
                v => context.ExecutionState = v, () => context.ExecutionState);
        }
Beispiel #4
0
        public void ExecutionContext_AlgorithmException()
        {
            GeneticAlgorithm algorithm = Mock.Of <GeneticAlgorithm>();
            ExecutionContext context   = new ExecutionContext(algorithm);

            PropertyChangedHelper.VerifyPropertyChangedEvent(
                context, nameof(ExecutionContext.AlgorithmException), new ArgumentException(),
                v => context.AlgorithmException = v, () => context.AlgorithmException);
        }
Beispiel #5
0
        public void PropertyNotifyExtensionsRaiseEvent()
        {
            bool changedEventRaised  = false;
            bool changingEventRaised = false;
            var  myobj = new PropertyChangedHelper();

            myobj.PropertyChanged  += (sender, args) => changedEventRaised = true;
            myobj.PropertyChanging += (sender, args) => changingEventRaised = true;
            myobj.Name              = "im trying to raise events";

            Assert.IsTrue(changedEventRaised);
            Assert.IsTrue(changingEventRaised);
        }
Beispiel #6
0
        public void WhenObservedPropertyChanges_ThenCallbackIsInvoked()
        {
            bool wasCalled = false;
            var  target    = new NotifyingSampleObject()
            {
                Child = new NotifyingSampleObject()
                {
                    Value = "foo"
                }
            };
            var listener = new PropertyChangedHelper().BuildListener(target, x => x.Child.Value, () => { wasCalled = true; });

            target.Child.Value = "bar";

            Assert.IsTrue(wasCalled);
        }
Beispiel #7
0
        public void WhenListenerIsDisposed_ThenCallbackIsNoLongerInvoked()
        {
            bool wasCalled = false;
            var  target    = new NotifyingSampleObject()
            {
                Child = new NotifyingSampleObject()
                {
                    Value = "foo"
                }
            };

            var listener = new PropertyChangedHelper().BuildListener(target, x => x.Child.Value, () => wasCalled = true);

            listener.Dispose();

            target.Child.Value = "bar";

            Assert.IsFalse(wasCalled);
        }
 protected void OnPropertyChanged <T>(Expression <Func <T> > propertyExpression)
 {
     PropertyChangedHelper.RaisePropertyChanged(this, propertyExpression, PropertyChanged);
 }