Пример #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);
        }
Пример #2
0
        public void WhenMemberChainContainsMethod_ThenThrowNotSupportedExceptionOnBuilding()
        {
            var target = new NotifyingSampleObject();

            Assert.ThrowsException <NotSupportedException>(() =>
            {
                var listener = new PropertyChangedHelper().BuildListener(target, x => x.SampleMethod().NotNotifyingChild, _dummyCallback);
            });
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #8
0
 protected void OnPropertyChanged <T>(Expression <Func <T> > propertyExpression)
 {
     PropertyChangedHelper.RaisePropertyChanged(this, propertyExpression, PropertyChanged);
 }