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")); }
public void WhenSendingMessageToSpecificTypeOfReceiver_ShouldSendMessageToAllFromTypeExceptOriginalSender() { var mediator = new ConcreteMediator(); var colleague1Mock = new Mock <ConcreteColleague1>() { CallBase = true }; var colleague2Mock = new Mock <ConcreteColleague1>() { CallBase = true }; var colleague3Mock = new Mock <ConcreteColleague3>() { CallBase = true }; colleague1Mock.Setup(c => c.Receive(It.IsAny <string>())); colleague2Mock.Setup(c => c.Receive(It.IsAny <string>())); colleague3Mock.Setup(c => c.Receive(It.IsAny <string>())); var colleague1 = colleague1Mock.Object; var colleague2 = colleague2Mock.Object; var colleague3 = colleague3Mock.Object; mediator.Register(colleague1); mediator.Register(colleague2); mediator.Register(colleague3); colleague1.Send <ConcreteColleague1>("Custom message"); colleague1Mock.Verify(c => c.Receive(It.IsAny <string>()), Times.Never); colleague2Mock.Verify(c => c.Receive("Custom message"), Times.Once); colleague3Mock.Verify(c => c.Receive(It.IsAny <string>()), Times.Never); }
static void Main(string[] args) { var mediator = new ConcreteMediator(); var dev = new ColleagueDev(); var test = new ColleagueTest(); mediator.Register(dev); mediator.Register(test); dev.Send("Hello from DEV World, its better here"); test.Send("We are the testers, beeboop"); }
static void Main(string[] args) { IColleague <string> colleagueA = new ConcreteColleague <string>("ColleagueA"); IColleague <string> colleagueB = new ConcreteColleague <string>("ColleagueB"); IColleague <string> colleagueC = new ConcreteColleague <string>("ColleagueC"); IMediator <string> mediator1 = new ConcreteMediator <string>(); mediator1.Register(colleagueA); mediator1.Register(colleagueB); mediator1.Register(colleagueC); colleagueA.SendMessage(mediator1, "MessageX from ColleagueA"); }
static void Main(string[] args) { ConcreteMediator cm = new ConcreteMediator(); Person a1 = new Adult("adult 1"); Person a2 = new Adult("adult 2"); Person c1 = new Child("child 1"); cm.Register(a1); cm.Register(a2); cm.Register(c1); a1.Send("Hello adults", audience.adult); a1.Send("Hello everyone"); Console.Read(); }
static void Main(string[] args) { IColleague <string> colleagueA = new ConcreteColleague <string>("Colleague A"); IColleague <string> colleagueB = new ConcreteColleague <string>("Colleague B"); IColleague <string> colleagueC = new ConcreteColleague <string>("Colleague C"); IMediator <string> mediator = new ConcreteMediator <string>(); mediator.Register(colleagueA); mediator.Register(colleagueB); mediator.Register(colleagueC); colleagueC.SendMessage(mediator, "message from " + colleagueC.GetName() + "!"); Console.ReadKey(); }
static void Main(string[] args) { IColleague<string> colleagueA = new ConcreteColleague<string>("Colleague A"); IColleague<string> colleagueB = new ConcreteColleague<string>("Colleague B"); IColleague<string> colleagueC = new ConcreteColleague<string>("Colleague C"); IMediator<string> mediator = new ConcreteMediator<string>(); mediator.Register(colleagueA); mediator.Register(colleagueB); mediator.Register(colleagueC); colleagueC.SendMessage(mediator, "message from " + colleagueC.GetName() + "!"); Console.ReadKey(); }
public static void Test() { // Create chatroom participants AbstractColleague colleague1 = new ConcreteColleague() { ID = "1" }; AbstractColleague colleague2 = new ConcreteColleague() { ID = "2" }; AbstractColleague colleague3 = new ConcreteColleague() { ID = "3" }; AbstractColleague colleague4 = new ConcreteColleague() { ID = "4" }; AbstractColleague colleague5 = new ConcreteColleague() { ID = "5" }; var mediator = new ConcreteMediator(); mediator.Register(colleague1); mediator.Register(colleague2); mediator.Register(colleague3); mediator.Register(colleague4); mediator.Register(colleague5); colleague1.Send("2", "from 1 to 2"); colleague3.Send("4", "from 3 to 4"); colleague5.Send("1", "from 5 to 1"); }
public CoreViewModel() { PswFileName = "Passwords"; OpenViews = new ObservableCollection <ViewBase>(); OpenNewWindow = new OpenWindowCommand(SetView); CreateAccount = new CreateAccountCommand(AccountWizard); Login = new LoginCommand(LoginToAccount); passwordManager = new PasswordProvider(); mediator = new ConcreteMediator(OpenNewWindow); mediator.Register(this); }
static bool TestMediatorPattern() { Console.WriteLine("TESTING THE MEDIATOR DESIGN PATTERN: "); Participant <string> p1 = new ConcreteParticipant <string>("p1"); Participant <string> p2 = new ConcreteParticipant <string>("p2"); Participant <string> p3 = new ConcreteParticipant <string>("p3"); Mediator <string> m = new ConcreteMediator <string>(); m.Register(p1); m.Register(p2); m.Register(p3); p1.SendMessage(m, "Message from p1"); //Output //p2 received: Message from p1 //p3 received: Message from p1 Console.ReadKey(); return(true); }