Пример #1
0
        public void TestPublishRetrieve()
        {
            UserMessage message = new UserMessage("group-16", "First M");

            worker_.Tell(new Publish(message, 10));

            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            Message operationAckMessage = testclient_.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(OperationAck), operationAckMessage.GetType());
            OperationAck operationAck = (OperationAck)operationAckMessage;


            Assert.AreEqual(10, operationAck.CommunicationId);

            worker_.Tell(new RetrieveMessages("group-16", 10));

            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            Message foundMessagesMessage = testclient_.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(FoundMessages), foundMessagesMessage.GetType());
            FoundMessages foundMessages = (FoundMessages)foundMessagesMessage;

            Assert.AreEqual(10, foundMessages.CommunicationId);
            Assert.AreEqual(message, foundMessages.Messages.FirstOrDefault());
        }
Пример #2
0
        public void TestMessageId()
        {
            //Message with same Id will be published
            //----------------------------------------------------------
            long comm_id = 10;

            //Create Message
            String      author       = "group-16";
            String      message      = "same";
            UserMessage test_message = new UserMessage(author, message);

            //Publish Message
            worker_.Tell(new Publish(test_message, comm_id));
            //Get Message
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            //OperationAckMessage tells if Message was published
            Message      operationAckMessage = testclient_.ReceivedMessages.Dequeue();
            OperationAck operationAck        = (OperationAck)operationAckMessage;

            //Holt die Message vom entsprechenden Autor
            worker_.Tell(new RetrieveMessages(author, comm_id));
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            Message       foundMessagesMessage = testclient_.ReceivedMessages.Dequeue();
            FoundMessages foundMessages        = (FoundMessages)foundMessagesMessage;


            UserMessage same_message = foundMessages.Messages.FirstOrDefault();

            //Publish Message
            worker_.Tell(new Publish(same_message, comm_id));
            //Get Message
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            //operationFailedMessage tells if Message was published
            Message operationFailedMessage = testclient_.ReceivedMessages.Dequeue();

            Assert.AreEqual(typeof(OperationFailed), operationFailedMessage.GetType());
        }
Пример #3
0
        public void TestLikeDislike()
        {
            long comm_id = 10;

            //Create Message
            String      author       = "Group16";
            String      message      = "My message";
            UserMessage test_message = new UserMessage(author, message);

            //Publish Message
            worker_.Tell(new Publish(test_message, comm_id));

            //Get Message
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            //OperationAckMessage tells if Message was published
            Message      operationAckMessage = testclient_.ReceivedMessages.Dequeue();
            OperationAck operationAck        = (OperationAck)operationAckMessage;

            //Holt die Message vom entsprechenden Autor
            worker_.Tell(new RetrieveMessages(author, comm_id));
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            Message       foundMessagesMessage = testclient_.ReceivedMessages.Dequeue();
            FoundMessages foundMessages        = (FoundMessages)foundMessagesMessage;


            UserMessage userMessage = foundMessages.Messages.FirstOrDefault();

            Assert.AreEqual("My message", userMessage.Message);


            long message_id = userMessage.MessageId;


            Like    like_test    = new Like(testclient_.ToString(), comm_id, message_id);
            Dislike dislike_test = new Dislike(testclient_.ToString(), comm_id, message_id);


            //AddLike add_like = new AddLike(testclient_.ToString(), message_id , comm_id);
            //AddDislike add_dislike = new AddDislike(testclient_.ToString(), message_id, comm_id);

            //Publish like
            worker_.Tell(like_test);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Assert.AreEqual(typeof(OperationAck), operationAckMessage.GetType());

            //Publish dislike
            worker_.Tell(dislike_test);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Assert.AreEqual(typeof(OperationAck), operationAckMessage.GetType());


            worker_.Tell(new RetrieveMessages(author, comm_id));
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }

            //Holt sich die Nachrichtt
            foundMessagesMessage = testclient_.ReceivedMessages.Dequeue();
            foundMessages        = (FoundMessages)foundMessagesMessage;
            userMessage          = foundMessages.Messages.FirstOrDefault();

            int num_likes    = userMessage.Likes.Count;
            int num_dislikes = userMessage.Dislikes.Count;

            Assert.AreEqual(1, num_likes);
            Assert.AreEqual(1, num_dislikes);



            //Add like dislike with wrong id
            Like    like_wrongid    = new Like(testclient_.ToString(), comm_id, 5);
            Dislike dislike_wrongid = new Dislike(testclient_.ToString(), comm_id, 5);

            //Publish wrong like
            worker_.Tell(like_wrongid);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Console.WriteLine(operationAckMessage);
            Assert.AreEqual(typeof(OperationFailed), operationAckMessage.GetType());


            //Publish wrong dislike
            worker_.Tell(dislike_wrongid);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Assert.AreEqual(typeof(OperationFailed), operationAckMessage.GetType());



            //Add like/dislike 2nd time with same client and same message;
            Like    like_wrongclient    = new Like(testclient_.ToString(), comm_id, message_id);
            Dislike dislike_wrongclient = new Dislike(testclient_.ToString(), comm_id, message_id);

            //Publish 2nd like form same client on same message
            worker_.Tell(like_wrongclient);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Console.WriteLine(operationAckMessage);
            Assert.AreEqual(typeof(OperationFailed), operationAckMessage.GetType());


            //Publish 2nd dislike form same client on same message
            worker_.Tell(dislike_wrongclient);
            while (testclient_.ReceivedMessages.Count == 0)
            {
                system_.RunFor(1);
            }
            operationAckMessage = testclient_.ReceivedMessages.Dequeue(); //OperationAckMessage tells if Message was published
            Assert.AreEqual(typeof(OperationFailed), operationAckMessage.GetType());
        }