Exemplo n.º 1
0
        public void TestRaiseProperty()
        {
            int eventCount = 0;
            var bindable   = new DummyBindable();

            Assert.IsFalse(bindable.IsChanged);
            bindable.PropertyChanged += (sender, e) => eventCount++;
            bindable.Raise("test");
            Assert.IsTrue(bindable.IsChanged);
            Assert.AreEqual(1, eventCount);
        }
Exemplo n.º 2
0
        public void TestClone_CloneIgnore_BindableBase()
        {
            var bindableBase = new DummyBindable();

            bindableBase.IgnoreEvents = true;
            bindableBase.IsChanged    = true;
            var bindableBase2 = bindableBase.Clone();

            Assert.IsTrue(bindableBase2.IgnoreEvents);
            Assert.IsTrue(bindableBase2.IsChanged);
            bindableBase.IgnoreEvents = false;
            bindableBase.IsChanged    = false;
            bindableBase2             = bindableBase.Clone();
            Assert.IsFalse(bindableBase2.IgnoreEvents);
            Assert.IsFalse(bindableBase2.IsChanged);
        }
Exemplo n.º 3
0
        public void TestIgnoreEvents()
        {
            // Arrange
            int eventCount = 0;
            var bindable   = new DummyBindable();

            Assert.IsFalse(bindable.IsChanged);
            bindable.PropertyChanged += (sender, e) => eventCount++;

            // Act
            bindable.IgnoreEvents = true;
            bindable.Raise("test");
            bindable.IgnoreEvents = false;

            // Assert
            Assert.IsTrue(bindable.IsChanged);
            Assert.AreEqual(0, eventCount);
        }
Exemplo n.º 4
0
        public void Test_Success_DeferPropertyChanged_順序通りに実行できること()
        {
            // arrange
            var  b       = new DummyBindable();                     // テスト対象のオブジェクト
            bool isScope = false;                                   // スコープを通過したかどうか
            int  index   = 0;                                       // プロパティの変更順序インデックス
            var  result  = new Dictionary <int, string>();          // プロパティの実行順序の連想配列

            b.PropertyChanged += (sender, e) =>
            {
                Assert.IsTrue(isScope);
                result[index] = e.PropertyName;
                index++;
            };

            // act
            using (b.DeferPropertyChanged())
            {
                isScope = true;

                b.DateTime  = DateTime.Now;
                b.DayOfWeek = DayOfWeek.Thursday;
                b.Value     = 123;
                b.Text      = "Test";

                isScope = false;
            }

            // assert
            // 順番にチェックするためにインデックスを初期化する。
            index = 0;
            Assert.IsTrue(result[index++] == "DateTime");
            Assert.IsTrue(result[index++] == "DayOfWeek");
            Assert.IsTrue(result[index++] == "Value");
            Assert.IsTrue(result[index++] == "Text");
            Debug.Print(string.Join(Environment.NewLine, result.Select(x => $"{x.Key}, プロパティ名:{x.Value}")));
        }
Exemplo n.º 5
0
        public void Test_Success_DeferPropertyChanged_順序通りに実行できること()
        {
            // arrange
            var b        = new DummyBindable();                     // テスト対象のオブジェクト
            bool isScope = false;                                   // スコープを通過したかどうか
            int index    = 0;                                       // プロパティの変更順序インデックス
            var result   = new Dictionary<int, string>();           // プロパティの実行順序の連想配列
            b.PropertyChanged += (sender, e) =>
                                 {
                                     Assert.IsTrue(isScope);
                                     result[index] = e.PropertyName;
                                     index++;
                                 };

            // act
            using (b.DeferPropertyChanged())
            {
                isScope = true;

                b.DateTime  = DateTime.Now;
                b.DayOfWeek = DayOfWeek.Thursday;
                b.Value     = 123;
                b.Text      = "Test";

                isScope = false;
            }

            // assert
            // 順番にチェックするためにインデックスを初期化する。
            index = 0;
            Assert.IsTrue(result[index++] == "DateTime");
            Assert.IsTrue(result[index++] == "DayOfWeek");
            Assert.IsTrue(result[index++] == "Value");
            Assert.IsTrue(result[index++] == "Text");
            Debug.Print(string.Join(Environment.NewLine, result.Select(x => $"{x.Key}, プロパティ名:{x.Value}")));
        }