public void Event_on_a_subproperty_shall_be_removed_and_readded_if_subproperty_is_changed() { TestObject SubProperty1 = new TestObject(); TestObject SubProperty2 = new TestObject(); TestObject TestObject = new TestObject { SubProperty = SubProperty1 }; TestProxy3 TestProxy = new TestProxy3(TestObject); bool EventCalled; TestProxy.PropertyChanged += (_, args) => EventCalled = args.PropertyName == "Property"; TestObject.SubProperty = SubProperty2; EventCalled = false; TestProxy.Property.ToString(); //For lazy & OnDemand //old subproperty shall be removed SubProperty1.Property = 42; Assert.IsFalse(EventCalled); TestProxy.Property.ToString(); //For lazy & OnDemand //new subproperty shall be added SubProperty2.Property = 42; Assert.IsTrue(EventCalled); TestProxy.Property.ToString(); //For lazy & OnDemand //shall work if new value is null TestObject.SubProperty = null; Assert.Throws <NullReferenceException>(() => TestProxy.Property.ToString()); }
public void Event_shall_be_routed_through_proxy_on_subproperty() { bool EventCalled = false; TestObject TestObject = new TestObject { SubProperty = new TestObject() }; TestProxy3 TestProxy = new TestProxy3(TestObject); TestProxy.PropertyChanged += (_, args) => EventCalled = args.PropertyName == "Property"; TestProxy.Property.ToString(); //For lazy & OnDemand TestObject.SubProperty.Property = 42; Assert.IsTrue(EventCalled); Assert.AreEqual(42, TestProxy.Property); }