public void ObserverAccessors() { // Create observer with null args, then // use accessors to set notification method and context IObserver observer = new Observer(null, null); observer.NotifyContext = this; observer.NotifyMethod = "observerTestMethod"; // create a test event, setting a payload value and notify // the observer with it. since the observer is this class // and the notification method is observerTestMethod, // successful notification will result in our local // observerTestVar being set to the value we pass in // on the note body. INotification note = new Notification("ObserverTestNote", 10); observer.NotifyObserver(note); // test assertions Assert.IsTrue(observerTestVar == 10, "Expecting observerTestVar = 10"); }
public void ObserverConstructor() { // Create observer passing in notification method and context IObserver observer = new Observer("observerTestMethod", this); // create a test note, setting a body value and notify // the observer with it. since the observer is this class // and the notification method is observerTestMethod, // successful notification will result in our local // observerTestVar being set to the value we pass in // on the note body. INotification note = new Notification("ObserverTestNote", 5); observer.NotifyObserver(note); // test assertions Assert.IsTrue(observerTestVar == 5, "Expecting observerTestVar = 5"); }