public void ExceptionTest() { AssertThrow <ArgumentNullException>( () => TwoWayBinding.Create((IProperty <Source, string>)null, this.target.GetProperty(o => o.Property)).Dispose(), () => TwoWayBinding.Create(this.source.GetProperty(o => o.Property), (IProperty <Target, string>)null).Dispose(), () => TwoWayBinding.Create(this.source.GetProperty(o => o.Property), null, this.target.GetProperty(o => o.Property), v => v).Dispose(), () => TwoWayBinding.Create(this.source.GetProperty(o => o.Property), v => v, this.target.GetProperty(o => o.Property), null).Dispose()); }
public void TwoWayBindingTest() { this.AssertValues(this.source.Property, 0, this.target.Property, 0); Assert.AreNotEqual(this.source.Property, this.target.Property); var value = this.source.Property; int sourceOriginated = 0; int targetOriginated = 0; using (var binding = TwoWayBinding.Create( this.source.GetProperty(o => o.Property), this.target.GetProperty(o => o.Property))) { binding.ChangeOriginatedAtSource += (s, e) => { Assert.AreEqual(binding, s); Assert.AreEqual(binding.Source, e.Property); ++sourceOriginated; }; binding.ChangeOriginatedAtTarget += (s, e) => { Assert.AreEqual(binding, s); Assert.AreEqual(binding.Target, e.Property); ++targetOriginated; }; this.AssertValues(value, 0, value, 1); AssertOriginatedCounts(0, sourceOriginated, 0, targetOriginated); this.source.Property = value = GetRandomString(); this.AssertValues(value, 1, value, 2); AssertOriginatedCounts(1, sourceOriginated, 0, targetOriginated); this.target.Property = value = GetRandomString(); this.AssertValues(value, 2, value, 3); AssertOriginatedCounts(1, sourceOriginated, 1, targetOriginated); } this.AssertValues(value, 2, value, 3); AssertOriginatedCounts(1, sourceOriginated, 1, targetOriginated); this.source.Property.Ignore(); var targetValue = this.target.Property; var sourceValue = this.source.Property = GetRandomString(); this.AssertValues(sourceValue, 3, targetValue, 3); AssertOriginatedCounts(1, sourceOriginated, 1, targetOriginated); this.target.Property = targetValue = GetRandomString(); this.AssertValues(sourceValue, 3, targetValue, 4); AssertOriginatedCounts(1, sourceOriginated, 1, targetOriginated); }