comparison UnitTests/CS/EditableObjects/NotifyPropertyChangedTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.ComponentModel;
3 using System.Reflection;
4 using BLToolkit.Reflection;
5 using BLToolkit.TypeBuilder;
6 using NUnit.Framework;
7
8 namespace EditableObjects
9 {
10 [TestFixture]
11 public class NotifyPropertyChangedTest
12 {
13 [PropertyChanged]
14 public abstract class ObservableObject : INotifyPropertyChanged, IPropertyChanged
15 {
16 #region Implementation of IPropertyChanged
17
18 public event PropertyChangedEventHandler PropertyChanged;
19
20 #endregion
21
22 public abstract int ID { get; set; }
23 public abstract string Name { get; set; }
24 public abstract int Seconds { get; set; }
25
26 public static ObservableObject CreateInstance()
27 {
28 return TypeAccessor<ObservableObject>.CreateInstance();
29 }
30
31 #region Implementation of IPropertyChanged
32
33 void IPropertyChanged.OnPropertyChanged(PropertyInfo propertyInfo)
34 {
35 OnPropertyChanged(propertyInfo.Name);
36 }
37
38 #endregion
39
40 protected internal virtual void OnPropertyChanged(string propertyName)
41 {
42 if (PropertyChanged != null)
43 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
44 }
45 }
46
47 [Test]
48 public void TestPropertyChangedFired()
49 {
50 ObservableObject obj = ObservableObject.CreateInstance();
51 bool propertyChangedFired = false;
52 obj.PropertyChanged += delegate { propertyChangedFired = true; };
53
54 obj.Name = "this should fire PropertyChanged event";
55 Assert.That(propertyChangedFired);
56 }
57 }
58 }