Exemplo n.º 1
0
        public void RemoveControllerAndSubsequentNotify()
        {
            // Get the Singleton MainController instance
              			IMainController mainController = MainController.Instance;

            // Create and register the test Controller to be removed.
            mainController.RegisterController(new MainControllerTestController2(this));

            // Create and register the Controller to remain
            IController mainControllerTestController = new MainControllerTestController(Thread.CurrentThread.Name, this);
            mainController.RegisterController(mainControllerTestController);

            // test that notifications work
               			mainController.NotifyObservers(new Notification(NOTE1));
            Assert.IsTrue(lastNotification == NOTE1, "Expecting lastNotification == NOTE1");

            mainController.NotifyObservers(new Notification(NOTE2));
            Assert.IsTrue(lastNotification == NOTE2, "Expecting lastNotification == NOTE2");

            // Remove the Controller
            mainController.RemoveController(MainControllerTestController2.NAME);

            // test that retrieving it now returns null
               			Assert.IsNull(mainController.RetrieveController(MainControllerTestController2.NAME), "Expecting MainController.retrieveController(MainControllerTestController2.NAME) == null");

            // test that notifications no longer work
            // (MainControllerTestController2 is the one that sets lastNotification
            // on this component, and MainControllerTestController)
            lastNotification = null;

            mainController.NotifyObservers(new Notification(NOTE1));
            Assert.IsTrue(lastNotification != NOTE1, "Expecting lastNotification != NOTE1");

            mainController.NotifyObservers(new Notification(NOTE2));
            Assert.IsTrue(lastNotification != NOTE2, "Expecting lastNotification != NOTE2");

            Cleanup();
        }
Exemplo n.º 2
0
        public void SuccessiveRegisterAndRemoveController()
        {
            // Get the Singleton MainController instance
              			IMainController mainController = MainController.Instance;

            // Create and register the test Controller,
            // but not so we have a reference to it
            IController MainControllerTestController = new MainControllerTestController(Thread.CurrentThread.Name, this);
            string name = MainControllerTestController.Name;
            mainController.RegisterController(MainControllerTestController);

            // test that we can retrieve it
            Assert.IsTrue(mainController.RetrieveController(name) is MainControllerTestController, "Expecting MainController.retrieveController( MainControllerTestController.NAME ) is MainControllerTestController");

            // Remove the Controller
            mainController.RemoveController(name);

            // test that retrieving it now returns null
            Assert.IsNull(mainController.RetrieveController(name), "Expecting MainController.retrieveController( MainControllerTestController.NAME ) == null");

            // test that removing the Controller again once its gone doesn't cause crash
            try
            {
                mainController.RemoveController(name);
            }
            catch
            {
                Assert.Fail("Expecting MainController.removeController( MainControllerTestController.NAME ) doesn't crash", null);
            }

            // Create and register another instance of the test Controller,
            MainControllerTestController = new MainControllerTestController(Thread.CurrentThread.Name, this);
            name = MainControllerTestController.Name;
            mainController.RegisterController(MainControllerTestController);

            Assert.IsTrue(mainController.RetrieveController(name) is MainControllerTestController, "Expecting MainController.retrieveController( MainControllerTestController.NAME ) is MainControllerTestController");

            // Remove the Controller
            mainController.RemoveController(name);

            // test that retrieving it now returns null
            Assert.IsNull(mainController.RetrieveController(name), "Expecting MainController.retrieveController( MainControllerTestController.NAME ) == null");
        }
Exemplo n.º 3
0
        public void RegisterAndRetrieveController()
        {
            // Get the Singleton MainController instance
              			IMainController mainController = MainController.Instance;

            // Create and register the test Controller
            IController MainControllerTestController = new MainControllerTestController(Thread.CurrentThread.Name, this);
            string name = MainControllerTestController.Name;
            mainController.RegisterController(MainControllerTestController);

            // Retrieve the component
            IController Controller = mainController.RetrieveController(name);

            // test assertions
               			Assert.IsTrue(Controller is MainControllerTestController, "Expecting comp is MainControllerTestController");
            // Remove our Controller
            mainController.RemoveController(name);
        }