示例#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();
            }
        }