Exemplo n.º 1
0
        public void PrimitiveArray()
        {
            PrimitiveArrayClass a = new PrimitiveArrayClass
            {
                Ints   = new[] { 1, 2, 3, 4, 5, 6 },
                Floats = new[] { 1.5f, 2.5f, 3.5f },
                Ints2  = new[, ] {
                    { 1, 2 }, { 3, 4 }
                }
            };

            JObject target = new JObject();

            Serializer.Serialize((NewtonsoftJsonAdapter)target, a);

            AssertChildren(3, target);

            PrimitiveArrayClass b = Deserializer.Deserialize <PrimitiveArrayClass>((NewtonsoftJsonAdapter)target);

            for (int i = 0; i < a.Ints.Length; i++)
            {
                Assert.AreEqual(a.Ints[i], b.Ints[i]);
            }
            for (int i = 0; i < a.Floats.Length; i++)
            {
                Assert.AreEqual(a.Floats[i], b.Floats[i]);
            }
            for (int x = 0; x < a.Ints2.GetLength(0); x++)
            {
                for (int y = 0; y < a.Ints2.GetLength(1); y++)
                {
                    Assert.AreEqual(a.Ints2[x, y], b.Ints2[x, y]);
                }
            }
        }
        public void An_empty_array_of_objects_should_be_properly_serialized()
        {
            var message = new PrimitiveArrayClass {
                Values = new int[] { }
            };

            TestSerialization(message);
        }
        public void A_primitive_array_of_objects_with_one_element_should_be_properly_serialized()
        {
            var message = new PrimitiveArrayClass {
                Values = new[] { 1 }
            };

            TestSerialization(message);
        }
        public void A_primitive_array_of_objects_should_be_properly_serialized()
        {
            var message = new PrimitiveArrayClass {
                Values = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
            };

            TestSerialization(message);
        }
Exemplo n.º 5
0
            public bool Equals(PrimitiveArrayClass other)
            {
                if (ReferenceEquals(null, other))
                {
                    return(false);
                }

                if (ReferenceEquals(this, other))
                {
                    return(true);
                }

                if (ReferenceEquals(other.Values, Values))
                {
                    return(true);
                }

                if (other.Values == null && Values != null)
                {
                    return(false);
                }

                if (other.Values != null && Values == null)
                {
                    return(false);
                }

                if (other.Values != null && Values != null)
                {
                    if (other.Values.Length != Values.Length)
                    {
                        return(false);
                    }

                    for (int i = 0; i < Values.Length; i++)
                    {
                        if (!Equals(other.Values[i], Values[i]))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
        public void PrimitiveArray()
        {
            PrimitiveArrayClass a = new PrimitiveArrayClass
            {
                Ints   = new[] { 1, 2, 3, 4, 5, 6 },
                Floats = new[] { 1.5f, 2.5f, 3.5f },
                Ints2  = new[, ] {
                    { 1, 2 }, { 3, 4 }
                }
            };

            XmlDocument target = new XmlDocument();

            Serializer.Serialize((SystemXmlAdapter)target, a);

            Assert.AreEqual(3, target.DocumentElement.ChildNodes.Count);

            Assert.AreEqual(1, GetElement(target, "Ints").ChildNodes.Count);
            Assert.AreEqual(1, GetElement(target, "Floats").ChildNodes.Count);

            PrimitiveArrayClass b = Deserializer.Deserialize <PrimitiveArrayClass>((SystemXmlAdapter)target);

            for (int i = 0; i < a.Ints.Length; i++)
            {
                Assert.AreEqual(a.Ints[i], b.Ints[i]);
            }
            for (int i = 0; i < a.Floats.Length; i++)
            {
                Assert.AreEqual(a.Floats[i], b.Floats[i]);
            }
            for (int x = 0; x < a.Ints2.GetLength(0); x++)
            {
                for (int y = 0; y < a.Ints2.GetLength(1); y++)
                {
                    Assert.AreEqual(a.Ints2[x, y], b.Ints2[x, y]);
                }
            }
        }
Exemplo n.º 7
0
    private void PrimitiveNullArrayLengthTest <TValue>()
    {
        var expected = new PrimitiveArrayClass <TValue>();

        Roundtrip(expected, 5);
    }