Пример #1
0
        public void ExportObjectTest()
        {
            UiSample sample = new UiSample();

            sample.widget.window.title  = "FooBar";
            sample.widget.window.name   = "foo_window";
            sample.widget.window.width  = 400;
            sample.widget.window.height = 300;

            sample.widget.image.src       = "logo.png";
            sample.widget.image.name      = "Foo Logo";
            sample.widget.image.hOffset   = 10;
            sample.widget.image.vOffset   = 20;
            sample.widget.image.alignment = "right";

            sample.widget.text.data      = "About Us";
            sample.widget.text.size      = 24;
            sample.widget.text.style     = "normal";
            sample.widget.text.name      = "about";
            sample.widget.text.alignment = "center";

            string expected = "{\"widget\":{\"window\":" +
                              "{\"title\":\"FooBar\",\"name\":\"foo_window\"," +
                              "\"width\":400,\"height\":300},\"image\":{\"src\":" +
                              "\"logo.png\",\"name\":\"Foo Logo\",\"hOffset\":10," +
                              "\"vOffset\":20,\"alignment\":\"right\"},\"text\":{" +
                              "\"data\":\"About Us\",\"size\":24,\"style\":\"normal\"," +
                              "\"name\":\"about\",\"hOffset\":0,\"vOffset\":0," +
                              "\"alignment\":\"center\",\"onMouseUp\":null}," +
                              "\"debug\":false}}";

            string json = JsonMapper.ToJson(sample);

            Assert.AreEqual(expected, json);
        }
Пример #2
0
        public void ImportObjectTest()
        {
            string json = @"
{
  ""widget"": {
    ""debug"": true,

    ""window"": {
      ""title"": ""Sample Widget"",
      ""name"": ""main_window"",
      ""width"": 500,
      ""height"": 500
    },

    ""image"": {
      ""src"": ""Images/Sun.png"",
      ""name"": ""sun1"",
      ""hOffset"": 250,
      ""vOffset"": 250,
      ""alignment"": ""center""
    },

    ""text"": {
      ""data"": ""Click Here"",
      ""size"": 36,
      ""style"": ""bold"",
      ""name"": ""text1"",
      ""hOffset"": 250,
      ""vOffset"": 100,
      ""alignment"": ""center"",
      ""onMouseUp"": ""sun1.opacity = (sun1.opacity / 100) * 90;""
    }
  }
}";

            UiSample sample = JsonMapper.ToObject <UiSample> (json);

            Assert.IsNotNull(sample, "A1");
            Assert.AreEqual("Sample Widget", sample.widget.window.title,
                            "A2");
            Assert.AreEqual(500, sample.widget.window.width, "A3");
            Assert.AreEqual("sun1", sample.widget.image.name, "A4");
            Assert.AreEqual("Click Here", sample.widget.text.data, "A5");
        }