コード例 #1
0
        public void TestBindToAndUnbindFrom()
        {
            Bindable <Dummy> dummy  = new Bindable <Dummy>(new Dummy());
            Bindable <Dummy> dummy2 = new Bindable <Dummy>(new Dummy());

            Assert.AreNotEqual(dummy.Value, dummy2.Value);

            dummy2.BindTo(dummy);
            Assert.AreEqual(dummy.Value, dummy2.Value);

            dummy.Value = null;
            Assert.IsNull(dummy.Value);
            Assert.IsNull(dummy2.Value);

            dummy2.UnbindFrom(dummy);
            dummy.Value = new Dummy();
            Assert.IsNotNull(dummy.Value);
            Assert.IsNull(dummy2.Value);

            Bindable <SubDummy> subDummy = new Bindable <SubDummy>(new SubDummy());

            dummy.BindToRaw(subDummy);
            Assert.AreEqual(subDummy.Value, dummy.Value);

            subDummy.Value = new SubDummy();
            Assert.AreEqual(subDummy.Value, dummy.Value);

            dummy.UnbindFromRaw(subDummy);
            subDummy.Value = null;
            Assert.IsNull(subDummy.Value);
            Assert.IsNotNull(dummy.Value);

            dummy.Value = new Dummy();
            Assert.Throws(typeof(ArgumentException), () =>
            {
                subDummy.BindToRaw(dummy);
            });
        }