Exemplo n.º 1
0
        public void Test()
        {
            var mediator = new ConcreteMediator<string>();

            var producer1 = new ConcreteProducer<string>(mediator);
            var producer2 = new ConcreteProducer<string>(mediator);

            var consumer1 = new ConcreteConsumer<string>();
            var consumer2 = new ConcreteConsumer<string>();
            var consumer3 = new ConcreteConsumer<string>();
            
            mediator.Register(consumer1);
            mediator.Register(consumer2);
            mediator.Register(consumer3);

            Assert.That(consumer1.Notification, Is.Null);
            Assert.That(consumer2.Notification, Is.Null);
            Assert.That(consumer3.Notification, Is.Null);

            producer1.Publish("producer 1");

            Assert.That(consumer1.Notification, Is.EqualTo("producer 1"));
            Assert.That(consumer2.Notification, Is.EqualTo("producer 1"));
            Assert.That(consumer3.Notification, Is.EqualTo("producer 1"));

            producer2.Publish("producer 2");

            Assert.That(consumer1.Notification, Is.EqualTo("producer 2"));
            Assert.That(consumer2.Notification, Is.EqualTo("producer 2"));
            Assert.That(consumer3.Notification, Is.EqualTo("producer 2"));
        }
Exemplo n.º 2
0
        public void Test()
        {
            var mediator      = new ConcreteMediator();
            var collaboratorA = new ConcreteCollaboratorA(mediator);
            var collaboratorB = new ConcreteCollaboratorB(mediator);

            mediator.CollaboratorA = collaboratorA;
            mediator.CollaboratorB = collaboratorB;
            collaboratorA.Send("Test request");
            collaboratorB.Send("Test response");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Execute()
        {
            ConcreteMediator m = new ConcreteMediator();

            ConcreteColleague1 c1 = new ConcreteColleague1(m);
            ConcreteColleague2 c2 = new ConcreteColleague2(m);

            m.Colleague1 = c1;
            m.Colleague2 = c2;

            c1.Send("How are you?");
            c2.Send("Fine, thanks");
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            ConcreteMediator m = new ConcreteMediator();

              ConcreteColleague1 c1 = new ConcreteColleague1(m);
              ConcreteColleague2 c2 = new ConcreteColleague2(m);

              m.Colleague1 = c1;
              m.Colleague2 = c2;

              c1.Send("How are you?");
              c2.Send("Fine, thanks");

              // Wait for user
              Console.ReadKey();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            ConcreteMediator m = new ConcreteMediator();

            ConcreteColleague1 c1 = new ConcreteColleague1(m);
            ConcreteColleague2 c2 = new ConcreteColleague2(m);

            m.Colleague1 = c1;
            m.Colleague2 = c2;

            c1.Send("How are you?");
            c2.Send("Fine, thanks");

            // Wait for user
            Console.ReadKey();
        }