public void AnyString()
        {
            const int length = 128;
            string    x      = _random.AnyString(length);

            Assert.AreEqual(length, x.Length);
        }
Exemple #2
0
        public void Test()
        {
            var testObject = new SimpleJsonObject
            {
                Name   = _random.AnyString(6),
                Number = _random.Any(),
            };

            for (int i = 0; i < _random.Any(2, 7); i++)
            {
                var childObject = new SimpleChildJsonObject
                {
                    Name   = _random.AnyString(6),
                    Number = _random.Any(),
                };

                testObject.Children.Add(childObject);
            }


            var memoryStream = new MemoryStream();

            // Serialize the object
            using (var writer = JSON.GetWriter(memoryStream))
            {
                testObject.ToJson(writer);
            }

            Assert.Greater(memoryStream.Position, 0);

            memoryStream.Position = 0;


            // Deserialize back into the original object

            var simpleJsonObjectResponse = new SimpleJsonObject();

            using (var reader = JSON.GetReader(memoryStream))
            {
                reader.Read();

                simpleJsonObjectResponse.FromJson(reader);
            }
        }
        public void JsonCloneAnyObject()
        {
            var myObject = new MyPlainObject
            {
                Id        = Guid.NewGuid(),
                Name      = _random.AnyString(8),
                Timestamp = DateTime.UtcNow,
                Value     = _random.Any(),
                DataBlock = _random.AnyBytes(128),
            };

            var clonedObject = myObject.JsonClone();

            Assert.IsFalse(ReferenceEquals(myObject, clonedObject));

            Assert.AreEqual(myObject.Id, clonedObject.Id);
            Assert.AreEqual(myObject.Name, clonedObject.Name);
            Assert.AreEqual(myObject.Timestamp, clonedObject.Timestamp);
            Assert.AreEqual(myObject.Value, clonedObject.Value);
            Assert.AreEqual(myObject.DataBlock, clonedObject.DataBlock);
        }