Exemplo n.º 1
0
        public void PresenceUpdateLeaveTopic()
        {
            INError error = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            byte[]  room  = Encoding.UTF8.GetBytes("test-room");
            INTopic topic = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INTopic topic1) =>
            {
                topic = topic1;
                client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INTopic topic2) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);

            byte[]           leaveUserId = null;
            ManualResetEvent evt2        = new ManualResetEvent(false);

            client1.OnTopicPresence += (object source, NTopicPresenceEventArgs args) =>
            {
                leaveUserId = args.TopicPresence.Leave[0].UserId;
                evt2.Set();
            };
            client2.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
            {
                // No action.
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });

            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.AreEqual(userId2, leaveUserId);
        }
Exemplo n.º 2
0
        public void PresenceUpdateLeaveTopic()
        {
            INError error = null;

            ManualResetEvent evt1  = new ManualResetEvent(false);
            string           room  = "test-room";
            INTopic          topic = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics1) =>
            {
                topic = topics1.Results[0];
                client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics2) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);

            string           leaveUserId = null;
            ManualResetEvent evt2        = new ManualResetEvent(false);

            client1.OnTopicPresence = (INTopicPresence presence) =>
            {
                leaveUserId = presence.Leave[0].UserId;
                evt2.Set();
            };
            client2.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
            {
                // No action.
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });

            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.AreEqual(userId2, leaveUserId);
        }
Exemplo n.º 3
0
        public void MessageSendWithoutJoinTopic()
        {
            INError error = null;

            INTopic          topic = null;
            ManualResetEvent evt1  = new ManualResetEvent(false);

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom("test-room").Build(), (INResultSet <INTopic> topics) =>
            {
                topic = topics.Results[0];
                client1.Send(NTopicLeaveMessage.Default(topic.Topic), (bool complete) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);

            ManualResetEvent evt2 = new ManualResetEvent(false);

            client1.Send(NTopicMessageSendMessage.Default(topic.Topic, "{\"some\":\"data\"}"), (INTopicMessageAck ack) =>
            {
                evt2.Set();
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(5000, false);
            Assert.IsNotNull(error);
        }
Exemplo n.º 4
0
        public void PresenceUpdateChangeHandle()
        {
            string  handle = random.GetString(20);
            INError error  = null;

            ManualResetEvent evt1  = new ManualResetEvent(false);
            string           room  = "test-room-handle-update";
            INTopic          topic = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics1) =>
            {
                topic = topics1.Results[0];

                client1.OnTopicPresence = (INTopicPresence presence) =>
                {
                    Assert.AreEqual(presence.Leave[0].UserId, presence.Join[0].UserId);
                    Assert.AreEqual(presence.Join[0].Handle, handle);
                    evt1.Set();
                };

                client1.Send(new NSelfUpdateMessage.Builder().Handle(handle).Build(), (bool completed) =>
                {
                    // do nothing
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);
        }
Exemplo n.º 5
0
        public void MessagesListTopic()
        {
            INError error = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);
            string           room = "history-room";
            INTopic          t    = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics) =>
            {
                t = topics.Results[0];
                evt1.Set();
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(t);

            string data = "{\"some\":\"history data " +
                          System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(random.GetString())) + "\"}";

            for (int i = 0; i < 10; i++)
            {
                ManualResetEvent evtFor = new ManualResetEvent(false);
                client1.Send(NTopicMessageSendMessage.Default(t.Topic, data), (INTopicMessageAck ack) =>
                {
                    evtFor.Set();
                }, (INError err) =>
                {
                    error = err;
                    evtFor.Set();
                });
                evtFor.WaitOne(5000, false);
                if (error != null)
                {
                    break;
                }
            }
            Assert.IsNull(error);

            INResultSet <INTopicMessage> messages = null;
            ManualResetEvent             evt2     = new ManualResetEvent(false);

            client1.Send(new NTopicMessagesListMessage.Builder().TopicRoom(room).Forward(false).Limit(10).Build(), (INResultSet <INTopicMessage> msgs) =>
            {
                messages = msgs;
                evt2.Set();
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
            });
            evt2.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(messages);
            Assert.AreEqual(10, messages.Results.Count);
            foreach (var msg in messages.Results)
            {
                Assert.AreEqual(data, msg.Data);
            }
        }
Exemplo n.º 6
0
        public void MessageSendTopic()
        {
            INError error = null;

            ManualResetEvent evt1  = new ManualResetEvent(false);
            string           room  = "test-room";
            INTopic          topic = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics1) =>
            {
                topic = topics1.Results[0];
                client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INResultSet <INTopic> topics2) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);

            string            data       = "{\"some\":\"data\"}";
            INTopicMessage    message    = null;
            INTopicMessageAck messageAck = null;
            ManualResetEvent  evt2       = new ManualResetEvent(false);
            ManualResetEvent  evt3       = new ManualResetEvent(false);

            client1.OnTopicMessage = (INTopicMessage msg) =>
            {
                message = msg;
                evt2.Set();
            };
            client2.Send(NTopicMessageSendMessage.Default(topic.Topic, data), (INTopicMessageAck ack) =>
            {
                messageAck = ack;
                evt3.Set();
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
                evt3.Set();
            });

            evt2.WaitOne(5000, false);
            evt3.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(message);
            Assert.IsNotNull(messageAck);

            Assert.AreEqual(userId2, message.UserId);
            Assert.AreEqual(TopicMessageType.Chat, message.Type);
            Assert.AreEqual(data, message.Data);

            Assert.AreEqual(messageAck.MessageId, message.MessageId);
            Assert.AreEqual(messageAck.CreatedAt, message.CreatedAt);
            Assert.AreEqual(messageAck.ExpiresAt, message.ExpiresAt);
            Assert.AreEqual(messageAck.Handle, message.Handle);
        }
