public void DirtyStateEventIsRaised() { object eventSender = null; DirtyStateChangedEventHandlerArgs dirtyStateChangedEventHandlerArgs = null; var nbCalls = 0; _modelDirtyDetector.DirtyStateChanged += (sender, args) => { eventSender = sender; dirtyStateChangedEventHandlerArgs = args; nbCalls++; }; _modelDirtyDetector.Start(_testingClassA); Assert.AreEqual(nbCalls, 0); Assert.IsNull(eventSender); Assert.IsNull(dirtyStateChangedEventHandlerArgs); _testingClassA.Bool = !_testingClassA.Bool; Assert.AreEqual(nbCalls, 1); Assert.AreSame(_modelDirtyDetector, eventSender); Assert.IsNotNull(dirtyStateChangedEventHandlerArgs); Assert.IsTrue(dirtyStateChangedEventHandlerArgs.IsDirty); Assert.AreSame(dirtyStateChangedEventHandlerArgs.ObservedModel, _testingClassA); _testingClassA.Bool = !_testingClassA.Bool; Assert.AreEqual(nbCalls, 2); Assert.AreSame(_modelDirtyDetector, eventSender); Assert.IsNotNull(dirtyStateChangedEventHandlerArgs); Assert.AreSame(dirtyStateChangedEventHandlerArgs.ObservedModel, _testingClassA); Assert.IsFalse(dirtyStateChangedEventHandlerArgs.IsDirty); }
private void NotifyDirtyStateChanged(DirtyStateChangedEventHandlerArgs args) { var handler = DirtyStateChanged; if (handler != null) { handler(this, args); } }