예제 #1
0
        static void Main(string[] args)
        {
            var m = new Mediator();

            var p1 = new Participant(m);
            var p2 = new Participant(m);
            var p3 = new Participant(m);

            Console.WriteLine($"p1 = {p1.Value}; p2 = {p2.Value}; p3 = {p3.Value}");

            p1.Say(3);

            Console.WriteLine($"p1 = {p1.Value}; p2 = {p2.Value}; p3 = {p3.Value}");

            p2.Say(2);

            Console.WriteLine($"p1 = {p1.Value}; p2 = {p2.Value}; p3 = {p3.Value}");
        }
예제 #2
0
        static void ExerciseDemo()
        {
            var m  = new Exercise.Mediator();
            var p1 = new Participant(m);
            var p2 = new Participant(m);

            WriteLine(p1);
            WriteLine(p2);

            p1.Say(3);

            WriteLine(p1);
            WriteLine(p2);

            p2.Say(2);

            WriteLine(p1);
            WriteLine(p2);
        }
예제 #3
0
        public void Test()
        {
            Mediator mediator = new Mediator();
            var      p1       = new Participant(mediator);
            var      p2       = new Participant(mediator);

            Assert.That(p1.Value, Is.EqualTo(0));
            Assert.That(p2.Value, Is.EqualTo(0));

            p1.Say(2);

            Assert.That(p1.Value, Is.EqualTo(0));
            Assert.That(p2.Value, Is.EqualTo(2));

            p2.Say(4);

            Assert.That(p1.Value, Is.EqualTo(4));
            Assert.That(p2.Value, Is.EqualTo(2));
        }