Пример #1
0
        static void Main(string[] args)
        {
            //Get User input
            User user = GetInput();

            //Data Transform, this could enhance with dependency injection or strategy pattern to change the
            // transformation method during run time.
            string userData = Newtonsoft.Json.JsonConvert.SerializeObject(user);

            //Register the publisher to the message broker
            MessageBroker messageBroker = new MessageBroker();
            Publisher     publisher     = new Publisher(messageBroker);

            //Subscibe to the message broker
            ConcreteSubscriber  subscriber1         = new ConcreteSubscriber("Subscriber 1", messageBroker);
            FormattedSubscriber formattedSubscriber = new FormattedSubscriber(messageBroker);

            // Publish to all subscriber
            publisher.PublishData(userData);

            //Display Data
            Console.WriteLine(subscriber1.GetDisplayData());
            Console.WriteLine(formattedSubscriber.GetDisplayData());

            Console.ReadLine();
        }
Пример #2
0
        public void TestConcreteSubscriber()
        {
            string name = "concrete subscriber";
            string data = "test data";
            var    messageBrokerMock = new Mock <MessageBroker>();

            var subscriber = new ConcreteSubscriber(name, messageBrokerMock.Object);

            subscriber.EnqueueData(data);

            Assert.AreEqual(name + "'s Data : \r\n" + data + "\r\n", subscriber.GetDisplayData());
        }