public void TestWriteValueDefaultExtensions()
        {
            var writer = new JTokenJSValueWriter();

            writer.WriteObjectBegin();
            writer.WriteObjectProperty("StringValue1", "");
            writer.WriteObjectProperty("StringValue2", "5");
            writer.WriteObjectProperty("StringValue3", "Hello");
            writer.WriteObjectProperty("BoolValue1", false);
            writer.WriteObjectProperty("BoolValue2", true);
            writer.WriteObjectProperty("IntValue1", 0);
            writer.WriteObjectProperty("IntValue2", 42);
            writer.WriteObjectProperty("FloatValue", 3.14);
            writer.WriteObjectProperty("NullValue", JSValue.Null);
            writer.WriteObjectEnd();
            JToken jValue = writer.TakeValue();

            Assert.AreEqual("", jValue["StringValue1"]);
            Assert.AreEqual("5", jValue["StringValue2"]);
            Assert.AreEqual("Hello", jValue["StringValue3"]);
            Assert.AreEqual(false, jValue["BoolValue1"]);
            Assert.AreEqual(true, jValue["BoolValue2"]);
            Assert.AreEqual(0, jValue["IntValue1"]);
            Assert.AreEqual(42, jValue["IntValue2"]);
            Assert.AreEqual(3.14, jValue["FloatValue"]);
            Assert.AreEqual(JTokenType.Null, jValue["NullValue"].Type);
        }
        public void TestWriteCustomType()
        {
            var robot = new RobotInfo
            {
                Model  = RobotModel.R2D2,
                Name   = "Bob",
                Age    = 42,
                Shape  = RobotShape.Trashcan,
                Shape2 = RobotShape.Beercan,
                Shape3 = null,
                Steps  = new List <int> {
                    1, 2, 3
                },
                Dimensions = new Dictionary <string, int> {
                    ["Width"] = 24, ["Height"] = 78
                },
                Badges = Tuple.Create(2, "Maverick", true),
                Tools  = new RobotTool[] {
                    new RobotTool {
                        Name = "Screwdriver", Weight = 2, IsEnabled = true
                    },
                    new RobotTool {
                        Name = "Electro-shocker", Weight = 3, IsEnabled = false
                    }
                },
                Path = new RobotPoint[] {
                    new RobotPoint {
                        X = 5, Y = 6
                    },
                    new RobotPoint {
                        X = 45, Y = 90
                    },
                    new RobotPoint {
                        X = 15, Y = 16
                    }
                },
                Extra = new R2D2Extra {
                    MovieSeries = "Episode 2"
                }
            };

            var writer = new JTokenJSValueWriter();

            writer.WriteValue(robot);
            JToken jValue = writer.TakeValue();

            Assert.AreEqual((int)RobotModel.R2D2, jValue["Model"]);
            Assert.AreEqual("Bob", jValue["Name"]);
            Assert.AreEqual(42, jValue["Age"]);
            Assert.AreEqual((int)RobotShape.Trashcan, jValue["Shape"]);
            Assert.AreEqual((int)RobotShape.Beercan, jValue["Shape2"]);
            Assert.AreEqual(JTokenType.Null, jValue["Shape3"].Type);
            Assert.AreEqual(3, (jValue["Steps"] as JArray).Count);
            Assert.AreEqual(1, jValue["Steps"][0]);
            Assert.AreEqual(2, jValue["Steps"][1]);
            Assert.AreEqual(3, jValue["Steps"][2]);
            Assert.AreEqual(2, (jValue["Dimensions"] as JObject).Count);
            Assert.AreEqual(24, jValue["Dimensions"]["Width"]);
            Assert.AreEqual(78, jValue["Dimensions"]["Height"]);
            Assert.AreEqual(2, jValue["Badges"][0]);
            Assert.AreEqual("Maverick", jValue["Badges"][1]);
            Assert.AreEqual(true, jValue["Badges"][2]);
            Assert.AreEqual(2, (jValue["Tools"] as JArray).Count);
            Assert.AreEqual("Screwdriver", jValue["Tools"][0]["Name"]);
            Assert.AreEqual(2, jValue["Tools"][0]["Weight"]);
            Assert.AreEqual(true, jValue["Tools"][0]["IsEnabled"]);
            Assert.AreEqual("Electro-shocker", jValue["Tools"][1]["Name"]);
            Assert.AreEqual(3, jValue["Tools"][1]["Weight"]);
            Assert.AreEqual(false, jValue["Tools"][1]["IsEnabled"]);
            Assert.AreEqual(3, (jValue["Path"] as JArray).Count);
            Assert.AreEqual(5, jValue["Path"][0]["X"]);
            Assert.AreEqual(6, jValue["Path"][0]["Y"]);
            Assert.AreEqual(45, jValue["Path"][1]["X"]);
            Assert.AreEqual(90, jValue["Path"][1]["Y"]);
            Assert.AreEqual(15, jValue["Path"][2]["X"]);
            Assert.AreEqual(16, jValue["Path"][2]["Y"]);
            Assert.AreEqual("Episode 2", jValue["Extra"]["MovieSeries"]);
        }