示例#1
0
        private static void TestIntegers(TreeFormat format)
        {
            TreeSerializationSettings settings = new TreeSerializationSettings()
            {
                LeaveStreamOpen = true
            };

            using (MemoryStream stream = new MemoryStream())
            {
                using (ITreeWriter writer = Writer(format, stream, settings))
                {
                    writer.WriteStartArray();

                    for (int i = -1; i < 300; i += 7)
                    {
                        writer.WriteValue(i);
                    }

                    writer.WriteEndArray();
                }

                long bytesWritten = stream.Position;
                stream.Seek(0, SeekOrigin.Begin);

                using (ITreeReader reader = Reader(format, stream, settings))
                {
                    Assert.Equal(TreeToken.StartArray, reader.TokenType);

                    for (int i = -1; i < 300; i += 7)
                    {
                        Assert.True(reader.Read());
                        Assert.Equal(TreeToken.Integer, reader.TokenType);
                        Assert.Equal(i, reader.ReadAsInt32());
                    }

                    Assert.True(reader.Read());
                    Assert.Equal(TreeToken.EndArray, reader.TokenType);
                    Assert.False(reader.Read());
                }

                Assert.Equal(bytesWritten, stream.Position);
            }
        }