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); }
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); }
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); }
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}"))); }
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}"))); }