Exemple #1
0
        public void Test6()
        {
            var keybind = new KeybindComponent(KeyBindType.Attack)
            {
                Extra = new List <ChatComponent>
                {
                    new StringComponent("text1"),
                    new StringComponent("text2")
                }
            };

            var chat = new Chat(keybind);
            var j    = chat.ToJObject();

            Assert.Equal("key.attack", j.SelectToken("keybind"));
            Assert.Equal("text1", j.SelectToken("extra[0].text"));
            Assert.Equal("text2", j.SelectToken("extra[1].text"));

            const string json  = @"{
                ""keybind"":""key.attack"",
                ""extra"":[
                    { ""text"":""text1"" },
                    { ""text"":""text2"" }
                ]
            }";
            var          chat2 = Chat.Parse(json);

            Assert.True(JToken.DeepEquals(j, chat2.ToJObject()));
        }
Exemple #2
0
        public void Test4()
        {
            var chat = new Chat("text")
            {
                Component =
                {
                    Bold       = true,
                    Itatic     = false,
                    Insertion  = "insert",
                    Color      = ColorType.Red,
                    ClickEvent = new ChatClickEvent(ClickEventType.ChangePage, 1),
                    HoverEvent = new ChatHoverEvent(HoverEventType.ShowText,  "show")
                }
            };
            var keybind = new KeybindComponent
            {
                Keybind = KeyBindType.Back,
                Bold    = false,
                Itatic  = true,
                Color   = ColorType.Green
            };

            chat.Component.Extra = new List <ChatComponent> {
                keybind
            };

            var json = chat.ToJObject();

            Assert.Null(json.SelectToken("underlined"));
            Assert.Null(json.SelectToken("strikethrough"));
            Assert.Null(json.SelectToken("obfuscated"));
            Assert.True(json.SelectToken("bold").Value <bool>());
            Assert.False(json.SelectToken("extra[0].bold").Value <bool>());
            Assert.False(json.SelectToken("itatic").Value <bool>());
            Assert.True(json.SelectToken("extra[0].itatic").Value <bool>());
            Assert.Equal("red", json.SelectToken("color"));
            Assert.Equal("green", json.SelectToken("extra[0].color"));
            Assert.Equal("key.back", json.SelectToken("extra[0].keybind"));
            Assert.Equal("insert", json.SelectToken("insertion"));
            Assert.Equal("change_page", json.SelectToken("clickEvent.action"));
            Assert.Equal(1, json.SelectToken("clickEvent.value").Value <int>());
            Assert.Equal("show_text", json.SelectToken("hoverEvent.action"));
            Assert.Equal("show", json.SelectToken("hoverEvent.value"));
        }
Exemple #3
0
        public void Test4()
        {
            Chat chat = new Chat("text");

            chat.Component.Bold       = true;
            chat.Component.Itatic     = false;
            chat.Component.Insertion  = "insert";
            chat.Component.Color      = ColorType.Red;
            chat.Component.ClickEvent = new ChatClickEvent(ClickEventType.ChangePage, 1);
            chat.Component.HoverEvent = new ChatHoverEvent(HoverEventType.ShowText, "show");
            KeybindComponent keybind = new KeybindComponent();

            keybind.Bold         = false;
            keybind.Itatic       = true;
            keybind.Color        = ColorType.Green;
            chat.Component.Extra = new List <ChatComponent>()
            {
                keybind
            };

            var json = chat.ToJObject();

            Assert.Null(json.SelectToken("underlined"));
            Assert.Null(json.SelectToken("strikethrough"));
            Assert.Null(json.SelectToken("obfuscated"));
            Assert.True(json.SelectToken("bold").Value <bool>());
            Assert.False(json.SelectToken("extra[0].bold").Value <bool>());
            Assert.False(json.SelectToken("itatic").Value <bool>());
            Assert.True(json.SelectToken("extra[0].itatic").Value <bool>());
            Assert.Equal("red", json.SelectToken("color"));
            Assert.Equal("green", json.SelectToken("extra[0].color"));
            Assert.Equal("insert", json.SelectToken("insertion"));
            Assert.Equal("change_page", json.SelectToken("clickEvent.action"));
            Assert.Equal(1, json.SelectToken("clickEvent.value").Value <int>());
            Assert.Equal("show_text", json.SelectToken("hoverEvent.action"));
            Assert.Equal("show", json.SelectToken("hoverEvent.value"));
        }