Ejemplo n.º 1
0
        public void PublisherTest()
        {
            //Arrange
            Publisher danceGenrePublisher = new Publisher();
            Publisher rockGenrePublisher  = new Publisher();

            PubSubServer server = new PubSubServer();

            Message danceGenreMessage = new Message();

            danceGenreMessage.genre       = "Dance";
            danceGenreMessage.description = "Dance music is popular in clubs.";

            Message rockGenreMessage = new Message();

            rockGenreMessage.genre       = "Rock";
            rockGenreMessage.description = "Rock music was very popular in the 90's";


            //Act
            danceGenrePublisher.Send(danceGenreMessage, server);
            rockGenrePublisher.Send(rockGenreMessage, server);


            //Assert
            Assert.IsNotNull(server.buffer);
            CollectionAssert.AllItemsAreNotNull(server.buffer);
            Assert.IsTrue(server.buffer.Any());
        }
Ejemplo n.º 2
0
        public void SubscriberTest()
        {
            //Arrange
            Publisher danceGenrePublisher = new Publisher();
            Publisher rockGenrePublisher  = new Publisher();

            Subscriber allGenreSubscriber   = new Subscriber();
            Subscriber danceGenreSubscriber = new Subscriber();

            PubSubServer server = new PubSubServer();

            Message danceGenreMessage = new Message();

            danceGenreMessage.genre       = "Dance";
            danceGenreMessage.description = "Dance music is popular in clubs.";

            Message rockGenreMessage = new Message();

            rockGenreMessage.genre       = "Rock";
            rockGenreMessage.description = "Rock music was very popular in the 90's";


            //Act
            danceGenrePublisher.Send(danceGenreMessage, server);
            rockGenrePublisher.Send(rockGenreMessage, server);

            allGenreSubscriber.Listen("Dance");
            allGenreSubscriber.Listen("Rock");
            allGenreSubscriber.Listen("Country");

            danceGenreSubscriber.Listen("Dance");

            server.subscribers.Add(allGenreSubscriber);
            server.subscribers.Add(danceGenreSubscriber);

            server.Next();

            //Assert
            Assert.IsNotNull(server.subscribers);
            CollectionAssert.AllItemsAreNotNull(server.subscribers);
            Assert.IsTrue(server.subscribers.Any());
        }
Ejemplo n.º 3
0
    void Start()
    {
        // Initialisation
        PubSubServer server = new PubSubServer();

        Subscriber subscriber1 = new Subscriber();

        subscriber1.server = server;
        subscriber1.Initialise();   // The subscriber will subscribe to the server

        Publisher publisher1 = new Publisher();

        publisher1.server = server;


        // Use
        publisher1.PublishMessage("CIAO1");
        publisher1.PublishMessage("CIAO2");



        // subscriber1.SubscribeToTopic("aaa");
    }