Exemplo n.º 7
0
        public void MessageSendTopic()
        {
            INError error = null;

            ManualResetEvent evt1 = new ManualResetEvent(false);

            byte[]  room  = Encoding.UTF8.GetBytes("test-room");
            INTopic topic = null;

            client1.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INTopic topic1) =>
            {
                topic = topic1;
                client2.Send(new NTopicJoinMessage.Builder().TopicRoom(room).Build(), (INTopic topic2) =>
                {
                    evt1.Set();
                }, (INError err) =>
                {
                    error = err;
                    evt1.Set();
                });
            }, (INError err) =>
            {
                error = err;
                evt1.Set();
            });
            evt1.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(topic);

            byte[]            data       = Encoding.UTF8.GetBytes("{\"some\":\"data\"}");
            INTopicMessage    message    = null;
            INTopicMessageAck messageAck = null;
            ManualResetEvent  evt2       = new ManualResetEvent(false);
            ManualResetEvent  evt3       = new ManualResetEvent(false);

            client1.OnTopicMessage += (object source, NTopicMessageEventArgs args) =>
            {
                message = args.Message;
                evt2.Set();
            };
            client2.Send(NTopicMessageSendMessage.Default(topic.Topic, data), (INTopicMessageAck ack) =>
            {
                messageAck = ack;
                evt3.Set();
            }, (INError err) =>
            {
                error = err;
                evt2.Set();
                evt3.Set();
            });

            evt2.WaitOne(5000, false);
            evt3.WaitOne(5000, false);
            Assert.IsNull(error);
            Assert.IsNotNull(message);
            Assert.IsNotNull(messageAck);

            Assert.AreEqual(userId2, message.UserId);
            Assert.AreEqual(TopicMessageType.Chat, message.Type);
            Assert.AreEqual(data, message.Data);

            Assert.AreEqual(messageAck.MessageId, message.MessageId);
            Assert.AreEqual(messageAck.CreatedAt, message.CreatedAt);
            Assert.AreEqual(messageAck.ExpiresAt, message.ExpiresAt);
            Assert.AreEqual(messageAck.Handle, message.Handle);
        }