public void SuccessiveRegisterAndRemoveMediator() { // Get the Singleton View instance IView view = View.Instance; // Create and register the test mediator, // but not so we have a reference to it IMediator viewTestMediator = new ViewTestMediator(Thread.CurrentThread.Name, this); string name = viewTestMediator.MediatorName; view.RegisterMediator(viewTestMediator); // test that we can retrieve it Assert.IsTrue(view.RetrieveMediator(name) is ViewTestMediator, "Expecting view.retrieveMediator( ViewTestMediator.NAME ) is ViewTestMediator"); // Remove the Mediator view.RemoveMediator(name); // test that retrieving it now returns null Assert.IsNull(view.RetrieveMediator(name), "Expecting view.retrieveMediator( ViewTestMediator.NAME ) == null"); // test that removing the mediator again once its gone doesn't cause crash try { view.RemoveMediator(name); } catch { Assert.Fail("Expecting view.removeMediator( ViewTestMediator.NAME ) doesn't crash", null); } // Create and register another instance of the test mediator, viewTestMediator = new ViewTestMediator(Thread.CurrentThread.Name, this); name = viewTestMediator.MediatorName; view.RegisterMediator(viewTestMediator); Assert.IsTrue(view.RetrieveMediator(name) is ViewTestMediator, "Expecting view.retrieveMediator( ViewTestMediator.NAME ) is ViewTestMediator"); // Remove the Mediator view.RemoveMediator(name); // test that retrieving it now returns null Assert.IsNull(view.RetrieveMediator(name), "Expecting view.retrieveMediator( ViewTestMediator.NAME ) == null"); }
public void RegisterAndRetrieveMediator() { // Get the Singleton View instance IView view = View.Instance; // Create and register the test mediator IMediator viewTestMediator = new ViewTestMediator(Thread.CurrentThread.Name, this); string name = viewTestMediator.MediatorName; view.RegisterMediator(viewTestMediator); // Retrieve the component IMediator mediator = view.RetrieveMediator(name); // test assertions Assert.IsTrue(mediator is ViewTestMediator, "Expecting comp is ViewTestMediator"); // Remove our mediator view.RemoveMediator(name); }
/** * Tests registering a Mediator for 3 different notifications, removing the * Mediator from the View, and seeing that neither notification causes the * Mediator to be notified. Added for the fix deployed in version 1.7 */ public void TestRemoveMediatorAndSubsequentNotify() { // Get the Singleton View instance IView view = View.Instance; // Create and register the test mediator to be removed. view.RegisterMediator(new ViewTestMediator2(this)); // Create and register the Mediator to remain IMediator viewTestMediator = new ViewTestMediator(Thread.CurrentThread.Name, this); string name = viewTestMediator.MediatorName; view.RegisterMediator(viewTestMediator); // test that notifications work view.NotifyObservers(new Notification(NOTE1)); Assert.True(lastNotification == NOTE1, "Expecting lastNotification == NOTE1"); view.NotifyObservers(new Notification(NOTE2)); Assert.True(lastNotification == NOTE2, "Expecting lastNotification == NOTE2"); // Remove the Mediator view.RemoveMediator(ViewTestMediator2.NAME); // test that retrieving it now returns null Assert.Null(view.RetrieveMediator(ViewTestMediator2.NAME), "Expecting view.retrieveMediator(ViewTestMediator2.NAME) == null"); // test that notifications no longer work // (ViewTestMediator2 is the one that sets lastNotification // on this component, and ViewTestMediator) lastNotification = null; view.NotifyObservers(new Notification(NOTE1)); Assert.True(lastNotification != NOTE1, "Expecting lastNotification != NOTE1"); view.NotifyObservers(new Notification(NOTE2)); Assert.True(lastNotification != NOTE2, "Expecting lastNotification != NOTE2"); Cleanup(); }
public void RemoveMediatorAndSubsequentNotify() { // Get the Singleton View instance IView view = View.Instance; // Create and register the test mediator to be removed. view.RegisterMediator(new ViewTestMediator2(this)); // Create and register the Mediator to remain IMediator viewTestMediator = new ViewTestMediator(Thread.CurrentThread.Name, this); string name = viewTestMediator.MediatorName; view.RegisterMediator(viewTestMediator); // test that notifications work view.NotifyObservers(new Notification(NOTE1)); Assert.IsTrue(lastNotification == NOTE1, "Expecting lastNotification == NOTE1"); view.NotifyObservers(new Notification(NOTE2)); Assert.IsTrue(lastNotification == NOTE2, "Expecting lastNotification == NOTE2"); // Remove the Mediator view.RemoveMediator(ViewTestMediator2.NAME); // test that retrieving it now returns null Assert.IsNull(view.RetrieveMediator(ViewTestMediator2.NAME), "Expecting view.retrieveMediator(ViewTestMediator2.NAME) == null"); // test that notifications no longer work // (ViewTestMediator2 is the one that sets lastNotification // on this component, and ViewTestMediator) lastNotification = null; view.NotifyObservers(new Notification(NOTE1)); Assert.IsTrue(lastNotification != NOTE1, "Expecting lastNotification != NOTE1"); view.NotifyObservers(new Notification(NOTE2)); Assert.IsTrue(lastNotification != NOTE2, "Expecting lastNotification != NOTE2"); Cleanup(); }