Exemplo n.º 1
0
        public void TestRegisterAndRemoveMediator()
        {
            // Get the Multiton View instance
            IView view = View.GetInstance("ViewTestKey5", () => new View("ViewTestKey5"));

            // Create and register the test mediator
            IMediator mediator = new Mediator("testing", this);

            view.RegisterMediator(mediator);

            // Remove the component
            IMediator removedMediator = view.RemoveMediator("testing");

            // assert that we have removed the appropriate mediator
            Assert.IsTrue(removedMediator.MediatorName == "testing", "Expecting removedMediator.MediatorName == 'testing'");

            // assert that the mediator is no longer retrievable
            Assert.IsNull(view.RetrieveMediator("testing"), "Expecting view.RetrieveMediator('testing') == null");
        }
Exemplo n.º 2
0
        public void TestOnRegisterAndOnRemove()
        {
            // Get the Multiton View instance
            IView view = View.GetInstance("ViewTestKey6", () => new View("ViewTestKey6"));

            // Create and register the test mediator
            IMediator mediator = new ViewTestMediator4(this);

            view.RegisterMediator(mediator);

            // assert that onRegsiter was called, and the mediator responded by setting our boolean
            Assert.IsTrue(onRegisterCalled, "Expecting onRegisterCalled == true");

            //Remove the component
            view.RemoveMediator(ViewTestMediator4.NAME);

            // assert that the mediator is no longer retrievable
            Assert.IsTrue(onRemoveCalled, "Expecting onRemoveCalled == true");
        }
        public void TestHasMediator()
        {
            // // register a Mediator
            var view = View.GetInstance(() => new View());

            // Create and register the test mediator
            IMediator mediator = new Mediator("HasMediatorTest", this);
            view.RegisterMediator(mediator);

            // assert that the view.hasMediator method returns true
            // for that mediator name
            Assert.IsTrue(view.HasMediator("HasMediatorTest") == true, "Expecting view.HasMediator('HasMediatorTest') == true");

            view.RemoveMediator("HasMediatorTest");

            // assert that the view.hasMediator method returns false
            // for that mediator name
            Assert.IsTrue(view.HasMediator("HasMediatorTest") == false, "Expecting view.HasMediator('HasMediatorTest') == false");
        }
        public void TestGetInstanceThreadSafety()
        {
            var instances = new List <IView>();

            for (var i = 0; i < 1000; i++)
            {
                new Thread(() =>
                {
                    instances.Add(View.GetInstance("ThreadSafety", key => new View(key)));
                }).Start();
            }

            // test assertions
            for (int i = 1, count = instances.Count; i < count; i++)
            {
                Assert.AreEqual(instances[0], instances[i]);
            }

            View.GetInstance("ThreadSafety", key => new View(key));
        }
Exemplo n.º 5
0
        public void TestRemoveOneOfTwoMediatorsAndSubsequentNotify()
        {
            // Get the Multiton View instance
            IView view = View.GetInstance("ViewTestKey9", () => new View("ViewTestKey9"));

            // Create and register that responds to notifications 1 and 2
            view.RegisterMediator(new ViewTestMediator2(this));

            // Create and register that responds to notification 3
            view.RegisterMediator(new ViewTestMediator3(this));

            // test that all 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");

            view.NotifyObservers(new Notification(NOTE3));
            Assert.IsTrue(lastNotification == NOTE3, "Expecting lastNotification == NOTE3");

            // Remove the Mediator that responds to 1 and 2
            view.RemoveMediator(ViewTestMediator2.NAME);

            // test that retrieving it now returns null
            Assert.IsTrue(view.RetrieveMediator(ViewTestMediator2.NAME) == null, "Expecting view.RetrieveMediator(ViewTestMediator2.NAME) == null");

            // test that notifications no longer work
            // for notifications 1 and 2, but still work for 3
            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");

            view.NotifyObservers(new Notification(NOTE3));
            Assert.IsTrue(lastNotification == NOTE3, "Expecting lastNotification == NOTE3");
        }
        public void TestRegisterAndNotifyObserver()
        {
            // Get the Singleton View instance
            var view = View.GetInstance(() => new View());

            // Create observer, passing in notification method and context
            var observer = new Observer(ViewTestMethod, this);

            // Register Observer's interest in a particulat Notification with the View 
            view.RegisterObserver(ViewTestNote.NAME, observer);

            // Create a ViewTestNote, setting 
            // a body value, and tell the View to notify 
            // Observers. Since the Observer is this class 
            // and the notification method is viewTestMethod,
            // successful notification will result in our local 
            // viewTestVar being set to the value we pass in 
            // on the note body.
            var note = ViewTestNote.Create(10);
            view.NotifyObservers(note);

            // test assertions  
            Assert.IsTrue(viewTestVar == 10, "Expecting viewTestVar = 10");
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initialize the Singleton <c>Controller</c> instance
 /// </summary>
 /// <remarks>
 ///     <para>Called automatically by the constructor</para>
 ///
 ///     <para>
 ///         Please aware that if you are using a subclass of <c>View</c>
 ///         in your application, you should also subclass <c>Controller</c>
 ///         and override the <c>initializeController</c> method in the following way:
 ///     </para>
 ///
 ///     <c>
 ///         // ensure that the Controller is talking to my IView implementation
 ///         public override void initializeController()
 ///         {
 ///             view = MyView.Instance;
 ///         }
 ///     </c>
 /// </remarks>
 private void InitializeController()
 {
     m_view = View.GetInstance(m_multitonKey);
 }
Exemplo n.º 8
0
 void InitializeController()
 {
     view = View.GetInstance(multitonKey, () => new View(multitonKey));
 }
Exemplo n.º 9
0
 protected virtual void InitializeController()
 {
     view = View.GetInstance(() => new View());
 }
 /// <summary>
 /// Initialize the Multiton <c>Controller</c> instance
 /// </summary>
 /// <remarks>
 ///     <para>Called automatically by the constructor</para>
 ///     <para>
 ///         Please aware that if you are using a subclass of <c>View</c>
 ///         in your application, you should also subclass <c>Controller</c>
 ///         and override the <c>initializeController</c> method in the following way:
 ///     </para>
 ///     <example>
 ///         <code>
 ///             // ensure that the Controller is talking to my IView implementation
 ///             public override void initializeController()
 ///             {
 ///                 view = MyView.getInstance(multitonKey, () => new MyView(multitonKey));
 ///             }
 ///         </code>
 ///     </example>
 /// </remarks>
 protected virtual void InitializeController()
 {
     view = View.GetInstance(multitonKey, key => new View(key));
 }
Exemplo n.º 11
0
        protected virtual void InitializeController()
        {
            IView tempView = new View(multitonKey);

            view = View.GetInstance(multitonKey, tempView);
        }