コード例 #1
0
        public void ShouldGiveNewValueToValueChangedCallbackWhenValueChanges()
        {
            var    entity  = new NotifyingEntity();
            var    adapter = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);
            object value   = null;

            adapter.ValueChangedCallback = newValue => value = newValue;
            entity.Property = 3;
            Assert.AreEqual(3, value);
        }
コード例 #2
0
        public void ShouldNotNotifyAboutValueChangesAfterBeingDisposed()
        {
            var entity            = new NotifyingEntity();
            var adapter           = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);
            var callbackCallCount = 0;

            adapter.ValueChangedCallback = newValue => ++ callbackCallCount;
            adapter.Dispose();
            entity.Property = 3;
            Assert.AreEqual(0, callbackCallCount);
        }
コード例 #3
0
        public void ShouldCallValueChangedCallbackWhenValueChanges()
        {
            var entity         = new NotifyingEntity();
            var adapter        = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);
            var callbackCalled = false;

            adapter.ValueChangedCallback = newValue => callbackCalled = true;

            entity.Property = 5;

            Assert.IsTrue(callbackCalled);
        }
コード例 #4
0
        public void ShouldNotCallValueChangedCallbackWhenSettingValue()
        {
            var  entity         = new NotifyingEntity();
            var  adapter        = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);
            bool callbackCalled = false;

            adapter.ValueChangedCallback = newValue => { callbackCalled = true; };

            adapter.SetValue(5);

            Assert.IsFalse(callbackCalled);
        }
コード例 #5
0
        public void ShouldNotUseOldValueChangedCallbackIfGivenNewOne()
        {
            var entity            = new NotifyingEntity();
            var adapter           = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);
            var callbackCallCount = 0;

            adapter.ValueChangedCallback = newValue => ++ callbackCallCount;
            entity.Property = 5;
            adapter.ValueChangedCallback = newValue => { };
            entity.Property = 3;
            Assert.AreEqual(1, callbackCallCount);
        }
コード例 #6
0
        public void ShouldDoNothingWithoutValueChangedCallbackWhenValueChanges()
        {
            var entity  = new NotifyingEntity();
            var adapter = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);

            try
            {
                entity.Property = 5;
            }
            catch
            {
                Assert.Fail();
            }
        }
コード例 #7
0
        public void ShouldDoNothingAfterValueChangedCallbackIsSetToNullWhenValueChanges()
        {
            var entity  = new NotifyingEntity();
            var adapter = new ClrPropertyAdapter(entity, NotifyingEntity.PropertyInfo);

            adapter.ValueChangedCallback = newValue => { };
            adapter.ValueChangedCallback = null;
            try
            {
                entity.Property = 3;
            }
            catch
            {
                Assert.Fail();
            }
        }