Ejemplo n.º 1
0
        public void Callback_OnSerialized()
        {
            // Arrange
            var instance = new SerializationCallback_OnSerialized();

            // Act
            JsonNode.ConvertFrom(instance);

            // Assert
            Assert.AreEqual("OnSerialized", instance.Result);
        }
Ejemplo n.º 2
0
        public void ConvertFrom_uint()
        {
            // Arrange
            uint value = 42;

            // Act
            var node = JsonNode.ConvertFrom(value);

            // Assert
            Assert.IsNotNull(node);
            Assert.IsInstanceOfType(node, typeof(JsonIntegerNode));
            Assert.AreEqual(value, (node as JsonIntegerNode).Value);
        }
Ejemplo n.º 3
0
        public void ConvertFrom_string()
        {
            // Arrange
            string value = "Hello World!";

            // Act
            var node = JsonNode.ConvertFrom(value);

            // Assert
            Assert.IsNotNull(node);
            Assert.IsInstanceOfType(node, typeof(JsonStringNode));
            Assert.AreEqual(value, (node as JsonStringNode).Value);
        }
Ejemplo n.º 4
0
        public void ConvertFrom_ulong()
        {
            // Arrange
            ulong value = ulong.MaxValue;

            // Act
            var node = JsonNode.ConvertFrom(value);

            // Assert
            Assert.IsNotNull(node);
            Assert.IsInstanceOfType(node, typeof(JsonIntegerNode));
            Assert.AreEqual(value, (node as JsonIntegerNode).UnsignedValue);
        }
Ejemplo n.º 5
0
        public void ConvertFrom_string_list()
        {
            // Arrange
            var value = new List <string>(new string[] { "A", "B", "C" });

            // Act
            var arrayNode = JsonNode.ConvertFrom(value) as JsonArrayNode;

            Assert.IsNotNull(arrayNode);
            Assert.AreEqual(3, arrayNode.Count);
            Assert.AreEqual("A", (arrayNode[0] as JsonStringNode).Value);
            Assert.AreEqual("B", (arrayNode[1] as JsonStringNode).Value);
            Assert.AreEqual("C", (arrayNode[2] as JsonStringNode).Value);
        }
Ejemplo n.º 6
0
        public void ConvertFrom_string_array()
        {
            // Arrange
            string[] value = { "A", "B", "C" };

            // Act
            var arrayNode = JsonNode.ConvertFrom(value) as JsonArrayNode;

            // Assert
            Assert.IsNotNull(arrayNode);
            Assert.AreEqual(3, arrayNode.Count);
            Assert.AreEqual("A", (arrayNode[0] as JsonStringNode).Value);
            Assert.AreEqual("B", (arrayNode[1] as JsonStringNode).Value);
            Assert.AreEqual("C", (arrayNode[2] as JsonStringNode).Value);
        }
Ejemplo n.º 7
0
        public void ConvertFrom_string_dictionary()
        {
            // Arrange
            var value = new Dictionary <string, int>();

            value["A"] = 3;
            value["B"] = 2;
            value["C"] = 1;

            // Act
            var objectNode = JsonNode.ConvertFrom(value) as JsonObjectNode;

            // Assert
            Assert.IsNotNull(objectNode);
            Assert.AreEqual(3, objectNode.Count);
            Assert.AreEqual(3, (objectNode["A"] as JsonIntegerNode).Value);
            Assert.AreEqual(2, (objectNode["B"] as JsonIntegerNode).Value);
            Assert.AreEqual(1, (objectNode["C"] as JsonIntegerNode).Value);
        }
Ejemplo n.º 8
0
        public void ConvertFrom_string_object()
        {
            // Arrange
            var value = new PersonCard()
            {
                Name    = "Sabrina Styles",
                Age     = 42,
                Friends = 872
            };

            // Act
            var objectNode = JsonNode.ConvertFrom(value) as JsonObjectNode;

            // Assert
            Assert.IsNotNull(objectNode);
            Assert.AreEqual(3, objectNode.Count);
            Assert.AreEqual("Sabrina Styles", (objectNode["Name"] as JsonStringNode).Value);
            Assert.AreEqual(42, (objectNode["Age"] as JsonIntegerNode).Value);
            Assert.AreEqual(872, (objectNode["Friends"] as JsonIntegerNode).Value);
        }