public void ParseChatMessageTest()
        {
            var data = "{\"type\":\"event\",\"event\":\"ChatMessage\",\"data\":{\"channel\":160788,\"id\":\"8fcfe1a0-ccc5-11e9-a733-1900adf73a91\",\"user_name\":\"Cat_King_34\",\"user_id\":108942852,\"user_roles\":[\"User\"],\"user_level\":9,\"user_avatar\":null,\"message\":{\"message\":[{\"type\":\"text\",\"data\":\"\",\"text\":\"\"},{\"type\":\"emoticon\",\"source\":\"external\",\"pack\":\"https://uploads.mixer.com/emoticons/nkkpu1fh-160788.png\",\"coords\":{\"x\":0,\"y\":24,\"width\":24,\"height\":24},\"text\":\":mcatHug\"}],\"meta\":{\"shouldDrop\":false}},\"user_ascension_level\":11}}";
            var msg  = InternalMessageParser.Parse(data, null) as ChatMessageData;

            Assert.AreEqual(160788, msg.Channel);
            Assert.AreEqual("8fcfe1a0-ccc5-11e9-a733-1900adf73a91", msg.Id);
            Assert.AreEqual("Cat_King_34", msg.UserName);
            Assert.AreEqual(108942852, msg.UserId);
            Assert.AreEqual(new[] { "User" }, msg.UserRoles);
            Assert.AreEqual(9, msg.UserLevel);
            //Assert.IsNull(msg.UserAvatar);
            Assert.AreEqual(new List <IMessagePart>
            {
                Common.MessagePartFactory.CreateMessageText(""),
                new Common.MessageImage
                {
                    Alt    = ":mcatHug",
                    Url    = "https://uploads.mixer.com/emoticons/nkkpu1fh-160788.png",
                    Width  = 24,
                    Height = 24,
                },
            }, msg.MessageItems);
            Assert.IsFalse(msg.ShouldDrop);
        }
        public void ParseUnknownTypeMessageTest()
        {
            var data = "{ \"type\":\"123\" }";
            var msg  = InternalMessageParser.Parse(data, null) as UnknownMessage;

            Assert.AreEqual(data, msg.Raw);
        }
        public void ParseWelcomeEventTest()
        {
            var data = "{\"type\":\"event\",\"event\":\"WelcomeEvent\",\"data\":{\"server\":\"d5afec05-4e2c-4816-981c-094f04a4d31c\"}}";
            var msg  = InternalMessageParser.Parse(data, null) as WelcomeEvent;

            Assert.AreEqual("d5afec05-4e2c-4816-981c-094f04a4d31c", msg.Server);
        }
        public void ParseUnknownEventMessageTest()
        {
            var data = "{ \"type\":\"event\",\"event\":\"abc\" }";
            var msg  = InternalMessageParser.Parse(data, null) as UnknownMessage;

            Assert.AreEqual(data, msg.Raw);
        }
        public void ParseUnknownFormatMessageTest()
        {
            var data = "{ \"abc\":123 }";
            var msg  = InternalMessageParser.Parse(data, null) as UnknownMessage;

            Assert.AreEqual(data, msg.Raw);
        }
        public void ParseNotJsonMessageTest()
        {
            var data = "abc";
            var msg  = InternalMessageParser.Parse(data, null) as UnknownMessage;

            Assert.AreEqual(data, msg.Raw);
        }
Ejemplo n.º 7
0
        public void OptOutEventsMethodのRawが正しく機能するか()
        {
            //origin.Rawがテスト対象
            //origin.Rawをパーサに渡して正しいOptOutEventsMethodが生成されるか確認する
            var origin = new OptOutEventsMethod(99, new string[] { "a", "b" });
            var parsed = InternalMessageParser.Parse(origin.Raw, null) as OptOutEventsMethod;

            Assert.AreEqual(origin.Id, parsed.Id);
            Assert.AreEqual(origin.Raw, parsed.Raw);
            CollectionAssert.AreEqual(origin.Arguments, parsed.Arguments);
        }
Ejemplo n.º 8
0
        public void AuthMethodのRawが正しく機能するか()
        {
            //origin.Rawがテスト対象
            //origin.Rawをパーサに渡して正しいAuthMethodが生成されるか確認する
            var origin = new AuthMethod(99, 123);
            var parsed = InternalMessageParser.Parse(origin.Raw, null) as AuthMethod;

            Assert.AreEqual(origin.ChannelId, parsed.ChannelId);
            Assert.AreEqual(origin.Id, parsed.Id);
            Assert.AreEqual(origin.MyId, parsed.MyId);
            Assert.AreEqual(origin.Raw, parsed.Raw);
            Assert.AreEqual(origin.Token, parsed.Token);
        }
        public void ParseUnknownReplyMessageTest()
        {
            var id     = 123;
            var method = new UnknownMethod(id);
            var dict   = new Dictionary <long, MethodBase>()
            {
                { id, method }
            };
            var data = "{ \"type\":\"reply\",\"reply\":\"abc\",\"id\":" + id + " }";
            var msg  = InternalMessageParser.Parse(data, dict) as UnknownMessage;

            Assert.AreEqual(data, msg.Raw);
        }
        public void ParseOptOutEventsReplyTest()
        {
            var id     = 99;
            var method = new OptOutEventsMethod(id, new string[] { });
            var dict   = new Dictionary <long, MethodBase>()
            {
                { id, method }
            };
            var data  = "{\"type\":\"reply\",\"error\":null,\"id\":" + id + ",\"data\":{}}";
            var reply = InternalMessageParser.Parse(data, dict) as OptOutEventsReply;

            Assert.AreEqual(id, reply.Id);
        }
        public void ParsePingReplyTest()
        {
            var id     = 99;
            var method = new PingMethod(id);
            var dict   = new Dictionary <long, MethodBase>()
            {
                { id, method }
            };
            var data  = "{\"type\":\"reply\",\"error\":null,\"id\":" + id + "}";
            var reply = InternalMessageParser.Parse(data, dict) as PingReply;

            Assert.AreEqual(id, reply.Id);
        }
        public void ParseAuthReplyTest(string data, long id, bool authenticated, string[] roles)
        {
            var method = new AuthMethod(id, 123);
            var dict   = new Dictionary <long, MethodBase>()
            {
                { id, method }
            };
            var reply = InternalMessageParser.Parse(data, dict) as AuthReply;

            Assert.AreEqual(id, reply.Id);
            Assert.AreEqual(authenticated, reply.Authenticated);
            Assert.AreEqual(roles, reply.Roles);
        }
Ejemplo n.º 13
0
        public void DeleteMessageEventのRawが正しく機能するか()
        {
            //origin.Rawがテスト対象
            //origin.Rawをパーサに渡して正しいDeleteMessageEventが生成されるか確認する
            var origin = new DeleteMessageEvent("123", new User("name", 229, new[] { "role1", "role2" }, 998));
            var parsed = InternalMessageParser.Parse(origin.Raw, null) as DeleteMessageEvent;

            Assert.AreEqual(origin.Moderator.UserId, parsed.Moderator.UserId);
            Assert.AreEqual(origin.Moderator.UserName, parsed.Moderator.UserName);
            Assert.AreEqual(origin.Moderator.UserLevel, parsed.Moderator.UserLevel);
            CollectionAssert.AreEqual(origin.Moderator.UserRoles, parsed.Moderator.UserRoles);
            Assert.AreEqual(origin.Id, parsed.Id);
            Assert.AreEqual(origin.Raw, parsed.Raw);
        }